1

I have to manually remove

dist/app.js to see the latest changes. I have this start script in my package.json

"start": "tsc && node dist/app.js"

is it by default node just keep the dist folder so I have to remove it before I compile it?

Judy Allen
  • 83
  • 1
  • 7

2 Answers2

1

To remove the dist folder you can have your package.json file as follows:

{
  "name": "sample",
  "version": "1.0.0",
  "description": "",
  "main": "dist/app.js",
  "scripts": {
    "clean": "rm -rf dist",
    "build": "tsc",
    "start": "npm run clean && npm run build && node dist/app.js"
  },
  "keywords": [],
  "author": "Jayant Malik",
  "license": "MIT",
  "dependencies": {
    "nodemon": "^2.0.6",
    "typescript": "^4.1.2"
  }
}
Jayant Malik
  • 1,328
  • 8
  • 11
0

TS won't remove files in dist folder if it's not during development mode;

See this issue: https://github.com/Microsoft/TypeScript/issues/13722

A simple solution would be to remove the dir (you can use rimraf for OS robustness)

Aviad
  • 3,424
  • 3
  • 14
  • 21
  • is using ts-node better than mere ts? in many node project I don't see their start script have something like rimraf – Judy Allen Dec 01 '20 at 10:14
  • This is unrelated to the original question, but tldr - use tsc. Read here for more https://stackoverflow.com/questions/51448376/whats-the-difference-between-tsc-typescript-compiler-and-ts-node – Aviad Dec 01 '20 at 15:06