Rebuild Typescript file with pm2 watch

Viewed 368

I've added pm2 to one of the repos I work with because I want to restart the local server on crashes and such. App engine handles that for us in production (hopefully ). It's an amazing service really, and I was hoping to replace nodemon with it, but I can't get it to automate the Typescript build on restart.

I was messing around with scripts, and configs, with no luck. I basically need it to to run /node_modules/.bin/tsc to rebuild the dist folder on save. Otherwise, I end up with a stale file that's reloaded for no reason other than change detection.

I haven't found anything online, maybe I'm not looking hard enough, and I don't want to run ts-node as an alternative. I tried running nodemon before and after, with no avail.

Some files:

ecosystem.config.js

  apps: [
    {
      name: "example",
      script: ".",
      exp_backoff_restart_delay: 1000,
      watch_option: {
        persistent: true,
        ignoreInitial: true,
      }
};

package.json

"pm2-start": "pm2 start && pm2 logs",

I tried adding the npm run build before pm2 start and it worked the first time, but not on reloads.

Thanks in advance.

0 Answers
Related