使用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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 入侵检测系统,浅析几个著名的入侵检测系统
- 下一篇: 五层木桶理论/五层木桶理论