Building Angular App (ng build) 🎯

beginner
11 min

Building Angular App (ng build) 🎯

Welcome to our comprehensive guide on building Angular apps using the ng build command! By the end of this tutorial, you'll be able to create, build, and deploy your very own Angular applications. Let's dive in!

What is ng build? 📝

ng build is an Angular CLI command used to build an Angular application for production. It bundles the application along with all its dependencies and creates a single deployment unit.

Prerequisites 📝

Before we start, make sure you have Node.js and Angular CLI installed on your system. If you haven't installed them yet, follow the guides on our website:

  1. Node.js Installation
  2. Angular CLI Installation

Creating a New Angular App 🎯

Let's start by creating a new Angular app:

bash
ng new my-angular-app

Replace my-angular-app with the name you want for your project.

Navigating Your App Directory 📝

Navigate into your newly created app directory:

bash
cd my-angular-app

Building the App 🎯

Now, let's build the app for production:

bash
ng build --configuration production

The --configuration production option tells Angular CLI to build the app using the production configuration.

Understanding the Build Output 📝

After running the ng build command, you'll find a new folder called dist in your project directory. This folder contains the built version of your app. Inside the dist folder, you'll find the following directories:

  1. my-angular-app: This directory contains the optimized JavaScript, CSS, and HTML files.
  2. assets: This directory contains your application's static files like images, fonts, etc.

Deploying Your App 🎯

Now that you have your built app, you can deploy it to any web server. For the sake of this tutorial, we'll use GitHub Pages to host our app. If you don't have a GitHub account, sign up here.

Follow our guide on Deploying an Angular App on GitHub Pages to learn how to deploy your app.

Quick Quiz
Question 1 of 1

What does the `ng build` command do?

Quick Quiz
Question 1 of 1

Where can you find the built version of your Angular app?