5

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?

Worthwelle
  • 1,244
  • 1
  • 16
  • 19
Owlnado
  • 53
  • 1
  • 4

2 Answers2

9

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/*']
})
felixmosh
  • 32,615
  • 9
  • 69
  • 88
1

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

You probably need:

new CleanWebpackPlugin({
  cleanOnceBeforeBuildPatterns: ['./js/build/*','./css/build/*']
}),
UjinT34
  • 4,784
  • 1
  • 12
  • 26