Building and Serving an Angular App
Present the Angular CLI commands for building an app for production and serving it locally during development.
// Install Angular CLI globally
npm install -g @angular/cli
This command installs the Angular CLI globally on your machine, which is required to create, build, and serve Angular applications.
// Create a new Angular application
ng new my-angular-app
This command scaffolds a new Angular application with the name 'my-angular-app', setting up the initial project structure and dependencies.
// Navigate into your application directory
cd my-angular-app
After creating the new Angular app, navigate into the generated project directory to run further commands inside the context of your new app.
// Serve the app on a local development server
ng serve
This command compiles the application and starts a web server. It also watches for file changes and rebuilds the app, refreshing the browser automatically.
// Build the app for production
ng build --prod
This command performs an Angular production build, optimizing the app for a smaller footprint and better performance by applying minification, uglification, and Ahead-of-Time (AOT) compilation.
// Ready to deploy
// The compiled output can be found in the 'dist/' directory
After a production build, your app is ready to be deployed. The compiled output files will be located in the 'dist/' directory within your project folder.