-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using two instances of CompressionPlugin causes files to be unintentionally deleted? #245
Comments
Please do not ignore |
Hi - sorry - I'm not familiar with the test framework or webpack so hoped sharing the issue, my written explanation and my workaround was better than saying nothing at all. That said - I appreciate it makes it a lot more difficult for someone to verify the issue or debug it. With that in mind I've had a go at hacking something together (sorry if I've got the wrong end of the stick!):
I believe you'll see from the console log that there's no If you remove
You should see that the |
You need to use different |
I.e. you will have multiple files with the same name https://github.com/webpack-contrib/compression-webpack-plugin/blob/master/src/index.js#L27 |
Hi, Thanks for the speedy responses! For the setup I'm using elsewhere I ideally need to keep the filename the same but with a different path - perhaps it was by happy coincidence or fluke but it worked as I'd hoped on an earlier version of the plugin and with Webpack 4. The filename option provided to CompressionWebpackPlugin is different - "[path]/br/[file]" vs "[file]", but I'm guessing you're referring to the filename itself? My rather elaborate workaround (https://github.com/tomkelsey/compression-webpack-plugin/tree/multiple-algorithms) appears to solve the specific issue I'm facing but didn't know if there was a more straightforward solution. |
hm, maybe bug, can you send broken test? |
Hey - sorry if I'm misunderstanding but the test I shared above highlights the issue I believe. I think the output of
|
Yep, bug |
Try to fix it in near future |
When you use But you case is more edge 😄 here two solutions: use |
In theory you need |
I would call it a limitation. Will be great if you can use |
Hi, Thanks for looking into this. I've realised the "solution" I linked above using multiple algorithms with one instance of the plugin doesn't work properly. Webpack seems to be losing track of what files had been deleted/created (which fits with the potential weird behaviour you mentioned above). I've taken your advice and now use I've then pushed the problem to another plugin (https://github.com/MikaAK/s3-plugin-webpack) which I've rejigged so that it uploads the Thanks again for your efforts in trying to resolve this! |
There is no webpack problems, it is hard for us, I can implement this, but it is not easy (also it reduce performance), in some cases limitation is good 😄 |
Expected Behavior
filename: '[path]/br/[file]'
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?
The text was updated successfully, but these errors were encountered: