Open thet opened 4 years ago
What about use cleanOnceBeforeBuildPatterns option, and then you can only remove the files that match your defined patterns.
To my understanding, the idea in general is it shouldn't be possible to delete the working directory and/or outside of it without setting dangerouslyAllowCleanPatternsOutsideProject
to true
. Though it looks like this isn't properly working depending on the folder structure and how webpack is run.
@thet would you mind adding some more details about that?
As far as I can tell your project looks something like this:
app
├── src
│ └── init.js
├── webpack
│ └── base.config.js
└── bundle.js
It would be nice to know the location of the package.json (or if there is more than one) and how you run webpack e.g. like npx webpack ...
or using some npm script like npm run build
.
Edit: the removal of the working directory is caused by del
version being outdated - that is already fixed with https://github.com/johnagan/clean-webpack-plugin/pull/165 ...
You likely have to use cleanOnceBeforeBuildPatterns
though as Sociosarbis mentioned e.g.
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['bundle.js']
})
this happened to me just now! luckily I had the backup of my project.
Please document this in the readme and warn users of such incidents
Yes, this is very bad indeed. Even the .git
folder was removed which meant that I lost everything since the last git push. That's very bad.
They should put a check for the root directory ASAP!
It removes everything except webpack files !!!
Issue description or question
When using
clean-webpack-plugin
when webpacksoutput.path
is the project root, everything is blindly deleted including the.git
directory. IMO it should only remove old build assets - I don't know if it's possible to find out which one are build assets and which one are not.Webpack Config
The config is in
webpack/base.config.js
.Environment