typedotenv with unplugin.
You can generate TypeScript code from .env
file.
When you edit the .env
file, the file is re-created.
npm install --save-dev unplugin-typedotenv
Vite
// vite.config.ts
import typedotenv from 'unplugin-typedotenv/vite'
export default defineConfig({
plugins: [typedotenv({ output: 'src/env.ts' })],
})
Rollup
// rollup.config.js
import typedotenv from 'unplugin-typedotenv/rollup'
export default {
plugins: [typedotenv({ output: 'src/env.ts' })],
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
build({
plugins: [require('unplugin-typedotenv/esbuild')({ output: 'src/env.ts' })],
})
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [require('unplugin-typedotenv/webpack')({ output: 'src/env.ts' })],
}