Azure / static-web-apps-cli

Azure Static Web Apps CLI ✨
https://aka.ms/swa/cli-local-development
MIT License
599 stars 119 forks source link

Hot reload staticwebapp.config.json changes when server is running #264

Open manekinekko opened 3 years ago

manekinekko commented 3 years ago

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

sgollapudi77 commented 3 years ago

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.

sgollapudi77 commented 3 years ago

@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?

manekinekko commented 3 years ago

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.

manekinekko commented 2 years ago

@sgollapudi77 did you manage to finish work on this feature?

sgollapudi77 commented 2 years ago

No Wassim, I didn't get chance to work on this feature.