Webpack 4警告:WARNING in configuration The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.
Webpack 4新增了mode选项,它用来表示构建代码的两种默认情况:开发与产品。下面这两个值分别代表了这两种情况:
- development:开发模式,webpack会默认配置常用于开发的参数,如输出运行时的错误信息等
- production:产品模式,webpack会默认配置常用语产品构建的餐宿,如压缩代码等
使用这两种模式的默认配置,用户可以实现零配置。mode选项可以在webpack.config.js里指定,也可以在webpack cli命令上指定:
配置文件:
mode: 'development'
mode: 'production'
命令行:
webpack --mode development
webpack --mode production
如果没有指定,webpack会抛出警告,类似于:
WARNING in configuration The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.