Angular应用中tsconfig.json文件配置说明及配置全局路径映射

本文深入探讨了TypeScript的配置文件tsconfig.json的选项,包括编译器选项、全局路径映射等关键配置。详细解释了如编译、输出、模块解析、严格类型检查等设置,旨在帮助开发者更好地理解和优化TypeScript项目构建过程。


1. tsconfig.json文件中的选项配置

TypeScript编译器配置文件的JSON模式

{
   
   
  "title": "JSON schema for the TypeScript compiler's configuration file",
  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {
   
   
    "filesDefinition": {
   
   
      "properties": {
   
   
        "files": {
   
   
          "description": "如果tsconfig.json文件中不存在files或者include属性, 则编译器包括包含目录和子目录中的所有文件,exclude属性指定的文件除外. 当指定files属性时, 仅包括files属性指定的文件和include属性指定的文件.",
          "type": "array",
          "items": {
   
   
            "type": "string"
          }
        }
      }
    },
    "excludeDefinition": {
   
   
      "properties": {
   
   
        "exclude": {
   
   
          "description": "指定要排除在编译之外的文件列表. exclude属性仅仅影响include属性包含的文件,而不影响files属性. 全局模式需要TypeScript 2.0或更改版本.",
          "type": "array",
          "items": {
   
   
            "type": "string"
          }
        }
      }
    },
    "includeDefinition": {
   
   
      "properties": {
   
   
        "include": {
   
   
          "description": "Specifies a list of glob patterns that match files to be included in compilation. If no 'files' or 'include' property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories except those specified by 'exclude'. Requires TypeScript version 2.0 or later.",
          "type": "array",
          "items": {
   
   
            "type": "string"
          }
        }
      }
    },
    "compileOnSaveDefinition": {
   
   
      "properties": {
   
   
        "compileOnSave": {
   
   
          "description": "Enable Compile-on-Save for this project.",
          "type": "boolean"
        }
      }
    },
    "extendsDefinition": {
   
   
      "properties": {
   
   
        "extends": {
   
   
          "description": "Path to base configuration file to inherit from. Requires TypeScript version 2.1 or later.",
          "type": "string"
        }
      }
    },
    "compilerOptionsDefinition": {
   
   
      "properties": {
   
   
        "compilerOptions": {
   
   
          "type": "object",
          "description": "Instructs the TypeScript compiler how to compile .ts files.",
          "properties": {
   
   
            "charset": {
   
   
              "description": "The character set of the input files.",
              "type": "string"
            },
            "composite": {
   
   
              "description": "Enables building for project references.",
              "type": "boolean"
            },
            "declaration": {
   
   
              "description": "Generates corresponding d.ts files.",
              "type": "boolean"
            },
            "declarationDir": {
   
   
              "type": "string",
              "description": "Specify output directory for generated declaration files. Requires TypeScript version 2.0 or later."
            },
            "diagnostics": {
   
   
              "description": "Show diagnostic information.",
              "type": "boolean"
            },
            "emitBOM": {
   
   
              "description": "Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.",
              "type": "boolean"
            },
            "emitDeclarationOnly": {
   
   
                "description": "Only emit '.d.ts' declaration files.",
                "type": "boolean"
            },
            "incremental": {
   
   
              "description": "启用增量编译.",
              "type": "boolean"
            },
              "tsBuildInfoFile": {
   
   
              "description": "指定用于存储增量编译信息的文件.",
              "type": "string"
            },

            "inlineSourceMap": {
   
   
              "description": "Emit a single file with source maps instead of having a separate file.",
              "type": "boolean"
            },
            "inlineSources": {
   
   
              "description": "Emit the source alongside the sourcemaps within a single file; requires --inlineSourceMap to be set.",
              "type": "boolean"
            },
            "jsx": {
   
   
              "description": "Specify JSX code generation: 'preserve', 'react', or 'react-native'.",
              "enum": [ "preserve", "react", "react-native" ]
            },
            "reactNamespace": {
   
   
              "description": "Specifies the object invoked for createElement and __spread when targeting 'react' JSX emit.",
              "type": "string"
            },
            "listFiles": {
   
   
              "description": "Print names of files part of the compilation.",
              "type": "boolean"
            },
            
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值