简体   繁体   English

NxWorkspace,Angular:在tsconfig.lib.json中拆分compilerOptions的目的是什么

[英]NxWorkspace, Angular: What is the purpose of splitting compilerOptions in tsconfig.lib.json

What is the purpose of tsconfig.lib.json in my NxWorkspace? tsconfig.lib.json 在我的 NxWorkspace 中的用途是什么?
I have a single Angular app in my workspace.我的工作区中有一个 Angular 应用程序。

tsconfig.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "declaration": true,
    "types": []
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "jest.config.ts",
    "**/*.spec.ts",
    "**/*.test.ts"
  ]
}

tsconfig.lib.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["jest", "node"]
  },
  "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
  1. What's the point in splitting 'compilerOptions' this way?以这种方式拆分“compilerOptions”有什么意义? Is there a valid reason, or was it just careless programming?有正当的理由,还是只是粗心的编程?

  2. I assume I can move the compiler options from tsconfig.lib.json to tsconfig.json and everything should work fine.我假设我可以将编译器选项从 tsconfig.lib.json 移动到 tsconfig.json 并且一切正常。 Or am I missing something?还是我错过了什么?

I think it is by design and it is not a careless programming.我认为这是设计使然,而不是粗心的编程。 They want to make libs as independent as possible.他们想让libs尽可能独立。 Thus, they offer the advantage of defining your custom TypeScript configuration at that point, so that you can set the bounderies of your library very well and libs have more potential configuration available.因此,它们提供了在此时定义自定义TypeScript配置的优势,因此您可以很好地设置库的边界,并且库有更多潜在的配置可用。

To your point, yes you can define a root tsconfig in your nx workspace.就您而言,是的,您可以在nx工作区中定义根tsconfig In fact, it is called tsconfig.base.json .实际上,它被称为tsconfig.base.json According to the official documentation:根据官方文档:

/tsconfig.base.json sets up the global TypeScript settings and creates aliases for each library to aid when creating TS/JS imports. /tsconfig.base.json 设置全局 TypeScript 设置并为每个库创建别名以帮助创建 TS/JS 导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM