@liuli-util/vite-plugin-env-dts-gen
Scan environment variables to generate dts type definitions to avoid manually maintaining dts type definitions for environment variables.
use
pnpm i -D @liuli-util/vite-plugin-env-dts-gen
Configure the plugin
//vite.config.ts
import { defineConfig } from 'vite'
import { envDtsGen } from '@liuli-util/vite-plugin-env-dts-gen'
export default defineConfig({
plugins: [envDtsGen()],
})
FAQ
The default plugin has the following behavior
- When the
ImportMetaEnv
interface insrc/vite-env.d.ts
already contains fields, it will not be repeatedly added or replaced, but skipped. This behavior is mainly to allow users to customize environment variables - never automatically clear an environment variable, even if it no longer exists in .env*, for the same reason as above
- Forcibly generate an environment variable during build, even if there is no change, this behavior is to avoid building immediately after pulling the code for the first time