Monday, May 21, 2018

Deploying Angular: base href


There is a lot of "magic" with modern "SPA" web apps...

Angular web apps are by default expected to be deployed on root folder of a web site "/".
This works well for testing, or deploying as a single web site app,
but in enterprise environments there are often multiple web apps on one web site.

Angular CLI "build" command has option to adjust "base-href", but that is not enough.
At the same time need to adjust "deploy-url" that is applied for static resources (scripts).
So the complete command is, assuming the app is deployed with path "/myapp/"
Observe that "/" is before and after the path of the app.

> ng build -prod --base-href /myapp/ --deploy-url /myapp/

The same adjustment is also needed when "bundling" a SPA web app with "host" web server app.
That is needed when manually adding built "dist" Angular app to web server app.
In case of Angular template with ASP.NET Core, when adjustment is done by Visual Studio
and the .net, when published app generates HTML with adjustment on the fly. Magic.  


useful link:

No comments: