vbenjs / vite-plugin-compression

Use gzip or brotli to compress resources
MIT License
404 stars 31 forks source link

Generate compressed build both in gzip and brotli #4

Closed PRossetti closed 3 years ago

PRossetti commented 3 years ago

This plugin only gives the option of compressing into one single format format 'gzip','brotliCompress' ,'deflate','deflateRaw'but if I want the output both in .gz and .br I cannot do that. What about if my user's browser doesn't supports brotli? I would like to give they the option to fetch the gz version instead of the flat one...

Also, when compressing with brotliCompress the extension of the files remains as .gz when it should be .br

Thank you for your contribution, Best regards!

anncwb commented 3 years ago

Currently you can use multiple plugins to achieve

PRossetti commented 3 years ago

Currently you can use multiple plugins to achieve

I have tried that but keeps generating just one type of compression, I think because it only generates the files with .gz extension, never with .br. This is most likely a bug. If I select brotliCompress, the output file extension should be .br but it isn't.

Hope you or anybody can help, Best regards!

PRossetti commented 3 years ago

I was able to found a workaround for the issue I reported. The thing is, regardless of what compression algorithm you choose, the output files ext is by default .gz, even when this is incorrect. If I choose brotliCompress, ext should be .br. Conveniently this library lets you change the ext value, is one of the possible configurable options, so that issue can be manually fixed with it. The other issue was that I want both .gz and .br, and this can also be fixed thanks to that same ext parameter, calling the plug-in two times like this:

    viteCompression({ algorithm: 'gzip', ext: '.gz' }),
    viteCompression({ algorithm: 'brotliCompress', ext: '.br' }),

Best regards!