Skip to content

Using two instances of CompressionPlugin causes files to be unintentionally deleted? #245

Open
@tomkelsey

Description

@tomkelsey
  • Operating System: OSX 11.2.2
  • Node Version: v12.14.1
  • NPM Version: 6.13.4
  • webpack Version: 5.28.0
  • compression-webpack-plugin Version: 7.1.2

Expected Behavior

  • Use Compression Plugin once to compress with brotli (same file name, different path - filename: '[path]/br/[file]'
  • Use Compression Plugin again to compress as gzip (same file name, same path - filename: '[file]')

Using Webpack 4 and version 6 of this plugin the output was as expected - a subdirectory with brotli compressed files and then the "original" files replaced with gzipped versions.

Actual Behavior

After upgrading to Webpack 5 and version 7, I was getting this error:

Conflict: Multiple assets emit different content to the same filename

And so I tried adding deleteOriginalAssets: true which fixed the error but it resulted in no brotli subdirectory being outputted.

I did some digging and it appears the brotli files are emitted but, at a guess, they then get deleted? Perhaps something to do with related assets and how webpack handles everything?

Code

I'm not familiar with the inner workings of webpack or it's plugins but I managed to bodge together a solution whereby the compression plugin supports multiple algorithms with one instance, that way you can choose to only invoke the deleteOriginalAssets logic if you're on the final pass and have already finished every other compression. The code is here: https://github.com/tomkelsey/compression-webpack-plugin/tree/multiple-algorithms I didn't do a PR as it's definitely not up to scratch and feel like there's probably a much more straightforward solution to this problem!

How Do We Reproduce?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions