How to configure environment variables with vue-cli 3?

Isaías Orozco Toledo picture Isaías Orozco Toledo · Nov 6, 2018 · Viewed 11.9k times · Source

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: enter image description here

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?

Answer

Bagaskara picture Bagaskara · Apr 25, 2019

it just happened to me, the solution is very simple. Just restart your development server.

ctrl + c

then

npm run serve