1. 程式人生 > >關於報錯clean-webpack-plugin:E:\workspace\ar\dist is outside of the project root. Skipping...

關於報錯clean-webpack-plugin:E:\workspace\ar\dist is outside of the project root. Skipping...

1.問題

webpack配置:

new CleanWebpackPlugin(['../dist'])//這裡我的webpack配置和dist不在同級目錄

執行會報錯:
clean-webpack-plugin: E:\workspace\test\dist is outside of the project root. Skipping…

2.clean-webpack-plugin介紹

用法
new CleanWebpackPlugin(paths [, {options}])
Paths (必須)

一個數組,陣列的每一個元素為要刪除的路徑
例如: [‘dist’,‘build’]

Options 和預設 (Optional)
{
"root":"[webpack.config的地址]",// 一個根的絕對路徑.
"verbose": true,// 將log寫到 console.
"dry": false,// 不要刪除任何東西,主要用於測試.
"exclude": ["files","to","ignore"]//排除不刪除的目錄,主要用於避免刪除公用的檔案
}

3.問題解決

這裡是root引數不準確導致的,可以通過如下配置解決這個問題

new CleanWebpackPlugin(['dist'], {
       root: path.resolve(__dirname, '../'),   //根目錄
       //其他配置按需求新增
})