Skip to content

Commit

Permalink
feat: Enable HMR on shared Rsbuild configuration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ldoppea committed Jan 15, 2025
1 parent e51382e commit 160705b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config/rsbuild-config-cozy-app/getRsbuildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ function getRsbuildConfig({
}
})
],
// Used when running `rsbuild dev`
// By default the dev configuration would serve app's files from localhost:300
// which is not what we want as we expect to serve apps from a local cozy-stack
dev: {
// this param tells to put files in the output folder so we can access them from cozy-stack
writeToDisk: true,
// this param tells the cozy-app which URL to use for the HMR websocket, otherwise it would use the cozy-stack URL by default
client: {
host: 'rsbuild.cozy.tools', // we cannot use localhost because chromium browsers prevent unsecure websockets to localhost
protocol: 'ws',
port: '<port>'
}
},
output: {
cleanDistPath: true,
filename: {
Expand Down

0 comments on commit 160705b

Please sign in to comment.