GorvGoyl
GorvGoyl

Reputation: 49220

How to auto-restart VSCode debugger whenever I change a file in Firebase Typescript project?

I have a typescript Firebase project for which I'd like to watch and restart debugger on file change.

my current script to run dev server:

"debug:func": "firebase emulators:start --only functions --inspect-functions 9230",

launch.json:

{
      "type": "pwa-node",
      "name": "Attach",
      "port": 9230,
      "request": "attach",
      "skipFiles": ["<node_internals>/**"],
      "restart": true
    }

Whenever I make a change in *.ts file:

  1. I need to compile it.. tsc
  2. restart debugger (ctrl+shift+F5) in order to debug the program.

How can I automate both steps (1 & 2) whenever I make a change to ts file?

Upvotes: 0

Views: 2084

Answers (1)

Kelvin Schoofs
Kelvin Schoofs

Reputation: 8718

You can try this combination of scripts:

  • build:watch which would simply be tsc in watch mode, i.e. tsc -w
  • debug:func: Your existing script
  • debug:watch: nodemon --watch out --ext js --exec npm run debug:func

The debug:watch makes use of nodemon, which will start your debug:func script and restart it every time a *.js file changes in your out directory. That means that with build:watch, your TS files will automatically recompile whenever they change, which will trigger nodemon to restart your debug:func.

It also requires the "restart": true in your task you have, along with a static inspect port, which you also have.

Upvotes: 1

Related Questions