Skip to content

Instantly share code, notes, and snippets.

@zxhfighter
Last active March 11, 2019 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zxhfighter/c56662543ca3d3d4aa6f82f46f534e69 to your computer and use it in GitHub Desktop.
Save zxhfighter/c56662543ca3d3d4aa6f82f46f534e69 to your computer and use it in GitHub Desktop.
tsconfig desc
{
    "extends": "../../tsconfig.json",
    "compilerOptions": {
        // allowSyntheticDefaultImports,这个字段实际只起到检查的作用,不会对编译后的代码有任何影响
        // 只有当导出 commonjs 的时候,才会加上兼容性的代码,如果是 ES6 的格式则原样输出
 
        // 而 esModuleInterop 就不一样,实际上开启这个字段的时候,默认也是会开 allowSyntheticDefaultImports
        // 并且对于编译后的代码也做了兼容。还要注意的是这个字段只有当把代码编译成 commonJS 的时候才会起作用
        "allowSyntheticDefaultImports": true,
 
        // 生成 .d.ts 类型文件
        "declaration": true,
 
        // 代码中输出设计类型信息,引用 tslib
        // tslib.__decorate([Input(), tslib.__metadata("design:type", Array)])
        "emitDecoratorMetadata": true,
 
        // 生成 .js.map 文件
        "sourceMap": true,
 
        // 常用方法从 tslib 引入,例如 __extends, __decorate, __rest,__metadata
        "importHelpers": true,
        "baseUrl": ".",
        "rootDir": ".",
 
        // 输出模块格式,import/export
        "module": "es2015",
 
        // ES语法使用 ES5,即 class 会编译成 function, const 编译成 var
        "target": "es5"
    },
    "files": [
        "index.ts"
    ],
    "angularCompilerOptions": {
        // 报错后,立即输出错误信息,不产出 .metadata.json 文件
        // 只有 skipMetadataEmit 为 false,同时 skipTemplateCodegen 为 true 才生效
        "strictMetadataEmit": true,
 
        // 需要产生 .metadata.json 文件
        "skipMetadataEmit": false,
 
        // 不产生模板文件,也即 .ngfactory.js 和 ngstyle.js 文件,这些文件无法发布到 npm,因此需要忽略
        // 会关闭模板编译以及模板诊断功能
        // 那么怎么在 .js 和 .metadata.json 中嵌入模板信息呢(templateUrl?)和样式信息(styleUrl)?
        // 模板可以用 gulp 替换 templateUrl 为 template
        // 样式由于没有使用内联方式,因此可以忽略
        "skipTemplateCodegen": true
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment