assets-webpack-plugin icon indicating copy to clipboard operation
assets-webpack-plugin copied to clipboard

`webpack-assets.json` gets removed if `output.clean` webpack option is enabled

Open Den-dp opened this issue 3 years ago • 1 comments

Describe the bug webpack-assets.json gets removed if the new output.clean webpack@5 option is used.

To Reproduce Steps to reproduce the behavior:

npm init -y
npm i webpack assets-webpack-plugin webpack-cli -D
npx webpack --mode production

Expected behavior webpack-assets.json file should be present in the output folder even if webpack configured with clean: true.

Webpack Config

const AssetsPlugin = require('assets-webpack-plugin');
const path = require('path');

module.exports = {
    output: {
        path: path.resolve(__dirname, 'dist'),
        clean: true
    },
    plugins: [
        new AssetsPlugin({
            useCompilerPath: true,
        })
    ]
};

Desktop (please complete the following information):

  • OS: Windows
  • Node version: v12.21.0
  • Plugin version: 7.1.0

Additional context I found that this is a regression that was introduced in 7.1.0 after fixing #327 via #392 Works fine if downgraded to the 7.0.0

npm i [email protected] -D
npx webpack --mode production

Den-dp avatar May 14 '21 17:05 Den-dp

I can confirm this.

A hotfix for this is:

const AssetsPlugin = require('assets-webpack-plugin');
const path = require('path');

module.exports = {
    output: {
        path: path.resolve(__dirname, 'dist'),
        clean: {
            keep: /webpack-assets\.json/
        }
    },
    plugins: [
        new AssetsPlugin({
            useCompilerPath: true,
        })
    ]
};

geldmacher avatar Jun 08 '21 11:06 geldmacher