Support Vite
It would be nice if this plugin was built in a way that it would work also with Vite.
https://github.com/keithamus/rollup-plugin-brotli works with Vite and the relevant difference seems to be that rollup-plugin-brotli gathers the files in generateBundle and then compresses the files in writeBundle. Vite does its own internal processing in the generateBundle phase so if you use this plugin today with Vite, it seems to work fine but actually you are compressing invalid versions of the files (they still contain placeholders like ´VITE__PRELOAD`)
This has earlier been discussed in Vite's issue tracker also https://github.com/vitejs/vite/issues/1960
Hi @Artur- ,
thanks for your report. I wanted to try out Vite for quite some time now, but was totally oblivious that this is probably the perfect opportunity for it.
The funny thing ist that I rewrote this plugin in v2.0 to do all of its work in the generateBundle phase after feedback from the rollup core team that this is the idiomatic way to write additional files (https://github.com/rollup/rollup/issues/2305). Sadly, Vite seems to add some of its own plugins after any user-defined plugins even if I use the enforce: 'post' flag, so there currently does not seem to be a way around using the writeBundle hook like you said.
Initial tests are looking promising, I will try to release a new (likely major) version of this plugin over the weekend to add proper Vite support ☺️
I just published v3.0.0.
Could you verify that it works as expected now in your Vite project?
I also published v2.5.1 that fails the build when it encounters the __VITE__PRELOAD__ token. This should hopefully save a few nerves for people who already use v2.x together with Vite and haven't noticed the incompatibility yet, or do not have any code yet that actually injects the token into the bundle.
I just added this plugin on my project using Vitejs, and it seems to work just fine!