Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CleanWebpackPlugin config fail when build

I tried to implement a webpack config on a Wordpress theme. I want to add the CleanWebpackPlugin and made a correct install of it.

I read a tutorial and I wrote something like this on my webpack.config.js:

new CleanWebpackPlugin(['./js/build/*','./css/build/*']),

After I made my npm run build I received this error:

clean-webpack-plugin only accepts an options object.

and it redirected me to the GitHub project. I read the documentation but didn't find how to solve my problem.

Can somebody help?

like image 698
Owlnado Avatar asked Mar 22 '19 17:03

Owlnado


2 Answers

I see that CleanWebpackPlugin v2 was released 18 days ago, It looks like you are using an old option type.

The new version, claims:

By default, this plugin will remove all files inside webpack's output.path directory, as well as all unused webpack assets after every successful rebuild.

So, if you need to clean a folder that is not in the output.path, you probably should follow: additional v2 information.

They introduced a new option to clean paths that are outside of output.path:

new CleanWebpackPlugin({
  cleanOnceBeforeBuildPatterns: ['./js/build/*','./css/build/*']
})
like image 88
felixmosh Avatar answered Nov 08 '22 03:11

felixmosh


Check the documentation: https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional

You probably need:

new CleanWebpackPlugin({
  cleanOnceBeforeBuildPatterns: ['./js/build/*','./css/build/*']
}),
like image 35
UjinT34 Avatar answered Nov 08 '22 04:11

UjinT34