johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building
MIT License
1.96k stars 137 forks source link

cleanAfterEveryBuildPatterns behaviour #121

Closed Oaxoa closed 5 years ago

Oaxoa commented 5 years ago

Issue description or question

I want to use the plugin for two purposes:

With the following configuration I have the following problems: It seems like the glob pattern for the cleanAfterEveryBuildPatterns is behaving in a strange way:

'**/css/*.js'

is a pattern tested with many different glob libraries and online tools. It should match something like '/f67Hy/css/core.js', but it doesn't. I also have subfolders in the 'css' folder so if I use

'**/css/**/*'

the subfolders are found and wiped, but if I try to wipe .js files only with

'**/css/**/*.js'

is doing nothing too. (I also tested this glob pattern).

Also, the plugin when verbose is set to true is printing details of what is cleaned BEFORE but not printing anything for what is being cleaned AFTER. I am also considering the option this might just be a race condition. I tried having the plugin run as the first plugin in the list or as the last, or even splitting it into two instances (one to run before and one after). Still no luck.

Thanks

Webpack Config

new CleanWebpackPlugin({
        cleanOnceBeforeBuildPatterns: ['**/*'],
        cleanAfterEveryBuildPatterns: ['**/css/*.js'],
        dry: false,
        verbose: true,
    }),

Environment

System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
    Memory: 1.03 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 11.10.1 - ~/.nvm/versions/node/v11.10.1/bin/node
    npm: 6.7.0 - ~/.nvm/versions/node/v11.10.1/bin/npm
  npmPackages:
    clean-webpack-plugin: ^2.0.1 => 2.0.1
    webpack: ^4.29.6 => 4.29.6
Oaxoa commented 5 years ago

So, after debugging the plugin I found the problem was that I need to set protectWebpackAssets: false in the option. To me, this was not clear. The plugin was adding all my files (not the folders) to the Globby (internally used to expand globs) ignore list, and tracing nothing about that. I hope this can help someone. Regards

chrisblossom commented 5 years ago

Thanks for posting the solution.