Passing environment-dependent variables in webpack

后端 未结 15 1947
醉酒成梦
醉酒成梦 2020-11-22 12:46

I\'m trying to convert an angular app from gulp to webpack. in gulp I use gulp-preprocess to replace some variables in the html page (e.g. database name) depending on the NO

15条回答
  •  太阳男子
    2020-11-22 13:17

    You can pass any command-line argument without additional plugins using --env since webpack 2:

    webpack --config webpack.config.js --env.foo=bar
    

    Using the variable in webpack.config.js:

    module.exports = function(env) {
        if (env.foo === 'bar') {
            // do something
        }
    }
    

    Source

提交回复
热议问题