johnagan / clean-webpack-plugin

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

dist not cleared at all when using [hash] in the ouput.path #167

Open kromit opened 4 years ago

kromit commented 4 years ago

When using this, CleanWebpackPlugin does literally nothing.

output: {
        path: path.join(__dirname, 'dist/static/js/[hash]'),
        filename: '[name].js',
    },

Please just let us clear the whole dist folder. I am going to rimraf this for now.

mattcarlotta commented 4 years ago

I'm experiencing the same issue as mentioned above. I'm also using rimraf as an alternative.

In case anyone else runs into this issue, you can do one of these options:

In package.json

"scripts": {
  "build": "rimraf dist && webpack",
},

or

In webpack.config.js

const rimraf = require("rimraf");

if (process.env.NODE_ENV === "production") {
  rimraf("dist", {}, () => console.log("Removed all previous build assets.")); 
}
djnorrisdev commented 4 years ago

@mattcarlotta Thanks for posting that- I didn't know that package exists.

Amaimersion commented 4 years ago

You can use remove-files-webpack-plugin for this.

Config:

new RemovePlugin({
    before: {
        include: [
            './dist'
        ]
    }
})

Note: i'm the creator of this plugin, so, it's a bit of an advertisement.

daltonamitchell commented 4 years ago

I think the issue is just that it doesn't output anything to console by default anymore. I had to set verbose: true and then manually add some files with obvious names like NO_NOT_DELETE.js so that I could verify it was removing things. It also appears that deletion now happens just before the new files are written so in my case it was so fast I didn't actually notice 😄

getsetgopi commented 3 years ago

I'm experiencing the same issue as mentioned above. I'm also using rimraf as an alternative.

In case anyone else runs into this issue, you can do one of these options:

In package.json

"scripts": {
  "build": "rimraf dist && webpack",
},

or

In webpack.config.js

const rimraf = require("rimraf");

if (process.env.NODE_ENV === "production") {
  rimraf("dist", {}, () => console.log("Removed all previous build assets.")); 
}

Phew!!! I was going insane with this issue. Thanks for the solution mate.

blazzy commented 3 years ago

or

In webpack.config.js

const rimraf = require("rimraf");

if (process.env.NODE_ENV === "production") {
  rimraf("dist", {}, () => console.log("Removed all previous build assets.")); 
}

Great suggestion. One note though: rimraf.sync might be a safer choice here than rimraf. Wouldn't want to risk blowing away files mid build!

haritha2112 commented 1 year ago

When using this, CleanWebpackPlugin does literally nothing.

output: {
        path: path.join(__dirname, 'dist/static/js/[hash]'),
        filename: '[name].js',
    },

Please just let us clear the whole dist folder. I am going to rimraf this for now.

I was facing a similar issue. I ended up using cleanOnceBeforeBuildPatterns to override the behavior:

new CleanWebpackPlugin({
    cleanOnceBeforeBuildPatterns: [path.join(__dirname, 'dist')]
}),

Now the dist folder gets removed for me