liveBook · Manning

Code reloading

As explained in Pro Angular 16

Hot reload is a development technique that updates a running application after source changes without requiring a full restart.

Code reloading makes edits visible during Angular development without manually restarting the server or refreshing the browser. Run `ng serve`, change a project file, and save it. The tools detect the change, rebuild the affected bundles, and reload the application in the browser. Here, “hot reloading” means an automatic browser reload, not an update that preserves the running page. section 9.3.2 section 9.7

Check a TypeScript change

Replace `src/main.ts` with `console.log("Hello");` and save it. Open the browser’s F12 developer tools and select Console to see `Hello` alongside messages from the automatic reloading process. Add `console.log("Hello, World");` and save again: the project recompiles, the browser reloads, and both messages appear. section 3.4.1

The first `ng serve` run performs a full build. Afterward, changing a file rebuilds only bundles affected by that file, making feedback quicker. For example, replacing `src/app/app.component.html` with a `Hello, World` div produces a successful build report with three unchanged chunks before the browser displays the edit. The development bundle contains code that connects to the Angular development HTTP server; when a change triggers a build, the server signals the browser to reload. section 9.3.2

Initial Chunk Files | Names   | Raw Size
runtime.js          | runtime |  6.51 kB |
main.js             | main    |  4.39 kB |
 
3 unchanged chunks
Build at: 2023-05-04T07:11:32.801Z - Hash: c9566a8321a0595b - Time: 642ms
Compiled successfully.

A build report after the template edit shows the rebuilt chunks and three unchanged chunks; the edit does not require rebuilding every bundle. section 9.3.2

How Pro Angular 16 covers it

How deep it goes
Explains change detection, selective bundle rebuilding, and the server signal that reloads the browser; does not describe preserving page state.
Examples
Uses `main.ts` console messages and an `app.component.html` template edit, with browser output and a build report.
What it assumes
Assumes an Angular project and file editing; demonstrates how to inspect output through the browser’s F12 Console.
What you can do after
Operate/configure it by running `ng serve`, saving an edit, and checking the browser or build output for the result.
How it connects
Connects to `ng serve`, TypeScript compilation, application bundles, the development HTTP server, and browser developer tools.

Also explained in

Compare how 4 books explain code reloading →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.