1. 程式人生 > >webpack4.x警告The 'mode' option has not been set, webpack will fallback to 'production' for thisvalue.

webpack4.x警告The 'mode' option has not been set, webpack will fallback to 'production' for thisvalue.

報錯的原因是webpack4.x新增了mode屬性,如果不進行設定,就會出現這個警告。

解決辦法:

1、設定 package.json
"scripts": {
  "dev": "webpack --mode development",  // 生產環境
  "pro": "webpack --mode production",  // 上線環境
}
2、設定 webpack.config.js
module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname,
    filename:
'./release/bundle.js' }, mode: 'development', // 生產環境 module: { rules: [{ test: /\.js?$/, exclude: /(node_modules)/, loader: 'babel-loader', }] } }
3、將 webpack 版本回退到 3.x