运行webpack4.* 打包报错:The ‘mode’ option has not been set

打包报如下错误:The ‘mode’ option has not been set, webpack will fallback to ‘production’ for this value. Set ‘mode’ option to ‘development’ or ‘production’ to enable defaults for each environment.

解决:配置如下

{
  "name": "public",
  "version": "1.0.0",
  "description": "",
  "main": "./src/main.js",
  "dependencies": {
    "lodash": "^4.17.15"
  },
  "devDependencies": {
    "webpack": "^4.42.1",
    "webpack-cli": "^3.3.11"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack-dev-server --open --mode development",
    "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

package.json

const path = require('path');

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

webpack.config.js

然后根目录下运行 .\node_modules\.bin\webpack  或者 全局  运行  webpack

你可能感兴趣的:(运行webpack4.* 打包报错:The ‘mode’ option has not been set)