Skip to content
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

feat: Enable HMR on shared Rsbuild configuration #2700

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Jan 14, 2025

By default Hot Module Rreplacement is configured to work with a localhost dev server

This server is responsible to serve the app and enable HMR

This wouldn't work with our apps because they are meant to be served by a local cozy-stack as a dev environment and so the cozy-app would try to connect to the HMR websocket using the cozy-stack's URL

Also the Rsbuild dev server is configured to serve built files from memory, so the /build folder would be empty and the cozy-stack wouldn't see any app

To fix this we can use both dev.writeToDisk and dev.client configurations

Then in order to benefit from this, the cozy-app should be run using rsbuild dev instead of rsbuild build --watch

More info:

In our projects, we found that using
`rsbuild build --watch --mode development` instead of just
`rsbuild build --watch` would speed up the re-build process

But when doing so, the bundler enables the
[fastRefresh](https://rsbuild.dev/plugins/list/plugin-react#fastrefresh)
mode from plugin-react

This mode does not work on `build` mode and trying to run the cozy-apps
would produce a blank screen with some `$RefreshSig$ is not defined`

This is because fastRefresh is meant to be run with `rsbuild dev`
command

So we want to disable this mode for all commands but `rsbuild dev`
By default Hot Module Rreplacement is configured to work with a
localhost dev server

This server is responsible to serve the app and enable HMR

This wouldn't work with our apps because they are meant to be served by
a local cozy-stack as a dev environment and so the cozy-app would try
to connect to the HMR websocket using the cozy-stack's URL

Also the Rsbuild dev server is configured to serve built files from
memory, so the `/build` folder would be empty and the cozy-stack
wouldn't see any app

To fix this we can use both `dev.writeToDisk` and `dev.client`
configurations

Then in order to benefit from this, the cozy-app should be run using
`rsbuild dev` instead of `rsbuild build --watch`

More info:
- web-infra-dev/rsbuild#4366
- https://rsbuild.dev/config/dev/write-to-disk#writing-to-disk
- https://rsbuild.dev/config/dev/client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant