Owlnado
Owlnado

Reputation: 53

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?

Upvotes: 5

Views: 10560

Answers (2)

felixmosh
felixmosh

Reputation: 35503

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/*']
})

Upvotes: 9

UjinT34
UjinT34

Reputation: 4987

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

You probably need:

new CleanWebpackPlugin({
  cleanOnceBeforeBuildPatterns: ['./js/build/*','./css/build/*']
}),

Upvotes: 1

Related Questions