static-web-apps-cli
static-web-apps-cli copied to clipboard
Hot reload staticwebapp.config.json changes when server is running
Is your feature request related to a problem? Please describe.
We need to support hot reloading the staticwebapp.config.json file whenever it got edited, without restarting the server.
Describe alternatives you've considered Currently, users need to kill the server and restart it so their changes get applied.
Additional context
Currently, we read and cache the staticwebapp.config.json when starting the server:
https://github.com/Azure/static-web-apps-cli/blob/722616015d16059d697428bd44f143ad72857b02/src/msha/server.ts#L146-L154
An easy implementation would be to move the call to await handleUserConfig(...) inside:
https://github.com/Azure/static-web-apps-cli/blob/722616015d16059d697428bd44f143ad72857b02/src/msha/server.ts#L49-L51
This is much needed feature, because it is really cumbersome for the user to restart the server every time he make changes in config file. Thanks for pointing out Wassim, will work on this.
@manekinekko for loading swa-config file we're using require here which is storing the files contents in a cache and is not reloading the contents of the file. Is there any workaround for this?
You can either clear the cached file before calling require() using such a helper function:
function clearCacheAndRequire(module: string) {
delete require.cache[require.resolve(module)];
return require(module);
}
Or, you can use fs.readFileSync() to always read the file from disk.
@sgollapudi77 did you manage to finish work on this feature?
No Wassim, I didn't get chance to work on this feature.