Typescript configuration files

Tsconfig. json configuration file

{
  "compilerOptions": {
    "module": "commonjs"."target": "es5"."outDir": "build"."baseUrl": ".",},"include": [
    "src/**/*.ts"]."exclude": [
    "node_modules"],}Copy the code

Listen for changes to typescript files

The output directory for ts files is build, according to outDir in tsconfig.json.

"watch-ts": "tsc -w".Copy the code

Listen to the TS files in the SRC directory. If the ts files in the SRC directory change, recompile the files and output the compilation results to the build directory.

Listen for changes to javascript files

Listen for the js file in the output directory build and re-execute when the JS file is sent for change.

"serve": "nodemon -w build/index.js".Copy the code

Nodemon-w is short for nodemon — Watch.

The startup script

  "scripts": {
    "start": "concurrently \"npm run watch\" \"npm run serve\""."serve": "nodemon -w build/index.js"."watch": "npm run clean && tsc -w"."clean": "rimraf ./build",},Copy the code

Reference code

Reference code