📅  最后修改于: 2023-12-03 15:20:43.127000             🧑  作者: Mango
TypeScript Watch Mood is a feature of TypeScript that allows developers to watch for changes in their TypeScript files and automatically recompile them when changes are detected. This feature enables developers to save time while developing, as they don’t have to manually recompile their code every time they make changes.
To enable TypeScript Watch Mode, developers can run the following command in their terminal:
tsc --watch
This command will start the TypeScript compiler in Watch Mode, which will detect any changes made in the TypeScript files and recompile them. Developers can use this command in the root directory of their TypeScript project.
Developers can also add a configuration file called tsconfig.json
to their project to specify compiler options for TypeScript Watch Mode. In this file, they can define various options such as the target version of TypeScript to use, where to output compiled JavaScript files, and which files to exclude from compilation.
Here is an example of a tsconfig.json
file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "dist",
"declaration": true,
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
When TypeScript Watch Mode compiles TypeScript files, it outputs the compiled JavaScript files to the directory specified in the outDir
property of tsconfig.json
. This makes it easy for developers to keep track of their compiled JavaScript files.
TypeScript Watch Mode is an excellent feature that saves developers time and hassle by automatically recompiling their code when changes are made. By simply running the tsc --watch
command, developers can enable TypeScript Watch Mode and start developing with ease.