webpack-contrib / compression-webpack-plugin

Prepare compressed versions of assets to serve them with Content-Encoding
MIT License
1.41k stars 108 forks source link

Bug: `deleteOriginalAssets: true` removes the `.js.LICENSE.txt` files #389

Open mman opened 4 months ago

mman commented 4 months ago

Bug report

We are using CompressionPlugin as the last step of our webpack config. When specifying deleteOriginalAssets: true it does remove original .js file when .js.gz is produced, but it also accidentally deletes accompanying .js.LICENSE.txt

Actual Behavior

With deleteOriginalAssets: false:

-rw-r--r--  1 mman  staff  1423307 May 21 11:42 60.96569f9e.js
-rw-r--r--  1 mman  staff     2881 May 21 11:42 60.96569f9e.js.LICENSE.txt
-rw-r--r--  1 mman  staff   421274 May 21 11:42 60.96569f9e.js.gz
-rw-r--r--  1 mman  staff   160371 May 21 11:42 main.c742e74d.js
-rw-r--r--  1 mman  staff     1818 May 21 11:42 runtime-main.17566f78.js

With deleteOriginalAssets: true:

-rw-r--r--  1 mman  staff   421274 May 21 11:42 60.96569f9e.js.gz
-rw-r--r--  1 mman  staff   160371 May 21 11:42 main.c742e74d.js
-rw-r--r--  1 mman  staff     1818 May 21 11:42 runtime-main.17566f78.js

Expected Behavior

.js.LICENSE.txt should remain in place.

How Do We Reproduce?

This bug is affecting the following project where I summarised the issue as https://github.com/victronenergy/venus-html5-app/issues/370.

Main webpack config is located here: https://github.com/victronenergy/venus-html5-app/blob/master/config/webpack.config.js

Please paste the results of npx webpack-cli info here, and mention other relevant information

€ npx webpack-cli info

  System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 81.77 MB / 16.00 GB
  Binaries:
    Node: 20.12.0 - /opt/homebrew/opt/node@20/bin/node
    npm: 10.5.0 - /opt/homebrew/opt/node@20/bin/npm
  Browsers:
    Chrome: 125.0.6422.60
    Safari: 17.5
  Packages:
    babel-loader: ^9.1.0 => 9.1.2 
    case-sensitive-paths-webpack-plugin: 2.3.0 => 2.3.0 
    compression-webpack-plugin: ^11.0.0 => 11.0.0 
    css-loader: ^6.7.3 => 6.7.3 
    css-minimizer-webpack-plugin: ^4.2.2 => 4.2.2 
    eslint-webpack-plugin: ^3.2.0 => 3.2.0 
    file-loader: ^6.2.0 => 6.2.0 
    html-webpack-plugin: ^4.5.2 => 4.5.2 
    pnp-webpack-plugin: ^1.6.4 => 1.7.0 
    postcss-loader: ^7.0.2 => 7.1.0 
    react-svg-loader: ^3.0.3 => 3.0.3 
    resolve-url-loader: ^5.0.0 => 5.0.0 
    sass-loader: ^10.0.5 => 10.4.1 
    style-loader: ^3.3.1 => 3.3.2 
    terser-webpack-plugin: ^4.2.3 => 4.2.3 
    url-loader: 4.1.1 => 4.1.1 
    webpack: ^5.75.0 => 5.76.2 
    webpack-cli: ^5.0.1 => 5.0.1 
    webpack-dev-middleware: ^6.0.1 => 6.0.2 
    webpack-dev-server: ^4.11.1 => 4.13.1 
    webpack-manifest-plugin: ^5.0.0 => 5.0.0 
    workbox-webpack-plugin: ^6.5.4 => 6.5.4 
mman commented 4 months ago

Just tried to update to the latest version of CompressionPlugin and the bug is still there:

    compression-webpack-plugin: ^11.0.0 => 11.1.0 
alexander-akait commented 4 months ago

You can write a custom function for this option deleteOriginalAssets, i.e. return false for such files, but I agree we should not delete LICENSE files here

mman commented 4 months ago

I assume it would be best if the plugin works out of the box..., compress only what is needed and never delete stuff it should not ...

that's why I tested on fresh create-react-app with no modifications... to see whether any of our customisations are not at fault...