How to compile typescript using npm command?

Well, I just wanted to know if there is any command that will directly compile typescript code and get the result. Right now, what am I doing, every time I make changes to the file, I have to re-run the inorder command to compile it.

npm start

This will launch the browser, and then I have to stop the execution using ctrl + c, and then I have to start the file using the npm command

node file_name

to see the result.

So I want to know if there is any npm command that will compile the .ts file and see the changes I made in the file when I run the file with

node file_name

Team

+4
source share
2

tsc (typescript ) --watch.

:

  • typescript tsconfig.json
  • tsc --watch, , .ts, tsc (, typescript, ./dist)
  • nodemon, , ./dist , , .

( package.json), ( npm install --save typescript nodemon npm-run-all rimraf)

"scripts": {
    "clean": "rimraf dist",
    "start": "npm-run-all clean --parallel watch:build watch:server --print-label",
    "watch:build": "tsc --watch",
    "watch:server": "nodemon './dist/index.js' --watch './dist'"
}

npm start

+11

, @ThomasThiebaud. , dist/, nodemon .

"scripts": {
    "clean": "rimraf dist",
    "build": "tsc",
    "watch:build": "tsc --watch",
    "watch:server": "nodemon './dist/index.js' --watch './dist'",
    "start": "npm-run-all clean build --parallel watch:build watch:server --print-label"
  },

npm start, .

+2

Source: https://habr.com/ru/post/1667767/


All Articles