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

你可能感兴趣的:(webpack)