I have like this configuration file in my vue.js + vite.js project:
File vite.config.js:
import { defineConfig, loadEnv } from 'vite'
import svgLoader from 'vite-svg-loader'
import vue from '@vitejs/plugin-vue'
import path from 'path'
const generateScopedName = 'tw_[local]'
export default ({ mode }) => {
process.env = {...process.env, ...loadEnv(mode, process.cwd(), '')};
return defineConfig({
define: {
'process.env': process.env
},
build: {
sourcemap: false,
cssCodeSplit: false,
rollupOptions: {
output: {
dir: 'dist',
chunkFileNames: '[name].js'
}
}
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
server: {
fs: {
allow: ['..']
},
hmr: {
overlay: false
}
},
plugins: [vue(), svgLoader()],
css: {
modules: {
generateScopedName
}
}
});
}
When I build my project by running command vite build then value of defined process.env variable will be saved as static value from current .env file values. But when I put my bulded projec to another place with different .env file then value of defined process.env won't update automatically. How I can correctly watch .env file values for changes on static build if it possible of course?