KevinNovak / Discord-Bot-TypeScript-Template

Discord bot - A discord.js bot template written with TypeScript.
MIT License
477 stars 86 forks source link

Can we have hot reload? #57

Open Dizotoff opened 1 year ago

Dizotoff commented 1 year ago

Hi.

First of all, thanks a lot for this template. It's excellent to have it.

Would it be possible to add a hot reload to it? Would be great if its re-build and re-started automatically.

I tried few implementations, but they wouldn't work:

"dev:hot0": "nodemon --watch src --exec \"npm run dev\"",

"dev:hot1": "concurrently \"npm run build\" \"nodemon --watch src dist/start-bot.js\"",

Both of them stuck after change event triggered. Any ideas what might be wrong?

matheus-caldeira commented 1 year ago

Hi,

Dependencies:

yarn add -D nodemon ts-node tsc-watch

package.json:

{
  "scripts": {
    "dev": "tsc-watch --onSuccess \"yarn watch\"",
    "dev:manager": "tsc-watch --onSuccess \"yarn watch:manager\"",
    "watch": "nodemon --watch './**/*.{ts}' --exec ts-node src/start-bot.ts",
    "watch:manager": "nodemon --watch './**/*.{ts}' --exec ts-node src/manager-bot.ts"
  }
}

tsconfig.json

{
  "compilerOptions": { .... },
  "ts-node": {
    "esm": true
  }
}
Dizotoff commented 1 year ago

Thanks a lot @matheus-caldeira

michael-delle commented 1 year ago

I like using PM2 so I just added "watch" to the process.json file

"watch": ["dist/"]