johnagan / clean-webpack-plugin

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

V2 dist folder content is deleted before webpack start building #133

Closed jimblue closed 5 years ago

jimblue commented 5 years ago

Issue description or question

Hi,

I've read the doc and a bunch of closed issue about this, but I didn't get how to replicate beforeEmit of V1?

Just need to stop removing all assets before webpack even start to bundle them...

Thank you so much for you help.

Cheers

Webpack Config

const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
    plugins: [
        new CleanWebpackPlugin()
    ],
};

Environment

System:
    OS: macOS Mojave 10.14.4
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 14.43 GB / 32.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
    npm: 6.9.0 - ~/.nvm/versions/node/v10.15.1/bin/npm
chrisblossom commented 5 years ago

I must say I am confused about how beforeEmit worked previously. It is my understanding that the compile hook happens before the emit hook, so to me they are accomplishing the same thing, unless you are wanting to clean after the compile hook. In that case, you should be able to use cleanAfterEveryBuildPatterns.

I wouldn't be against the idea of adding a custom hook option, but I'd like to understand the use case for this first. Is it possible for you to provide a minimal example to show what issue you are running into?

jimblue commented 5 years ago

Ok, let say my app is working well on production and I have new version of the app to build and push. If I launch webpack build and it fails, the dist folder will be empty and my app will be broken.

To prevent that, clean-webpack-plugin should wait for build success before removing dist folder content.

That way the new build will replace the removed one and the app will never be broken in case the build add an error...

chrisblossom commented 5 years ago

Thanks for the explanation, it makes a lot of sense and we already do this for cleanAfterEveryBuildPatterns.

Any thoughts of why we wouldn't always use the emit hook over compile?

chrisblossom commented 5 years ago

@jimblue See #134

jimblue commented 5 years ago

Nice!!!! That was fast... thank you

rohit-gohri commented 5 years ago

When can we expect a release for this?

johnagan commented 5 years ago

done https://www.npmjs.com/package/clean-webpack-plugin

jimblue commented 5 years ago

Thanks @johnagan, it's working great now !