(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?
Production is the new default When you create a new Angular project, the commands ng build and ng serve use the production build by default.
Compiles an Angular app into an output directory named dist/ at the given output path. Must be executed from within a workspace directory. Uses the webpack build tool, with default configuration options specified in the workspace configuration file (angular.
The ng build command is intentionally for building the apps and deploying the build artifacts. The command does not generate an output folder. The output folder is – dist/. The ng serve builds artifacts from memory instead for a faster development experience.
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="./">
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With