Auto generate the corresponding .env
file.
npm i unplugin-vue-dotenv
Vite
// vite.config.ts
import Dotenv from 'unplugin-vue-dotenv/vite'
export default defineConfig({
plugins: [
Dotenv({ /* options */ }),
],
})
Example: playground/
Rollup
// rollup.config.js
import Starter from 'unplugin-vue-dotenv/rollup'
export default {
plugins: [
Starter({ /* options */ }),
],
}
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-vue-dotenv/webpack')({ /* options */ })
]
}
Nuxt
// nuxt.config.js
export default {
buildModules: [
['unplugin-vue-dotenv/nuxt', { /* options */ }],
],
}
This module works for both Nuxt 2 and Nuxt Vite
Vue CLI
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-vue-dotenv/webpack')({ /* options */ }),
],
},
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
import Starter from 'unplugin-vue-dotenv/esbuild'
build({
plugins: [Starter()],
})
export interface Options {
/**
* Generate the corresponding `.env` file according to the mode
* @default [['']] // Only generate `.env` file
* @example [['test', true]] // Generate `.env.test` and `.env.test.local` files
*/
modes?: modeOpt[]
/**
* Filepath to generate corresponding .d.ts file.
* Default enabled when `typescript` is installed locally.
* Set `false` to disable.
*
* @default './env.d.ts'
*/
dts?: string | boolean
}