Angular/ng : Différence entre versions

De WikiSys
Aller à : navigation, rechercher
(ng help)
(ng build)
(2 révisions intermédiaires par le même utilisateur non affichées)
Ligne 24 : Ligne 24 :
 
  ng g c employees/listEmployees --spec false --flat true
 
  ng g c employees/listEmployees --spec false --flat true
 
  ng --port=4500 -o              http://localhost:4500/
 
  ng --port=4500 -o              http://localhost:4500/
 +
 +
== angular-cli “ng build” doesn't produce a working project?==
 +
* https://stackoverflow.com/questions/37558656/angular-cli-ng-build-doesnt-produce-a-working-project
 +
 +
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="./">
 +
 +
(ça marche)
 +
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.
 +
 +
==Angular CLI: Serving and Building for Production ==
 +
*  https://scotch.io/courses/build-your-first-angular-website/angular-cli-serving-and-building-for-production
 +
 +
ng build --prod

Version du 9 octobre 2019 à 13:43

ng --version

ng help

Available Commands:

  • add Adds support for an external library to your project.
  • build (b) Compiles an Angular app into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.
  • config Retrieves or sets Angular configuration values in the angular.json file for the workspace.
  • doc (d) Opens the official Angular documentation (angular.io) in a browser, and searches for a given keyword.
  • e2e (e) Builds and serves an Angular app, then runs end-to-end tests using Protractor.
  • generate (g) Generates and/or modifies files based on a schematic.
  • help Lists available commands and their short descriptions.
  • lint (l) Runs linting tools on Angular app code in a given project folder.
  • new (n) Creates a new workspace and an initial Angular app.
  • run Runs an Architect target with an optional custom builder configuration defined in your project.
  • serve (s) Builds and serves your app, rebuilding on file changes.
  • test (t) Runs unit tests in a project.
  • update Updates your application and its dependencies. See https://update.angular.io/
  • version (v) Outputs Angular CLI version.
  • xi18n Extracts i18n messages from source code.

For more detailed help run "ng [command name] --help"

ng s -o
ng g c employees/listEmployees --spec false --flat true
ng --port=4500 -o              http://localhost:4500/

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

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="./">

(ça marche) 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.

Angular CLI: Serving and Building for Production

ng build --prod