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

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个文件就可正常输出显示)   

使用npm运行react程序报错The 'mode' option has not been set, webpack will fallback to 'production' for this_第1张图片

你可能感兴趣的:(webpack,react)