Using Environment Variables with Vue.js

后端 未结 9 1408
礼貌的吻别
礼貌的吻别 2020-11-29 18:22

I\'ve been reading the official docs and I\'m unable to find anything on environment variables. Apparently there are some community projects that support environment variabl

9条回答
  •  星月不相逢
    2020-11-29 18:46

    This is how I edited my vue.config.js so that I could expose NODE_ENV to the frontend (I'm using Vue-CLI):

    vue.config.js

    const webpack = require('webpack');
    
    // options: https://github.com/vuejs/vue-cli/blob/dev/docs/config.md
    module.exports = {
        // default baseUrl of '/' won't resolve properly when app js is being served from non-root location
        baseUrl: './',
        outputDir: 'dist',
        configureWebpack: {
            plugins: [
                new webpack.DefinePlugin({
                    // allow access to process.env from within the vue app
                    'process.env': {
                        NODE_ENV: JSON.stringify(process.env.NODE_ENV)
                    }
                })
            ]
        }
    };
    

提交回复
热议问题