From 160705b24d6e4ab8b6eccd3047dacaaae9cf7bc0 Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Tue, 14 Jan 2025 16:50:31 +0100 Subject: [PATCH] feat: Enable HMR on shared Rsbuild configuration 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: - https://github.com/web-infra-dev/rsbuild/discussions/4366 - https://rsbuild.dev/config/dev/write-to-disk#writing-to-disk - https://rsbuild.dev/config/dev/client --- config/rsbuild-config-cozy-app/getRsbuildConfig.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/rsbuild-config-cozy-app/getRsbuildConfig.js b/config/rsbuild-config-cozy-app/getRsbuildConfig.js index 16614aef42..a961f2a4bd 100644 --- a/config/rsbuild-config-cozy-app/getRsbuildConfig.js +++ b/config/rsbuild-config-cozy-app/getRsbuildConfig.js @@ -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: '' + } + }, output: { cleanDistPath: true, filename: {