在使用webpack4的時候,mode可以設定未product(預設)或者development,但是在其他代碼中,如何擷取mode的值呢?
而官方文檔中已經明确:
If you want to change the behavior according to the mode variable inside the webpack.config.js, you have to export a function instead of an object
var config = {
entry: './app.js'
//...
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.devtool = 'source-map';
}
if (argv.mode === 'production') {
//...
}
return config;
};
恰好,官方給出了這個方法:
process.env.NODE_ENV
使用這個可以擷取目前mode的值