Caius Caius - 2 months ago 33
Javascript Question

How to deploy ng2 app after ng-build

I've never understood what comes after the

ng build
command. I mean, how can you actually load your built app on a normal server and access it? Until now I've found only topics talking about the
ng serve
ng build
, saying that after the
ng build
you're done. But that's not true.

If I try to build and then navigate to the folder, I get a lot of errors in the console about files not found etc... not to mention errors about unmatched routes and so on.

The fact is that the app before the build using
ng serve
works like a charm, but I can't go to the client and say:
"Well, you have to use ng serve".

Jokes apart, how do I actually serve my built app without using GitHub pages and other hosts, but using my own server?

I swear that I've searched a lot on this topic, but I've never found a "stable" solution for it.

Thanks for any possible tip. I'm freaking out with this thing.


Cleaning the post up.

If you use Angular CLI: ng build Navigate to your app folder /dist

enter image description here

To run the app on a server: copy everything from dist folder + all your assets ( bootstrap.css or image folder or fonts folder)

enter image description here


If you are trying to run the app from local PC keep in mind that the app is looking for your assets in the root folder (C:/, D:/).

Open your Index.html file and edit the to point to the correct path, you don't need to do this on a server or hosting.