spring
spring

Reputation: 18487

angular-cli "ng build" doesn't produce a working project?

(I'm new on planet Angular2 (emigrated from dying planet
Flex/Actionscript, so please forgive this naive question)

Have I made a fatal error in thinking that after running the "ng build" command on my project from Angular CLi, I would end up with a functioning project in the directory "dist" – which I could just run in a browser, put up on a server?

I end up with a folder full of correctly named stuff, etc. Is there a step I am missing here?

enter image description here

Upvotes: 25

Views: 42702

Answers (3)

Marian Zburlea
Marian Zburlea

Reputation: 9407

You need to run this in the CLI:

# This will create a production version in "dist" folder
ng build --prod

# This will create a production version in a custom folder
ng build --prod --output-path=custom

Upvotes: 1

Zze
Zze

Reputation: 18805

I thought I would cross post my answer from a similar question. Original Post.
I don't think the OP is a duplicate, so here;


You can achieve the desired outcome with the following cmd angular-cli command:

ng build --base-href /myUrl/

ng build --bh /myUrl/ or ng build --prod --bh /myUrl/

This changes the <base href="/"> to <base href="/myUrl/"> in the built version only which was perfect for our change in environment between development and production. The best part was no code base requires changing using this method.


To summarise, leave your index.html base href as: <base href="/"> then run ng build --bh ./ in angular-cli to make it a relative path, or replace the ./ with whatever you require.

This is the official angular-cli documentation referring to usage.

Upvotes: 8

user6927497
user6927497

Reputation: 736

I'm new to angular, and just ran into the same issue. You can open up and run the Index.html file in the browser directly from the file system, but you have to edit the path of the base href attribute in Index.html from:

<base href="/">

to:

<base href="./">

Upvotes: 72

Related Questions