johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

kromit opened this issue · comments

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'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.")); 
}

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

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.

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 😄

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.

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!

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