Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy angular app to production

I'm a little uncertain about some Angular 5 aspects. I've developed an app and don't know how to run it on production.

Currently I run my app using ng serve in NodeJS , but is it same in a production environment ?

thanks!

like image 459
Gfuentes Avatar asked Feb 22 '18 12:02

Gfuentes


People also ask

How to deploy an application using angular CLI?

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. The very first step would be to bundle up an application for production before its deployment. Navigate to project directory. This starts a local HTTP server with production files.

How to bundle an angular app for production?

How to bundle an Angular app for production? 1 Navigate to project directory. 2 Run ng build command in Angular CLI ng build --prod. 3 To get the preview of the application, run the following command: ng serve --prod.

How do I run an angular application in production mode?

Angular applications run in development mode by default, as you can see by the following message on the browser console: Angular is running in development mode. Call enableProdMode() to enable production mode.

How to deploy angular project to GitHub Pages?

To be able to deploy your Angular project to GitHub pages you must put your project's code in a GitHub repository Then, install the required deploy package. And finally, run the deploy command. Important Note: You must pass the --base-href parameter with the name of your repository.


3 Answers

ng serve

ng serve is for development purpose. Check docs.

When using ng serve the compiled output is served from memory, not from disk. This means that the application being served is not located on disk in the dist folder.

ng build

ng build --prod is for production purpose. Check docs.

ng build compiles the application into an output directory. The build artifacts will be stored in the dist/ directory, inside the root directory of your angular app.

Jus copy the dist folder to any server like IIS or Node Express and your angular app is up and running.

To deploy you app using IIS check this and using Node Express check this.

like image 58
Shaiju T Avatar answered Nov 07 '22 13:11

Shaiju T


Generally, I do not use Angular CLI's built in web server for production deployments.

With Angular CLI, you can create a production build using this command

ng build –prod 

That will create a dist folder, which you can upload to any web server of your choosing to deploy an application.

like image 45
JeffryHouser Avatar answered Nov 07 '22 13:11

JeffryHouser


First and foremost, you should build your app for production using

ng build --prod

You'll find a dist folder in your project folder. This is the Production-ready version of your app.

Now you'd require a server to deploy your app. Install this - https://www.npmjs.com/package/http-server and run using http-server dist/myProject (replace myProject with your project name)

like image 31
Vibhor Dube Avatar answered Nov 07 '22 15:11

Vibhor Dube