i try to use environment variables in vue-cli, but is not working, everytime says 'undefined' when use console.log(process.env.VUE_APP_BASE_URI)
. But process.env.NODE_ENV
says 'development' as i defined in webpack.config.js.
I read the documentation of vue-cli 3 and put my .env.* files in the root project. like this:
Webpack.config.js
module.exports = {
mode: 'development',
context: __dirname,
entry: {
main: ['babel-polyfill', './App/index.js']
},
plugins:[
new VueLoaderPlugin()
],
.env.development
VUE_APP_BASE_URI=http://localhost:64208/api/
.env.production
VUE_APP_BASE_URI=http://localhost:64208/api/
I use .NET Core with Vue. How to use the environment?
webpack.config.js
it usesvue.config.js
- important distinction. You would set--mode development
and--mode production
in yourscripts
inpackage.json
so the correct environment is loaded. – Virnelli