Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

TypeScript tsconfig.json


May 07, 2021 TypeScript


Table of contents


tsconfig.json

Overview

If there is a tsconfig.json it means that the directory is the root of the TypeScript project. tsconfig.json specifies the root file and compilation options for compiling the project. A project can be compiled in one of the following ways:

Use tsconfig.json

  • Calling tsc without any input tsc tsconfig.json searches up the parent directory step by step.
  • tsc without any input files, and use the --project -p to specify tsconfig.json file.

When an input file is specified on the command line, tsconfig.json is ignored.

Example

tsconfig.json sample file:

  • Use "files" property
{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "outFile": "../../built/local/tsc.js",
        "sourceMap": true
    },
    "files": [
        "core.ts",
        "sys.ts",
        "types.ts",
        "scanner.ts",
        "parser.ts",
        "utilities.ts",
        "binder.ts",
        "checker.ts",
        "emitter.ts",
        "program.ts",
        "commandLineParser.ts",
        "tsc.ts",
        "diagnosticInformationMap.generated.ts"
    ]
}
  • Use "include" and "exclude"

    {
        "compilerOptions": {
            "module": "commonjs",
            "noImplicitAny": true,
            "removeComments": true,
            "preserveConstEnums": true,
            "outFile": "../../built/local/tsc.js",
            "sourceMap": true
        },
        "include": [
            "src/**/*"
        ],
        "exclude": [
            "node_modules",
            "**/*.spec.ts"
        ]
    }
    

Details

"compilerOptions" ignored, and the compiler uses the default values. See the full list of compiler options (./compiler Options.md) here.

"files" a list that contains relative or absolute file paths. "include" and "exclude" properties specify a list of fileglob match patterns. The supportedglob wildcards are:

  • * Match 0 or more characters (excluding directory separators)
  • ? Match any character (excluding directory separators)
  • **/ Recursive matches any subdirection

If a section of aglob * pattern contains only . .* then only the supported file extension types are .ts .tsx .d.ts allowJs true true contain .js and .jsx .js

If "files" "include" the compiler defaults to all TypeScript files .ts .d.ts and .tsx) in the current .tsx "exclude" J S files .js .jsx are also included if allowJs are set to true I f "files" "include" the compiler combines them and includes them. Files "outDir" are always excluded by "files" exclude them with exclude).

Files "include" can be "exclude" property. H owever, files "files" by the "files" property are always included, regardless of "exclude" is set. If there is no special "exclude" excludes node_modules bower_components and jspm_packages jspm_packages default.

Any files referenced by a file specified by "files"或 or 指定的文件所引用的文件也会被包含进来。 A.ts 引用了 B.ts, so B.ts cannot be excluded 不能被排除,除非引用它的 it is by A.ts in the "exclude" list. ,因此

tsconfig.json be an empty file, so all default files (as described above) are compiled with the default configuration options.

The compilation options specified on the command line tsconfig.json file.

compileOnSave

Setting the compileOnSave the IDE to rebuild the tsconfig.json saving it.

{
    "compileOnSave": true,
    "compilerOptions": {
        "noImplicitAny" : true
    }
}

To support this feature requires Visual Studio 2015, TypeScript 1.8.4 or more and an atom-typescript plug-in installed.

Mode

See mode here: http://json.schemastore.org/tsconfig .