Reputation: 58
Whenever I run "npm run build" command, my vue project automatically use ".env.production" file(which is one of my .env files). I would like to build my project by specifying env files for example
Is there any way I can specify environment variables when running "npm run build"????
Upvotes: 3
Views: 10474
Reputation: 56
you can do this by run npm run build --mode production --dest ./dist/production
or
You can achieve this by edit package.json file and add the below run script.
when you add -- mode and --dest in the build command this will pass it to the build script and will look for the mentioned env
"build-production": "vue-cli-service build --mode production --dest ./dist/production",
This will take the environment variables from a file called .env.production if not found will search on file called .env
And will export the build in a dir called dist/production and you can change this from --dest part
Then you should run
npm run build-production
This will will run for production and you can make a second scrip and change to development to read from .env.development Something like
"build-development": "vue-cli-service build --mode development --dest ./dist/development",
Upvotes: 4