Closed cosmoKenney closed 5 years ago
...I've been experimenting with cleanStaleWebpackAssets
and that seems to reduce the set of files that are removed during a watched rebuild. However it is removing files that it has no business removing. For instance it removed all webpac created files from /img
. But then webpack doesn't rewrite those during a watched rebuild.
Are you saying when you set cleanStaleWebpackAssets: false
files are still being removed on rebuild?
However it is removing files that it has no business removing.
The issue is some plugins don't persist their assets as part of webpack's asset list. Since you are using an advanced webpack setup, I'd recommend setting cleanStaleWebpackAssets: false
or you can manually add negative glob patterns to cleanAfterEveryBuildPatterns
that match the files you do not want removed.
@chrisblossom yes! During a webpack --watch build that was started due to saving a file, will run the same clean-webpack-plugin logic as an initial build with cleanOnceBeforeBuildPatterns
setup. See my sample config excerpt in the first post.
webpack --watch on a build due to saving a file will execute just like an initial build with cleanOnceBeforeBuildPatterns setup like in my sample config above
I don't understand this sentence.
Try this and paste the output of verbose: true
:
new CleanWebpackPlugin( { cleanStaleWebpackAssets: false, verbose: true, dry: true } ),
@chrisblossom I need to use cleanOnceBeforeBuildPatterns
because my webpack generated assets are in sub-folders of the root of my project. Without any file specs specified in cleanOnceBeforeBuildPatterns
all of my project files are removed -- I tried this yesterday: new CleanWebpackPlugin( { cleanStaleWebpackAssets: false, verbose: true, dry: true } ),
Are you saying your source files and build files are in the same directory?
Please paste the output. Rename any sensitive filenames.
This is a classic asp.net website, so the source files start at the root. I'll probably just run some deletes before I start webpack. This is a large legacy project and so the output of the suggested config contains hundreds or thousands of files.
I am still having a very hard time understanding your issue / what exactly you need. Please reword in a very clear straight forward way. Pretend I don't have access to your project ;) Or even better, create a minimal repository that demonstrates your isssue.
cleanOnceBeforeBuildPatterns
only runs once, not on rebuilds. If your issue is only with rebuilds, set cleanStaleWebpackAssets: false
and nothing will be automatically removed.
I'll probably just run some deletes before I start webpack.
Definitely a good option.
@chrisblossom I just created a test project locally and I cannot replicate. I'll look into this some more on my end as my webpack build is rather complex.
Issue description or question
Like issue #118, all assets in cleanOnceBeforeBuildPatterns are removed during a rebuild via webpack watch. However webpack is only writing the changed files back to the output directories. This makes webpack watch unusable since most of the assets are removed during a rebuild. In this particular project
output.path
is the root (./
) of the project. And there are 50 entry pages. I usehtml-webpack-plugin
to write*.inc
files to/inc
I useextract-text-webpack-plugin
to write*.css
files to/css
I usefile-loader
to write images to/img
I useoutput.filename: "js/[name].js"
to write my .js files to/js
. I need to specify folder and file-extension wildcards (`js/.js) in the
cleanOnceBeforeBuildPatternsconfiguration, because there are files (
web.config`) in each of the above mentioned folders that need to stay there.Webpack Config
My webpack config is too large and made up of multiple parts in separate files to list here. Relevant info is below:
Environment
Run:
npx envinfo --system --binaries --npmPackages clean-webpack-plugin,webpack
If you need any more info, just let me know.