Reputation: 18487
(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?
Upvotes: 25
Views: 42702
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
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.
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
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