Before deploying the web app, Angular provides a way to check the behavior of the web application with the help of a few CLI-commands. Usually, ng serves command is used to build, watch, and serve the application from local memory. But for deployment, the behavior of the application is seen by running ng build command.
Difference between ng serve and ng build
|ng serve||ng build|
|The ng serve command is intentionally for fast, local and iterative developments and also for builds, watches and serves the application from a local CLI development server.||The ng build command is intentionally for building the apps and deploying the build artifacts.|
|The command does not generate an output folder.||The output folder is – dist/.|
|The ng serve builds artifacts from memory instead for a faster development experience.||The ng build command generates output files just once and doesn’t serve them.|
Before following the steps to deploy the application, make sure that Angular CLI is already installed in the system if it is not then run the following command.
npm install -g @angular/cli
The very first step would be to bundle up an application for production before its deployment.
Navigate to project directory.
Run ng build command in Angular CLI
ng build --prod
To get the preview of the application, run the following command:
ng serve --prod
This starts a local HTTP server with production files. Navigate to http://localhost:4200/ to view the application.
With these steps, the application is ready for deployment.
ng build command compiles the Angular app into an output directory named dist/ at the given output path. This command must be executed from within the working directory. The application builder in Angular uses the webpack build tool, with configuration options specified in the workspace configuration file (angular.json) or with a named alternative configuration. A “production” configuration is created by default when you use the CLI to create the project, and you can use that configuration by specifying the —
configuration="production" or the
The –prod flag activates many optimization flags. One of them is –aot for Ahead Of Time compilation. Your component templates are compiled during the build, so TypeScript can detect more issues in your code. You can compile in dev mode but still activate the –aot flag if you want to see this error before building for prod.
The dist folder is the build folder which contains all the files and folders which can be hosted in the server.
Inside dist/ folder
|assets||The folder contains resources copied from the Angular CLI assets configuration.|
|index.html||index.html file is the entrypoint for the application.|
|main.[hash].js||The file contain bundled application.|
|polyfill.[hash].bundle.js||It contains polyfill dependencies|
|runtime-[es-version].[hash].bundle.js||It contains webpack loader|
|style.[hash].bundle.css||It contains the style definitions|
- Performance: Dynamic applications didn’t always perform that well. Complex SPAs could be laggy and inconvenient to use due to their size.
- Steep learning curve: As AngularJS is a versatile instrument, there’s always more than one method to finish any task. This has produced some confusion among engineers.
- Adding Angular Material Component to Angular Application
- Angular 7 | Angular Data Services using Observable
- Angular CLI | Angular Project Setup
- Routing in Angular JS using Angular UI Router
- How to use mat-icon in angular?
- Angular 7 | Directives
- Angular 8 | Introduction
- How to use jQuery in Angular ?
- Angular 7 | Installation
- Angular 7 | Architecture
- Angular 7 | Components
- Angular 7 | Introduction
- Angular 7 | Observables
- How to use bootstrap 4 in angular 2?
- Angular 4 | Introduction
- What is the use of Angular 2 hashtags in template ?
- What is entryComponents in angular ngModule ?
- Difference Between Angular and Knockout
- What is the meaning of let-* in Angular 2 Templates ?
- Angular | keyup event
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.