Closed shravan2x closed 5 years ago
Possibly the same issue as https://github.com/johnagan/clean-webpack-plugin/issues/128 ?
Reverting to 1.0.1
is a temporary fix.
Try:
new CleanWebpackPlugin(/*['index.html', '*.js', '*.js.map', '*.css', '*.css.map'],*/ {
dry: true,
verbose: true,
cleanOnceBeforeBuildPatterns: ['index.html', '*.js', '*.js.map', '*.css', '*.css.map'],
cleanStaleWebpackAssets: false,
}),
If I add that option, no files get deleted anymore, not even the ones that cleanOnceBeforeBuildPatterns
should match.
Have you tried:
new CleanWebpackPlugin({
dry: true,
verbose: true,
cleanStaleWebpackAssets: false,
}),
By default, this plugin removes all files in webpack's output.path
. If nothing is being removed, it is my guess you have nested files and your patterns do not match that. See sindresorhus/del#patterns. You're probably wanting: **/*.js
...
No, all the patterns I have mentioned are expected at the root of the output directory. I have checked the link you sent me and am confident that my patterns are correct.
I have the same exact issue. Using webpack 4.29.4.
@tobni please post your clean-webpack-plugin
configuration, what exactly is happening, and what you expect to happen. Most likely I'll need a minimal example repository to further help.
@chrisblossom I too have the same issue
Basically what's happening is when I first run webpack everything is fine.
But if I go to edit say a javascript file and it gets transpiled etc in watch mode, your plugin runs and for some reason it starts deleting the js related files even though they are being excluded or not told to be deleted.
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [],
cleanAfterEveryBuildPatterns: ['css/admin', 'css/fonts', 'css/vendor/kendo-custom', 'css/site'],
protectWebpackAssets: false,
dry: true,
verbose: true
}),
clean-webpack-plugin: dry wwwroot\js\vendor\bootstrap.bundle.min.js.map
clean-webpack-plugin: dry wwwroot\js\vendor\jquery.min.js
clean-webpack-plugin: dry wwwroot\js\vendor\jquery.min.map
clean-webpack-plugin: dry wwwroot\js\vendor\jquery.validate.min.js
clean-webpack-plugin: dry wwwroot\js\vendor\jquery.validate.unobtrusive.min.js
clean-webpack-plugin: dry wwwroot\js\vendor\kendo.ui.core.min.js
clean-webpack-plugin: dry wwwroot\js\vendor\kendo.ui.core.min.js.map
I wanted to remove the file css/admin
which is js file that gets generated by webpack for css files when extracting. As a result I only want to delete those files. If I put a negative pattern such as 'css/**/*'
then it won't delete that file.
UPDATE
I think perhaps I can fix it by using
cleanAfterEveryBuildPatterns: ['!css/**/*', '!js/**/*','css/admin', 'css/fonts', 'css/vendor/kendo-custom', 'css/site']
putting the negative pattern first then deleting what I want
@dotnetshadow You could also look into the cleanStaleWebpackAssets: false
option. Looks like you are using plugins that do not persist webpack assets during rebuilds.
Closing this issue because it has stalled and multiple people are trying to piggyback on it instead of opening their own issue. @shravan2x please reopen with an example repository if you have not solved your issue yet.
Issue description or question
Perhaps I'm missing something here, but files I didn't expect to be removed are being removed by the plugin in v2. In v1, I used
['index.html', '*.js', '*.js.map', '*.css', '*.css.map']
to remove specific files in my output directory, which worked fine.When upgrading to v2, I set the same values as
cleanOnceBeforeBuildPatterns: ['index.html', '*.js', '*.js.map', '*.css', '*.css.map']
. However, files that shouldn't be matched are still deleted by the plugin:Webpack Config
Environment
Run:
npx envinfo --system --binaries --npmPackages clean-webpack-plugin,webpack