Skip to content

Support Bun's HMR #81

@MioYiSama

Description

@MioYiSama

Documentation: https://bun.com/docs/bundler/hot-reloading

Bun implements a client-side HMR API modeled after Vite's import.meta.hot API

So most of the code implemented for Vite can be reused for Bun's implementation.

However, this check is often not needed as Bun will dead-code-eliminate calls to all of the HMR APIs in production builds.
For this to work, Bun forces these APIs to be called without indirection. That means the following do not work:

The only thing to consider is that "const hot = import.meta.hot;" cannot work in Bun (which results in "error: import.meta.hot.data cannot be used indirectly."), i.g. _$$refresh("vite", import.meta.hot, _REGISTRY);. All destructured hot calls need to be replaced with import.meta.hot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions