简体   繁体   中英

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

What is the purpose of tsconfig.lib.json in my NxWorkspace?
I have a single Angular app in my workspace.

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? 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. 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. 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.

To your point, yes you can define a root tsconfig in your nx workspace. In fact, it is called 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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