webpack 运行提示“The ‘mode‘ option has not been set”的原因和解决方法

最近在研究webpack,当我执行npm run build / npm start / npm run server等命令时,都是提示下面的警告信息

WARNING in configuration

The ‘mode‘ option has not been set. Set ‘mode‘ option to ‘development‘ or ‘production‘ to enable defaults for this environment.

大致意思就是:未设置mode(模式),请指定是“开发环境”还是“生产环境”;

如何解决呢?只需要在package.json中添加配置项:

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

执行 npm start 处于开发中调试,有些是 npm run server,只是配置不同而已;执行 npm run build 打包项目,也就是打包成上线后的代码;