关于报错clean-webpack-plugin:E:\workspace\ar\dist is outside of the project root. Skipping...

版权声明:本文为博主原创文章,未经博主允许不得转载。github仓库:https://github.com/lzcwds,欢迎访问 https://blog.csdn.net/lzcwds/article/details/84784587

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, '../'),   //根目录
       //其他配置按需求添加
})

猜你喜欢

转载自blog.csdn.net/lzcwds/article/details/84784587