johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does the order of clean-webpack-plugin matter?

intrepid-ishan opened this issue · comments

commented

Does the order of CleanWebpackPlugin matter?

In my project, I am running plugins in the below order, as you can see CleanWebpackPlugin is the last item in the array. Will that impact my build?

plugins: [
  new MomentLocalesPlugin(), 
  new webpack.DefinePlugin(),
  new HtmlWebpackPlugin(),
  new CopyWebpackPlugin(),
  new CleanWebpackPlugin()
]

No, it does not

In my case the order was important and CleanWebpackPlugin should always be the first plugin to declare.

Here is the issue: the CleanWebpackPlugin uses the emit hook to perform the initial clean stage. If any other plugin uses the same hook "emit" to write files to the output directory, the file will be deleted if the handler of the emit event of this particular plugin was called first.

Example of such plugin is the "Chunks2JsonPlugin".

Placing the Chunks2JsonPlugin before the CleanWebpackPlugin will remove the file generated by the Chunks2JsonPlugin