webpck打包The 'mode' option has not been set, webpack will fallback to 'production' for this value

ゝ一纸荒年。 2022-04-14 02:37 312阅读 0赞

打包报如下错误: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.

  1. WARNING in configuration
  2. 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.
  3. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/

解决方法:

1、在package.json中添加: —mode development,–mode production

  1. "scripts": {
  2. "test": "echo \"Error: no test specified\" && exit 1",
  3. "dev": "webpack-dev-server --open --mode development",
  4. "build": "webpack --mode production"
  5. },

2、在webpack.config.js中设置:mode: ‘development’

  1. module.exports = {
  2. entry: "./src/main.js",
  3. output: {
  4. path: path.resolve(__dirname, 'dist'),
  5. filename: "demo.js"
  6. },
  7. mode: 'development' // 设置mode
  8. }
  9. 3、下载指定版本

npm install -D webpack@3 // 3 :webpack版本3最新

发表评论

表情:
评论列表 (有 0 条评论,312人围观)

还没有评论,来说两句吧...

相关阅读