在學習webpack根據入門教程"清理/dist文件時"出錯了,網上找了下改下寫法就行了,在此記錄下webpack
首先安裝 clean-webpack-plugin 插件web
npm install clean-webpack-plugin --save-dev
確保安裝成功npm
其次修改webpack.config.js配置文件學習
// webpack版本:4.35.0 // 教程原寫法,報錯 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin(['dist']) ]
// new的時候不傳參,報錯 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin() ] // 另外一種寫法,也報錯 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin(['dist'], { root: path.resolve(__dirname, '../'), //根目錄 }) ] // =============================分割線============================== // 修改下導入方式,new的時候不傳參,正確 const { CleanWebpackPlugin } = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin() ]