An npm script is a named command in the scripts section of package.json. It replaces long, easy-to-forget command lines with a short npm command such as npm start. section 5.5.2
Starting a TypeScript watcher
A tools/package.json file can define a start script that runs tsc-watch and executes the compiled program after successful compilation. Run it from the tools folder with npm start. section 5.5.2
Listing 5.17 Adding to the scripts section of the package.json file in the tools folder
{
"name": "tools",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc-watch --onsuccess \"node dist/index.js\""
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"tsc-watch": "^6.0.0",
"typescript": "^5.0.2"
}
}
Inspect a complete scripts configuration that combines tsc-watch with node dist/index.js; use b10 for the command that invokes it. section 5.5.2
Scripts also provide a single entry point for development tools:
- Define separate commands such as json for json-server and wds for webpack serve. section 17.1
- Combine commands with npm-run-all so one npm start launches the web service and development server together. section 17.1
- Expose common application tasks such as build, test, lint, and e2e alongside start. section 18.1.1
Listing 17.3 Configuring the development tools in the package.json file in the webapp folder
...
"scripts": {
"json": "json-server data.js -p 4600",
"wds": "webpack serve",
"start": "npm-run-all -p json wds"
},
...
Compare a package.json configuration that starts json-server and webpack in parallel, then invoke it with npm start using b14. section 17.1



