CleanWebpackPlugin does not clean in Webpack 4.0.1

Do you want to request a feature or report a bug?

What is the current behavior?
I am using latest version of webpack 4.0.1 with "clean-webpack-plugin": "^0.1.18" it looks like in this plugin does not clean dist folder when I build.
If the current behavior is a bug, please provide the steps to reproduce.
May be better to you another way to clean dist folders

package.json

 "scripts": {
    "start": "webpack-dev-server -w --hot --progress --config webpack/dev.js",
    "build": "webpack --progress --config webpack/prod.js",
}

webpack/common.js

const CleanWebpackPlugin = require('clean-webpack-plugin')
const extractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')

const path = require('path')

// initialize version.js
require('child_process').exec('node ' + path.resolve('./../scripts/setAppVersion.js'), {cwd: '../'}, function (err, stdout, stderr) {
    console.log(err)
})

module.exports = {
    mode: 'development',
    devtool: 'source-map',
    entry: './src/main.js',
    plugins: [
        new CleanWebpackPlugin(['dist']),
        new extractTextPlugin({
            filename: 'bundle.css',
            disable: false,
            allChunks: true,
        }),
        new HtmlWebpackPlugin({
            template: './src/index.ejs',
            hash: true,
        }),
    ],
    output: {
        filename: '[name].[chunkhash].js',
        path: path.resolve(__dirname, '../dist'),
        publicPath: '/',
    },
    module: {
        rules:[
            {
                test: /\.js$/,
                use: 'eslint-loader?{fix:true}',
                exclude: /node_modules/,
                enforce: 'pre',
            },
            {
                test: /\.html$/,
                exclude: /node_modules/,
                use: 'file-loader?name=[name].[ext]',
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader',
            },
            // TODO remove extractTextPlugin after delete all .scss in react-components
            {
                test: /\.scss$/,
                use: extractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: 'css-loader!sass-loader',
                }),
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: 'babel-loader',
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                loader: 'file-loader?name=fonts/[name].[ext]',
            },
            {
                test: /\.png$/,
                use: 'file-loader',
            },
        ],
    },
    performance: {hints: false},
    optimization: {splitChunks: {chunks: 'all'}},
}

webpack.prod.js

const merge = require('webpack-merge')
const webpack = require('webpack')

const common = require('./common.js')

module.exports = merge(common, {
    mode: 'production',
    devtool: false,
    plugins: [new webpack.optimize.ModuleConcatenationPlugin()],
})

What is the expected behavior?
Expected to delete dist folder or dist files before each build.
If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Node – v9.5.0
clean-webpack-plugin – 0.1.18
“webpack”: “^4.0.1”,
“webpack-bundle-size-analyzer”: “^2.7.0”,
“webpack-cli”: “^2.0.9”,
“webpack-dev-server”: “^3.1.0”,
“webpack-merge”: “^4.1.2”

Author: Fantashit

1 thought on “CleanWebpackPlugin does not clean in Webpack 4.0.1

  1. for now I just use this one
    “build”: “rimraf dist && webpack –progress –config webpack/prod.js”,

Comments are closed.