I'm authoring an Azure Function in TypeScript in VS Code. If I start the Azure Functions host locally (either by using F5 in VS Code or by running "npm start" from the command line), everything runs fine. However, when I make and save a change to my TypeScript code, the local Azure Function host doesn't pick up on the change/restart the function. I have to manually stop/restart it.
The default "start" entry in package.json appears to be trying to achieve this:
"start": "npm run start:host & npm run watch"
But running "npm start" does not appear to cause the restart-on-change behavior. I may not be looking in the right place, but it doesn't seem like the second command is even executing at all. That said, even if I have tsc watch running from inside VS Code while "func start" is running elsewhere, the Azure Function host still seems to need to be manually restarted after the transpiling happens.
Is there a way to make the local Azure Function host automatically restart whenever I make changes to my TypeScript code? Am I missing something about how this is supposed to work?
Thanks!
From doing more research, it seems like the issue is that the single ampersand (&) in the package.json does not run the commands in parallel on Windows. The Windows cmd shell runs commands separated by & in serial. So while this command may work as intended in bash or something else, it does not work when run on Windows.
It looks like you could fix this in a Windows-specific way by using something like what is mentioned in one of the answers here: https://stackoverflow.com/a/36275359/7117308
"start": "start npm run start:host & start npm run watch"
Or, to avoid extra cmd windows:
"start": "start npm run watch & npm run start:host"
As I mentioned, that's a Windows-specific solution, of course. That same stackoverflow post I referenced above shows options for platform-agnostic ways of achieving this.