Sub topic 3
Tour of the workspace root files
This chapter assumes you have created a workspace with ng new and can use a terminal, npm, and basic TypeScript. It walks through the files that sit at the workspace root, outside src. Knowing what each file does tells you which one to open when something needs to change.
What the root holds
The root contains configuration for the tools that build, check, and run your application. Your own code lives in src. A typical new workspace has these entries:
| Entry | Purpose |
|---|---|
| `angular.json` | Workspace and project configuration for the CLI |
| `package.json` | Dependencies and npm scripts |
| `package-lock.json` | Exact installed dependency versions |
| `tsconfig.json` | Base TypeScript settings |
| `tsconfig.app.json` | TypeScript settings for the application build |
| `tsconfig.spec.json` | TypeScript settings for unit tests |
| `.editorconfig` | Editor formatting rules (indentation, charset) |
| `.gitignore` | Files Git should not track |
| `public/` or `src/assets/` | Static files copied into the build |
| `node_modules/` | Installed packages (generated) |
The static files folder depends on the CLI version. Newer versions use public/, and older ones use src/assets/.
package.json
package.json lists the packages your project needs and defines scripts. The dependencies section holds runtime packages such as @angular/core. The devDependencies section holds build-time tools such as @angular/cli and the TypeScript compiler.
{
"scripts": {
"start": "ng serve",
"build": "ng build",
"test": "ng test"
}
}These scripts are thin wrappers. npm start runs ng serve, so both do the same thing. The CLI uses the local copy in node_modules, so each project can pin its own Angular version.
package-lock.json
The lock file records the exact version of every package that npm installed, including indirect ones. Commit it. It makes npm ci on a teammate's machine or a build server install the same tree you tested. Do not edit it by hand.
angular.json
This file tells the CLI how to build, serve, and test each project. It is the most important file in the root, and a later chapter reads it line by line. For now, note that changing build behavior usually means editing this file and not your source code.
The tsconfig files
tsconfig.json holds shared compiler options, such as strict mode. The other two files extend it:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app"
},
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts"]
}tsconfig.app.json limits compilation to what ships in the application. tsconfig.spec.json adds the test framework's type definitions. Keeping them apart stops test-only types from leaking into production code.
Housekeeping files
.editorconfig keeps formatting consistent across editors. .gitignore already excludes node_modules, build output in dist, and the .angular cache folder. That cache holds incremental build data, so you can delete it safely if builds behave strangely.
How the files relate
Exercise
You want strict type checking in both the application build and the unit tests. Which file should you edit, and why does one edit cover both?
Show answer
Edit tsconfig.json. Both tsconfig.app.json and tsconfig.spec.json extend it, so options set there apply to both builds.