To compile a ts file, use the command TSC xxx.ts; TSC xxx.ts -w can be used to compile and monitor changes to the file. When changes are detected, the file will be automatically compiled. If compiling file by file is too cumbersome, you can use the TSC command to compile all files at once. Compile and monitor all files using the command tc -w.


Using the configuration file to configure the compilation options, create a new tsconfig.json file

{ 
 	// Set the path to the file to compile
  // /**: indicates any folder
  // /*: indicates any file
  include: [
    ./src/ * * /*],// Set the file path that does not need to be compiled
  exclude: [
    "node_modules"].// Set the file to compile
  files: [
    app.js
  ],
  // Compiler options
  "compilerOptions": {
    // To specify the version of ts compiled to ES
    "target": "es5".// Used to specify the modularity specification to use
    "module": "commonjs".// Whether to generate a mapping information file for the code location after conversion and the code location before conversion
    "sourceMap": true.// The function module to be used, such as ES5, DOM, etc
    "lib": [].// Specify the output directory
    "outDir": "./dist".// Allows the compiler to compile JS, JSX files
    "allowJS": true.// Allows errors to be reported in JS files, usually with allowJS
		"checkJs": true,}}Copy the code

Because there are many configuration items, other configurations can be customized by Baidu or Google.