English
Checkpoint
What must work
Run in Source/Chatex.Web:
powershell
npm run buildpowershell
npm test -- --watch=falsepowershell
npm run lintpowershell
npm run format:checkFrom the repository root, the commands that topic 2 promised for this topic now work:
powershell
./Run.ps1 buildpowershell
./Run.ps1 testpowershell
./Run.ps1 webThe configuration files are final. Compare them with the reference, for example:
powershell
git diff --no-index Source/Chatex.Web/angular.json D:\Work\Chatex-Reference\Source\Chatex.Web\angular.jsonpowershell
git diff --no-index --stat Source/Chatex.Web/public D:\Work\Chatex-Reference\Source\Chatex.Web\publicNo output means identical. The same holds for package.json, package-lock.json, eslint.config.js, .prettierrc, .postcssrc.json, proxy.conf.json, the three tsconfig files, .vscode, src/index.html, src/main.ts, src/styles.css, icons.ts and the theme service with its test. app.ts, app.config.ts and app.routes.ts still differ; topics 16 and 17 complete them.
Commit:
powershell
git add .powershell
git commit -m "Create the Angular client with Tailwind CSS, linting, tests and the dev proxy"Common mistakes
Table 15.7. Common mistakes when setting up the client
| Symptom | Cause | Fix |
|---|---|---|
ng: The term 'ng' is not recognized as a name of a cmdlet, function, script file, or executable program. | the Angular CLI is not installed globally (and need not be) | run it through npm: npx ng …, or use the npm scripts |
[warn] src/main.ts … Code style issues found in the above file. Run Prettier with --write to fix. | a generated file with CRLF endings, or code typed without formatting | npm run format (or ./Run.ps1 format) |
Cannot apply unknown utility class `min-h-10` when building | @import 'tailwindcss' is missing at the top of styles.css, or a class inside @apply is misspelled | restore the import; check the class name |
The selector should start with one of these prefixes: "app" from npm run lint | a component selector without the app- prefix | rename the selector, for example app-root |
curl.exe -i http://localhost:4200/api/me answers 200 OK with HTML | the proxy is not active: proxyConfig is missing in angular.json, or the dev server was started before the file existed | add the option and restart npm start |
| the page flashes white before turning dark | theme-init.js is missing in public/ or not referenced in <head> | add the file and the <script src="theme-init.js"> tag |
| a theme change does not reach the page in a test | the test reads the DOM before the effect has run | call TestBed.tick() after changing the signal |
Self-check questions
- What do
package.jsonandpackage-lock.jsoneach record? Why does CI usenpm cirather thannpm install? - What does
ng adddo in addition tonpm install? - Which of the options of
ng newwould you change for an application that needs server-side rendering? - Why does Chatex switch off the inlining of critical CSS in production builds?
- What is the difference between
@themeand@theme inlineinstyles.css, and why do the semantic colours need the second one? - How does the theme reach the page before Angular has started? Why is the script a separate file?
- What is zone.js, and what tells a zoneless Angular application to update the screen?
- What do
signal,computedandeffecteach do? Why should an effect not set other signals? - What does
providedIn: 'root'mean for the lifetime ofThemeService? Which .NET registration corresponds to it? - Why does the development server forward
/apiand/hubsinstead of letting the browser callhttp://localhost:5214directly?
Exercises
- A sepia theme. Add a third set of values for the
--c-*variables under a classsepia, and a fourth value'sepia'toThemePreference. Which places inThemeService, its test andtheme-init.jsmust change? (Do it on a branch.) - A stricter lint rule. Add the rule
'@typescript-eslint/explicit-member-accessibility': 'error'to the TypeScript section ofeslint.config.jsand runnpm run lint. Which members would you have to change? Why does the reference not use the rule? - Bundle budget. Lower the
initialwarning budget inangular.jsonto 150 kB and build. Read the warning, then restore the value. Which package makes up most of the bundle? (Hint:npx ng build --stats-jsonwritesdist/chatex/stats.jsonfor a bundle analyser.)