webpack4 mode 的獲取

在使用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的值

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章