Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
How to watch env file changes in vite js on static build?

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!