0

Im using the latest version of angular-cli. If I understood rightly, I can use ng build to obtain a compiled project in a js representation. In a /dist folder, according to documentation by default.

Im new with JS, so I simply cant understand how can I launch the project...

Command works fine, and I can find a bunch of files in a folder, but how can I launch a project as expected (like it was in a dev mode with ts-files)? I mean simply launching index.html just shows me a "Loading.." text, but application doesnt launch how it was expected.

Help please. Thanks!

Michael
  • 1
  • 1
  • 3

4 Answers4

2

Even if you get the app to run from a file, with messing base href etc, some things might not work (maybe AJAX, etc).

The dist folder is meant to be used with a server.

If you want to just browse the app, regardless of the files, you can run ng serve, which will serve the app in-memory (for speed) at http://localhost:4200, and will sit and watch for changes, and update the page when you make them.

When you are done developing, you run ng build, and take the contents of the dist folder to your server.

Meligy
  • 34,211
  • 11
  • 83
  • 106
1

You would need a webserver. Just copy the contents of the /dist folder to a webserver root and you're ready to go.

What is your goal? Ng build is meant to create a distributable version of your app, ng serve is meant for local development.

MikeOne
  • 4,525
  • 2
  • 25
  • 22
  • 2
    Just found an answer: http://stackoverflow.com/questions/37558656/angular-clis-ng-build-doesnt-produce-a-working-project. I needed to add a dot here in index.html . Thanks for attention, Mike! – Michael Jan 31 '17 at 17:43
  • Mike, sorry its out of topic, but maybe u can help.. So Im going to using DigitalOcean (with dedicated Ubuntu) to launch this app remotely. What am I going to do is to open this essential index.html through node.js which I had already installed. It should works, but maybe there is a more common and better solution? – Michael Jan 31 '17 at 17:53
  • Maybe it is better to start a new question with some more specifics about what you're teying to achieve? – MikeOne Jan 31 '17 at 18:48
  • @Michael thanks for the comment. your `dot` saved my day. :) – Raj Nov 09 '18 at 10:17
1

Execute this command

ng build -prod

Also set in the environments/environment.ts file, the property "production":true

export const environment = {
  production: true
};

That will create a dist folder, ready to deploy

RaR
  • 2,748
  • 3
  • 23
  • 45
Klerith
  • 11
  • 4
0

There is new angular-cli tool, install that

Perform these one by one...

npm uninstall -g angular-cli
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli

I completely removed the node_modules directory (rm -rf node_modules dist), Generate a new project and compare files like your package.json, angular-cli.json by ng new temp Compare & Changed the package.json to match the "dependencies" and "devDependencies". Fixed the angular-cli.json file for changes in the environment configs.

run ng serve after the npm install

Arfan Mirza
  • 638
  • 1
  • 15
  • 23