使用npm运行react程序报错The 'mode' option has not been set, webpack will fallback to 'production' for th

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.

以上的警告指的是没有设定是开发模式还是生产模式,要求指定.

只需要在项目中的package.json中script中配置上

 "dev": "webpack --mode development",    "build": "webpack --mode production" 两句即可

使用方法在cmd中输入 npm run dev (开发环境输出的index.js没有压缩) 

npm run build (生产模式输出的index.js压缩过, ps:此时只要index.html和index.js2个文件就可正常输出显示)     


/////////////以下本人完整package.json文件源码供参考////////////

{
  "name": "reactapp",
  "version": "1.0.0",
  "description": "good",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server",
    "dev": "webpack --mode development",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.26.0",
    "react": "^16.3.1",
    "react-dom": "^16.3.1"
  }
}

你可能感兴趣的:(使用npm运行react程序报错The 'mode' option has not been set, webpack will fallback to 'production' for th)