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"]
}
What's the point in splitting 'compilerOptions' this way? Is there a valid reason, or was it just careless programming?
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.