npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@veloss/vite-t3-env

v0.0.5

Published

vite-t3-env plugin for vite

Downloads

9

Readme

@veloss/vite-t3-env

npm version npm downloads bundle size MIT License

vite 환경에서 환경변수를 t3-env와 쉽게 연동하고 타입을 자동으로 만들어주기 위한 vite plugins 입니다.

Concept

  • t3-env-plugin This project was inspired by svelte-kit's approach to handling environment variables. It is a Vite plugin that seamlessly integrates environment variables with t3-env and automatically generates types.

  • Define a t3 env function to validate client env and server env environment variables, and when this function is passed to t3EnvPlugin, environment variable validation is performed. After passing validation, environment variables are set in process.env and "$env/static/private"(server), import.meta.env and "$env/static/public"(client) modules. Type files are also automatically generated.

Usage

Install:

# npm
npm install @veloss/vite-t3-env

# yarn
yarn add @veloss/vite-t3-env

# pnpm
pnpm add @veloss/vite-t3-env

Import:

// ESM / Typescript
import { t3EnvPlugin } from "@veloss/vite-t3-env";

Examples

Simple example

// client.ts
import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import type { RuntimeEnv } from "@veloss/vite-t3-env";

export const clientEnv = (
  runtimeEnv: RuntimeEnv,
  clientPrefix: string | undefined
) => {
  return createEnv({
    clientPrefix,
    client: {
      PUBLIC_SERVER_URL: z.string().url(),
    },
    runtimeEnv,
  });
};

export type ClientEnv = ReturnType<typeof clientEnv>;
// server.ts
import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import type { RuntimeEnv } from "@veloss/vite-t3-env";

export const serverEnv = (runtimeEnv: RuntimeEnv) => {
  return createEnv({
    server: {
      DATABASE_URL: z.string().url(),
      NODE_ENV: z
        .enum(["development", "production", "test"])
        .default("development"),
      SESSION_SECRET: z.string().min(32),
    },
    runtimeEnv,
  });
};

export type ServerEnv = ReturnType<typeof serverEnv>;
// vite.config.ts
import { defineConfig } from "vite";
import { t3EnvPlugin } from "@veloss/vite-t3-env";
import { type ServerEnv, serverEnv } from "./env/server";
import { type ClientEnv, clientEnv } from "./env/client";

export default defineConfig({
  plugins: [
    t3EnvPlugin<ClientEnv, ServerEnv>({
      serverEnv,
      clientEnv,
      prefix: "PUBLIC_",
    }),
    // ...
  ],
});
// global.d.ts
// @veloss/vite-t3-env will generate this file
// this file is generated — do not edit it
declare namespace NodeJS {
  interface ProcessEnv {
    [key: string]: string;
    readonly DATABASE_URL: string;
    readonly NODE_ENV: string;
    readonly SESSION_SECRET: string;
  }
}
// vite-env.d.ts
// @veloss/vite-t3-env will generate this file
// this file is generated — do not edit it

/// <reference types="vite/client" />

interface ImportMetaEnv {
  readonly PUBLIC_SERVER_URL: string;
}

declare module "$env/static/private" {
  export const DATABASE_URL: string;
  export const NODE_ENV: string;
  export const SESSION_SECRET: string;
}

declare module "$env/static/public" {
  export const PUBLIC_SERVER_URL: string;
}

API

clientEnv

Type: (runtimeEnv: RuntimeEnv, clientPrefix?: string | undefined) => Readonly<ClientEnv>

Client environment function. This is used to create the client environment.

import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import type { RuntimeEnv } from "@veloss/vite-t3-env";

const clientEnv = (
  runtimeEnv: RuntimeEnv,
  clientPrefix: string | undefined
) => {
  return createEnv({
    clientPrefix,
    client: {
      PUBLIC_SERVER_URL: z.string().url(),
    },
    runtimeEnv,
  });
};

type ClientEnv = ReturnType<typeof clientEnv>;

serverEnv

Type: (runtimeEnv: RuntimeEnv) => Readonly<ServerEnv> (optional)

Server environment function. This is used to create the server environment.

import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import type { RuntimeEnv } from "@veloss/vite-t3-env";

const serverEnv = (runtimeEnv: RuntimeEnv) => {
  return createEnv({
    server: {
      DATABASE_URL: z.string().url(),
      NODE_ENV: z
        .enum(["development", "production", "test"])
        .default("development"),
      SESSION_SECRET: z.string().min(32),
    },
    runtimeEnv,
  });
};

type ServerEnv = ReturnType<typeof serverEnv>;

envOptions

Type: EnvOptions (optional)

Environment options. This is used to configure the environment file.

export default defineConfig({
  plugins: [
    t3EnvPlugin<ClientEnv, ServerEnv>({
      serverEnv,
      clientEnv,
      envOptions: {
        envFile: ".env",
      },
    }),
    // ...
  ],
});

prefix

Type: Partial<Prefix> | string (optional)

Prefix for the environment variables. This is used to add a prefix to the environment

export default defineConfig({
  plugins: [
    t3EnvPlugin<ClientEnv, ServerEnv>({
      serverEnv,
      clientEnv,
      prefix: "PUBLIC_",
    }),
    // ...
  ],
});

// or
export default defineConfig({
  plugins: [
    t3EnvPlugin<ClientEnv, ServerEnv>({
      serverEnv,
      clientEnv,
      prefix: {
        server: "PRIVATE_",
        client: "PUBLIC_",
      },
    }),
    // ...
  ],
});

Related

License

MIT