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

Set cleanStaleWebpackAssets: false by default for to avoid issues

7iomka opened this issue · comments

Issue description or question

// Automatically remove all unused webpack assets on rebuild
// default: true
    cleanStaleWebpackAssets: false,

Please, set cleanStaleWebpackAssets: false by default for to avoid issues.
For example for my use-case, I use browsersync alongside of webpack (as standalone, not webpack plugin), and it use and watch files inside build folder and reload page or inject styles.

After updating to the latest version of your plugin, after saving in any style file from the build folder, the fonts disappear, and all because the file in which they are imported does not go through the webpack whenever you save other style files. I do not know if I could explain my problem.

Webpack config

My sass webpack config: https://gist.github.com/7iomka/076e06e74f6b52024e704457a0d39232

I'm currently looking into this issue. If you could provide a very minimal repo it would be very helpful.

Instead of setting cleanStaleWebpackAssets: false, use a negative file match with cleanAfterEveryBuildPatterns.

new CleanWebpackPlugin({
    cleanAfterEveryBuildPatterns: ['!*.+(woff|woff2|eot|ttf|otf|TTF|OTF)']
});

@chrisblossom Thanks for the feedback.
Regarding the demo repository, unfortunately I can not give you access to my build, and it is also too complicated.
But I will say that your version covers only those files that pass through the webpack, and the given example covers only fonts, I'm right?
Fonts are deleted at the moment of saving the .js file with .scss/.css imports inside.
Maybe it can somehow help.
Regarding the proposed solution, explain in which cases I may need to delete any files during the development mode?

It should be noted that the defaults for this plugin are intended for basic webpack configurations. Like most webpack things, the more you add the more you have to configure.

But I will say that your version covers only those files that pass through the webpack, and the given example covers only fonts, I'm right?

Yes, that exact example is for fonts only, which you described as your issue.

Regarding the proposed solution, explain in which cases I may need to delete any files during the development mode?

If you don't want to remove any files during development, it is perfectly fine to disable cleanStaleWebpackAssets.

new CleanWebpackPlugin({
    cleanStaleWebpackAssets: false
});