liveBook · Manning

Ng serve

As explained in Pro Angular 16

ng serve is an Angular CLI command that builds an Angular application and serves it through a development server.

`ng serve` starts the Angular development tools in a project folder. It builds the application for the browser and starts a local web server, so you can test changes without manually rebuilding. Run it from the folder containing the Angular project. section 2.2.2 section 5.1.5

Run the application

From the project folder, run `ng serve`, wait for `Compiled successfully`, then open `http://localhost:4200`. The server uses port 4200 and serves `index.html` by default. Run `ng serve --open` if you want a browser window to open when the server starts. Save a change to a file in `src`; the tools automatically compile and package the changed application. section 2.2.2 section 5.1.5

The development build uses the TypeScript compiler to turn TypeScript into JavaScript and the Angular compiler to turn templates into JavaScript that creates elements and evaluates expressions. Webpack starts at `main.ts`, follows imports to find dependencies, and bundles the compiled output for the browser. These tools are managed by the Angular development tools; you do not need to run them separately. This is the development build, not the build used to prepare an application for deployment. 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.

The bundle table identifies the browser resources reported by a development build, including application code, third-party packages, runtime code, polyfills and styles. section 9.3.2

How Pro Angular 16 covers it

How deep it goes
Explains startup, browser access, change detection, compiler roles and webpack bundling; defers the production build.
Examples
Uses `ng serve`, `ng serve --open`, `localhost:4200`, build output and a template edit to illustrate development builds.
What it assumes
Assumes an Angular project created with `ng new` and access to its folder; explains the underlying development-build tools.
What you can do after
Operate it via Angular CLI to build and serve a project locally, then check that saved changes compile.
How it connects
Connects Angular CLI, TypeScript compilation, Angular template compilation, webpack bundling and the development web server.

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.