webpack警告解除(WARNING in configuration The 'mode' option has not been set)


webpack打包的時候會出現如下的錯誤:

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'uction' for this value. Set 'mode' option to 'development' or duction' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior.rn more: https://webpack.js.org/configuration/mode/

image

產生原因:

webpack升級4.0之后新增了mode屬性

解決方法:

  1. 在package.json中設置開發環境和生產環境
 "scripts": {
    "dev": "webpack --mode development",//設置開發環境
    "build": "webpack --mode production",//設置生產環境
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  1. 在webpack.confing.js中設置mode
const path = require('path')

//這個配置文件就是一個JS文件,通過Mode中的模塊操作,向外暴露一個配置對象
module.exports = {
    //手動指定入口和出口
    entry: path.join(__dirname,'./src/main.js'),//入口,表示打包哪個文件
    output:{
        path: path.join(__dirname,'./dist'),//指定打包好的文件,輸入到哪個目錄中
        filename: 'bundle.js'//指定輸出的文件的名稱
    },
    mode: 'development'//設置mode
}

設置完這兩個文件警告就解除了

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM