Run Angular2 as static app in browser without a server

this is a great way to export your application , just need a little change open index.html and change

<base href="/">

to

<base href="./">

Run the BUILD command to BUNDLE/build

ng build

or for a production build/bundle

ng build --prod

It will build/bundle your app into a distributable app.

When it is finished look in your apps root directory for a dist folder and that will contain everything your app needs to run in outside of the node server, say like a tomcat instance.

Update

Thanks to the comment from @Maris, make sure your file paths are relative to the current directory rather than relative to the root directory.

Simply run this command to change the base href element in your index.html.

ng build --prod --base-href ./


This works for me:

$ ng build --prod --base-href ./

It's impossible i think during to error in modern browsers:

Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History':...

it's a pity