Angular/Installation : Différence entre versions

De WikiSys
Aller à : navigation, rechercher
(Workspace files)
(Step 2: Create a workspace and initial application)
Ligne 6 : Ligne 6 :
To create a new workspace and initial app project:  
To create a new workspace and initial app project:  
   ng new propositions
   ng new mon-projet-angular --style=scss --skip-tests=true.
===Step 3: Serve the application===
===Step 3: Serve the application===

Version du 14 juin 2019 à 17:12

Step 1: Install the Angular CLI

 npm install -g @angular/cli

Step 2: Create a workspace and initial application

To create a new workspace and initial app project:

 ng new mon-projet-angular --style=scss --skip-tests=true.

Step 3: Serve the application

 cd ~/Angular/propositions
 ng serve --open

Step 4: Edit your first Angular component

emacs src/app/app.component.ts
title = 'Propositions Network';
emacs src/app/app.component.css
h1 {
  color: #369;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 250%;

Workspace and project file structure

You develop apps in the context of an Angular workspace. A workspace contains the files for one or more projects. A project is the set of files that comprise a standalone app, a library, or a set of end-to-end (e2e) tests.

The Angular CLI command ng new <project_name> gets you started. When you run this command, the CLI installs the necessary Angular npm packages and other dependencies in a new workspace, with a root folder named project_name. It also creates the following workspace and starter project files:

  • An initial skeleton app project, also called project_name (in the src/ subfolder).
  • An end-to-end test project (in the e2e/ subfolder).
  • Related configuration files.

The initial app project contains a simple Welcome app, ready to run

Workspace files

The top level of the workspace contains a number of workspace-wide configuration files. WORKSPACE CONFIG FILES PURPOSE

Configuration for code editors. See EditorConfig.
Specifies intentionally untracked files that Git should ignore.
CLI configuration defaults for all projects in the workspace, including configuration options for build, serve, and test tools that the CLI uses, such as :TSLint, Karma, and Protractor. For details, see Angular Workspace Configuration.
Provides npm packages to the entire workspace.
Configures npm package dependencies that are available to all projects in the workspace. See npm documentation for the specific format and contents of this file.
Provides version information for all packages installed into node_modules by the npm client. See npm documentation for details. If you use the yarn client, this file will be yarn.lock instead.
Default TypeScript configuration for apps in the workspace, including TypeScript and Angular template compiler options. See TypeScript Configuration.
Default TSLint configuration for apps in the workspace. 
Introductory documentation.


      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/mon-projet-angular",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/",
            "assets": [
              "styles": [
            "scripts": [],
            "es5BrowserSupport": true


The node_modules directory is only for build tools.

The package.json file in the app root defines what libraries will be installed into node_modules when you run npm install

Very often with an angular app, on your dev machine or on a build server, you use other Javascript libraries from npm (a node.js package manager) to build your angular app. Tasks can be concatenating resources, using CSS preprocessors like LESS or SASS, minification, replacing of values, etc. etc. The most common tools for managing and running these tasks are called grunt and gulp, which are installed through npm as well.

When you deploy your app, you only distribute the resulting build, not any of the source files or build tools.

It is of course possible to write an AngularJS app without building anything.

edit from comments: When you dive into Angular more, there are more advanced techniques of using libraries installed by npm even in the client app, you then selectively choose the ones you need, not the whole 50MB+ thing. I'd recommend staying with the basic approaches until you get a good grasp on them though.