1. 程式人生 > >webpack4 打包出錯問題:WARNING in configuration The 'mode' option has not been set, webpack will fallback t

webpack4 打包出錯問題:WARNING in configuration The 'mode' option has not been set, webpack will fallback t

Webpack4 打包出錯問題解決

報錯資訊 :
WARNING in configuration
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.
You can also set it to ‘none’ to disable any default behavior. Learn more:

https://webpack.js.org/concepts/mode/

第一種常見解決方案: 因為在老版本中Webpack打包命令是

webpack .\src\main.js .\dist\bundle.js

而在webpack4之後 官方對 webpack-cli 單獨抽離了出來 所以我們需要
1. 安裝webpack

npm i webpack -g

2. 安裝 cli

npm i -g webpack-cli

3. 打包 將 a.js b.js 替換了就可以

npx webpack a.js --output-filename b.js --output-path . --mode development 

第二種解決方案: 在 package.json 檔案中沒有加(看評論據說沒卵用 我試過 確實沒卵用 希望你們有用 所以放上來了)

"scripts": {
    "start": " --mode development",
    "build": "--mode production"
},