unjs / unplugin

Unified plugin system for Vite, Rollup, Webpack, esbuild, Rolldown, and more

Home Page:https://unplugin.unjs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vite - writeBundle not invoked

ilteoood opened this issue · comments

Environment

Node v20.10.0
Vite 5.1.4
Unplugin 1.6.0

Reproduction

Describe the bug

For Vite, during the development phase, the writeBundle hook is not invoked.
It is correctly invoked for webpack and rspack.

Additional context

No response

Logs

No response

@antfu is this something that can be addressed by unplugin? Or maybe is more related to vite itself?

I think it's designed by Vite dev server. You can try to write a vite plugin and see if writeBundle hook is invoked.

Hi @sxzz ,yes I already tried that and the behavior is the same. But since unplugin should be an abstraction layer between bundlers, IMO should try to give the same experience for all of them... Or at least make clear in the documentation the differences

We can indeed only offer limited compatibility. Considering that writeBundle literally means writing into a bundle, the vite dev server is a special case where the bundle isn't written to disk, so not calling this hook is expected behavior.

We can say the same for webpack's and rspack's dev server: nothing is wrote into the dist folder even there 🤔

It's out of unplugin's scope, as we just forward all the hooks available for Vite and it's up to Vite to decide when and how those hooks are called.

If you think the docs should be improved, we are open to PRs. Thanks for bringing this up.