欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

webpack打包报错:‘mode‘ option has not been set...

程序员文章站 2024-02-11 11:41:52
...

问题:

初学者刚开始用webpack打包的时候可能会遇到这个报错:

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。

解决办法:

1、首先在package.json中设置:

”scripts": {
    "dev": "webpack --mode development",  // 开发环境
     "build": "webpack --mode production",  // 生产环境
  }

2、然后在webpack.config.js中设置:


module.exports = {
    mode: 'development' // 设置mode   development为开发环境,production为生产环境
}