webpack4.0报错The 'mode' option has not been set, webpack will fallback to 'production' for thisvalue解决方法

日期:2019-01-20 16:03:31 类别:  Javascript

今天安装webpack,使用npm i webpack -g

这样安装最新的webpack 4版本,导致报错:

The 'mode' option has not been set, webpack will fallback to 'production' for thisvalue


解决方法:

1、在webpack.json中设置如下

"scripts": {
    "dev": "webpack --mode development",  // 开发环境
     "build": "webpack --mode production",  // 生产环境
  },

2、在webpack.config.js中设置如下:

module.exports = {
    entry: './src/app.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.js'
    },
    mode: 'development' // 设置mode
}

3、然后安装指定webpack 3

npm i -D webpack@3