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"
},

你可能感兴趣的:(Webpack)