liveBook · Manning

Angular compiler

As explained in Pro Angular 16

The Angular compiler transforms Angular application source and templates into executable browser-oriented output.

Browsers cannot use Angular templates containing expressions directly. The Angular compiler transforms those templates into JavaScript statements that use browser APIs to create HTML elements and evaluate expressions. The TypeScript compiler has a separate job: compiling TypeScript files into JavaScript. section 9.3.2

Running `ng serve` starts a development build. Webpack follows imports from `main.ts`, processes the application’s dependencies, and bundles the compiled output for the browser. The Angular development tools manage this process; the compiler is not normally run separately in this workflow. section 9.3.2 section 3.1

Rebuild after a template change

Replace `src/app/app.component.html` with `<div>Hello, World</div>` while the development tools are running. The build reports an updated `main.js` bundle and a successful compilation. This connects a template edit to the browser-ready build without treating the template as browser-executable source. section 9.3.2

Table 9.7. The bundles produced by the Angular build process
Name
Description
main.js
This file contains the compiled output produced from the src/app folder.
polyfills.js
This file contains JavaScript polyfills required for features used by the application not supported by the target browsers.
runtime.js
This file contains the code that loads the other modules.
styles.js
This file contains JavaScript code that adds the application’s global CSS stylesheets.
vendor.js
This file contains the third-party packages the application depends on, including the Angular packages.

Compare `main.js`, which contains compiled application output, with the other bundles. The Angular compiler transforms templates; bundling packages that output alongside other resources. section 9.3.2

How Pro Angular 16 covers it

How deep it goes
Explains the compiler’s role in the build pipeline, but defers the production build process and does not detail compiler internals.
Examples
Uses an `app.component.html` edit and the resulting successful rebuild and `main.js` output.
What it assumes
Introduces the roles of templates, TypeScript compilation, and bundling without assuming knowledge of compiler internals.
What you can do after
Evaluate/understand how a template edit becomes browser-ready JavaScript in an Angular development build.
How it connects
Relates Angular templates and browser APIs to the TypeScript compiler, webpack, imports, and bundles.

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.