johnagan / clean-webpack-plugin

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

Plugin stopped removing files v2 #149

Closed MerApelsin closed 5 years ago

MerApelsin commented 5 years ago

Issue description or question

Plugin stopped removing files in dist/ folder, had it working before i added css extraction but I don't think those two should affect each other. Tried googling around but mostly find answers for v1. No clue what I broke but grateful for any hints or insights :)

I've read the "Additional Upgrade Information" but didn't find my issue/way to solve it there. Tried a few patterns, had ['*/ ','!images*','!manifest.json'] working before but as said, somewhere along the lines it broke.

The plugin logs the files in terminal but doesn't do anything with em, neither in --watch or when building, even if the file isn't imported anywhere/used be webpack at all, such as test.js (empty) which I added as a kind of control file:

webpack is watching the files…

clean-webpack-plugin: dry dist/js
clean-webpack-plugin: dry dist/js/background.js
clean-webpack-plugin: dry dist/js/popup.js
clean-webpack-plugin: dry dist/js/test.js
clean-webpack-plugin: dry dist/popup.css
clean-webpack-plugin: dry dist/popup.html
Hash: 8f633eb21de2e45d114e
Version: webpack 4.35.0
Time: 815ms

Webpack Config

const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
var HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    entry: {
        'js/background': './src/js/background.js',
        'js/popup': './src/interface/popup.js',
    },
    plugins: [
      new CleanWebpackPlugin({
        //root: '/',
        dry: true,
        verbose: true,
        cleanOnceBeforeBuildPatterns: ['**/*','!images/*','!images*','!manifest.json'],
      }),
      new HtmlWebpackPlugin({
        filename: 'popup.html',
        template: './src/interface/popup.html',
        inject: 'head',
        excludeAssets: [/background.js/]
      }),
      new HtmlWebpackExcludeAssetsPlugin(),
      new MiniCssExtractPlugin({
        filename: './popup.css'
      })
    ],
    output: {
        path: path.resolve(__dirname, 'dist/'),
        filename: '[name].js'
    },

    module: {
        rules: [
          {
            test: /\.m?js$/,
            exclude: /(node_modules|bower_components)/,
            use: {
              loader: 'babel-loader'
            }
          },
          {
            test: /\.scss$/,
            use: [
                MiniCssExtractPlugin.loader,
                "css-loader",
                "sass-loader"
            ]
          },
          {
            test: /\.css$/,
            use: [
              {
                loader: MiniCssExtractPlugin.loader,
              },
              'css-loader',
            ],
          },
        ]
      },
};

Environment

System:
    OS: macOS 10.14.5
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 6.07 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.4.0 - /usr/local/bin/node
    Yarn: 1.16.0 - ~/.yarn/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  npmPackages:
    clean-webpack-plugin: ^3.0.0 => 3.0.0 
    webpack: ^4.35.0 => 4.35.0 
chrisblossom commented 5 years ago

Are you saying the files are not being deleted? I suspect you need to remove dry: true, from your configuration.

MerApelsin commented 5 years ago

Well damn, that was indeed it. Don't get why it worked with it earlier (since docs recommend it initially). Thanks for the time taken to figure that one out! 👍 Closing this issue.