| Angular-Project-Manifest | Angular-modular-configuration | |
Understanding Config.json files in Angular |
In many TypeScript projects, especially those generated by the Angular CLI, you will see multiple
tsconfig.*.json files. This hierarchy allows for specialized configurations while inheriting a common base
to prevent redundant and conflicting settings.
Here is a breakdown of the roles for tsconfig.json, tsconfig.app.json, and tsconfig.spec.json.
The root tsconfig.json file serves as the base configuration for the entire project. In a modern Angular
application, this file typically acts as a "solution-style" configuration for tools and IDEs, which may use it to
understand the overall structure of the project. A more specific file, like tsconfig.base.json, holds the
shared compiler options that other configurations will extend.
The tsconfig.app.json file is responsible for building the actual application code. It extends the main or base
configuration but provides specific settings tailored for compiling the application's source files.
ng build or ng serve.types array to include only the necessary type definitions for the browser environment.tsconfig.app.json to define its individual build settings, allowing them to vary from the global workspace configuration.
The tsconfig.spec.json file is specifically for compiling the project's test files. Like the application config, it extends the base tsconfig.json but is optimized for the testing environment.
ng test.types array is typically set to ["jasmine"] to ensure the correct global types are available for your test files.module setting might be different from the main application to better suit the Node.js test runner environment.In a typical Angular project, the inheritance structure looks like this:
tsconfig.app.json extends tsconfig.base.json tsconfig.spec.json extends tsconfig.base.json
The base file contains the common settings, and the other files provide overrides for their specific contexts. Here is a simplified example of how they interact:
extends.
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"strict": true,
"moduleResolution": "node",
"lib": ["ES2022", "dom"]
}
}
src/ (excluding tests)."exclude": ["**/*.spec.ts"] to skip test files.
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist/out-tsc",
"types": []
},
"files": [],
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.spec.ts"]
}
ng test.{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"types": ["jasmine"]
},
"include": [
"src/**/*.spec.ts"
]
}
| File Name | Purpose | Inherits From | Typical Use Case |
|---|---|---|---|
| tsconfig.json | Global base configuration for TypeScript compiler | — | Shared settings across all subprojects |
| tsconfig.app.json | Configuration specific to the Angular application code (src/) | tsconfig.json | App compilation, excluding tests and tooling |
| tsconfig.spec.json | Configuration for unit tests (usually using Jasmine/Karma) | tsconfig.json | Test compilation with additional type definitions |
| Angular-Project-Manifest | Angular-modular-configuration | |