SlideShare a Scribd company logo
Everything You Should Know About the New Angular CLI
Everything You Should Know About the New Angular CLI
Everything You Should Know About the New Angular CLI
Challenges
Support
Starter kit
Sharing code
Angular 42
4
@ahasall
Frontend Software Engineer
Amadou Sall
GDG Toulouse / February 2019
Everything You Should Know
About the New Angular CLI
www.amadousall.com
!
Workspaces
Libraries
Architects
Schematics
...
Overview
Workspaces
What is a Workspace?
Angular apps are developed in the context of a
workspace.
Mono-repo or multi-repo.
8
Types of Projects in Workspace
application
library
9
Workspace Files
.
├── .editorconfig
├── .gitignore
├── README.md
├── angular.json
├── package.json
├── tsconfig.json
└── tslint.json
10
Workspace Configuration/angular.json
{
"version": 1,
"newProjectRoot": "projects",
"projects": {
"first-app": {...},
"first-app-e2e": {...},
"second-app": {...},
"second-app-e2e": {...}
},
"defaultProject": "first-app"
}
11
Project Configuration
{
"projects": {
"first-app": {
"root": "projects/first-app/",
"sourceRoot": "projects/first-app/src",
"projectType": "application",
"prefix": "app",
"schematics": {...},
"architect": {...}
}
}
}
12
Everything You Should Know About the New Angular CLI
Tips and Tricks
By default, the workspace is “multi-repo”
ng new <workspace_name>
14
Tips and Tricks
If you want to use the “mono-repo” approach
ng new <workspace_name> -–create-application=false
15
Libraries
Library Support
17
Generating a Library
ng generate library <library_name>
Scaffolds a library
Updates our tsconfig.json file to add paths mapping
18
Building a Library
ng build <library_name>
Outputs the build artifacts to dist/<library_name>
19
Using Your Library
import { MakeItAwesomeModule } from 'make-it-awesome';
First it looks in the tsconfig paths
Then it looks in the node_modules folder
20
Publishing Your Library
ng build <library_name>
cd dist/<library_name>
npm adduser
npm publish –-access=public
Let’s share the library with the world
21
Everything You Should Know About the New Angular CLI
Tips and Tricks
Use the watch flag to always rebuild your library
ng b <library_name> --watch
23
TheDifferentTypesofAngularCLI
Commands
Native, Architect, Schematics
Native Commands
ng version
ng config
ng doc
ng help
25
Architect Commands
ng serve
ng build
ng lint
ng test
ng e2e
ng xi18n
ng run
26
Schematics Commands
ng new
ng generate
ng add
ng update
27
Architects
Architect Commands
ng serve
ng build
ng lint
ng test
ng e2e
ng xi18n
ng run
29
The ng run Command to Rule Them All
ng run <project>:<target>[:configuration]
Runs an Architect target
30
The ng run command
Predefined Commands
ng build <project>
ng test <project>
ng lint <project>
...
Using ng run
ng run <project>:build
ng run <project>:test
ng run <project>:lint
...
31
Project Configuration
"make-it-awesome": {
"root": "projects/make-it-awesome",
"sourceRoot": "projects/make-it-awesome/src",
"projectType": "library",
"prefix": "lib",
"architect": {
"build": {...},
"test": {...},
"lint": {...}
}
}
32
Target configuration
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/make-it-awesome/src/test.ts",
"tsConfig": "projects/make-it-awesome/tsconfig.spec.json",
"karmaConfig": "projects/make-it-awesome/karma.conf.js"
},
"configurations": {
"ci": {
"browsers": "ChromeHeadlessCI",
"codeCoverage": true
}
}
}
33
Everything You Should Know About the New Angular CLI
Tips and Tricks
Define your configuration inside the angular.json file
35
Schematics
What Can Schematics do?
scaffold a new Angular application
ng new
generate code via predefined blueprints
ng generate
37
What Can Schematics do?
add framework support
ng add
update your dependencies/migrate existing code
ng update
38
What are Schematics?
A generic tool that helps with:
• Code generation
• Code transformations
The goal is to make developers more productive
39
CreatingYourOwnSchematics
Why Create Our Custom Schematics
Our starter kit can be replaced by a single command
Building solid foundations
Enforcing best practices across the company
Startup mode
Automate all things!
41
Getting Started
> yarn global add @angular-devkit/schematics-cli
> schematics blank –name=simple
> schematics schematic –name=advanced
42
Getting Started
> schematics blank --name=first
CREATE /first/README.md (639 bytes)
CREATE /first/.gitignore (191 bytes)
CREATE /first/.npmignore (64 bytes)
CREATE /first/package.json (533 bytes)
CREATE /first/tsconfig.json (656 bytes)
CREATE /first/src/collection.json (214 bytes)
CREATE /first/src/first/index.ts (313 bytes)
CREATE /first/src/first/index_spec.ts (462 bytes)
43
Getting Started
.
├── README.md
├── package-lock.json
├── package.json
├── src
│ ├── collection.json
│ └── first
│ ├── index.ts
│ └── index_spec.ts
└── tsconfig.json
44
package.json
{
"name": "@ahasall/schematics",
"version": "0.0.0",
"schematics": "./collection.json",
"dependencies": {
"@angular-devkit/core": "^7.3.1",
"@angular-devkit/schematics": "^7.3.1",
"typescript": "~3.2.2",
"@types/node": "^8.0.31",
"rxjs": "6.3.3"
}
}
45
collection.json
{
"$schema": "/path/to/schema.json",
"schematics": {
"first": {
"description": "A first schematic",
"factory": "./first"
},
"second": {
"description": "A second schematic.",
"factory": "./second",
"schema": "./second/schema.json"
}
}
}
46
Rule Factory
Takes in options from
the CLI
Creates a RuleThe entry point of a
schematic
47
Rule Factory
export function tap(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
return tree;
};
}
48
Rule
export function tap(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
return tree;
};
}
49
Rule
Takes in a Tree and
outputs a modified
Tree
Applies actions to a
Tree
50
Tree
A staging area for
changes
Contains:
• a file system,
• and a list of changes
to apply to it
51
Working on a Tree
function do(tree: Tree, context: SchematicContext) {
tree.create('hello.txt', 'Bonjour GDG Toulouse’);
tree.read('file.txt');
tree.rename('hello.txt’, 'salut.txt');
tree.delete('salut.txt');
return tree;
}
52
Running a Schematic
> ng generate @ahasall/schematics:first <name>
> schematics @ahasall/schematics:first <name>
53
Chain Rules
function (tree: Tree, context: SchematicContext) {
return chain([
schematic('workspace', workspaceOptions),
schematic('application', applicationOptions),
...
])
}
54
Templating Engine
{
"name": "<%= utils.dasherize(name) %>",
...
"dependencies": {
"@angular/core": "<%= latestVersions.Angular %>",
"@angular/forms": "<%= latestVersions.Angular %>",
...
}
}
55
SchematicsUseCases
Theming your Angular Material applications
ng generate application –theme=klm
57
The Container-Component pattern
ng generate container-component flight
58
Setting up the Continuous Integration
ng add @airfrance/angular-toolkit
59
Nobody wants to read the docs
ng new –collection=@airfrance/schematics my-app
60
OtherNewFeatures
Budgets
Let’s make some savings
62
Differential Serving
Don’t make your users pay for Internet Explorer
63
Workspaces
Libraries
Architects
Schematics
...
Summary
@ahasall
Frontend Software Engineer
Amadou Sall
GDG Toulouse / February 2019
Thank You!
www.amadousall.com
!

More Related Content

What's hot (20)

PDF
Apple Templates Considered Harmful
Brian Gesiak
 
PDF
openCV with python
Wei-Wen Hsu
 
PDF
Reactive, component 그리고 angular2
Jeado Ko
 
KEY
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Guillaume Laforge
 
PDF
Riga Dev Day 2016 - Having fun with Javassist
Anton Arhipov
 
PPT
Real world cross-platform testing
Peter Edwards
 
PDF
FalsyValues. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
PPTX
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Farshid Pirahansiah
 
PDF
Workshop 10: ECMAScript 6
Visual Engineering
 
PDF
TensorFlow XLA RPC
Mr. Vengineer
 
PDF
iOS Behavior-Driven Development
Brian Gesiak
 
PDF
TVM VTA (TSIM)
Mr. Vengineer
 
PPTX
Getting started with open cv in raspberry pi
Jayaprakash Nagaruru
 
PDF
GeeCON 2017 - TestContainers. Integration testing without the hassle
Anton Arhipov
 
PPTX
Annotation processing tool
Andrzej Ludwikowski
 
PDF
Aplicações assíncronas no Android com
Coroutines & Jetpack
Nelson Glauber Leal
 
PDF
Voxxed Days Vilnius 2015 - Having fun with Javassist
Anton Arhipov
 
KEY
連邦の白いヤツ 「Objective-C」
matuura_core
 
PPTX
Angular 1 + es6
장현 한
 
PPTX
Developing web-apps like it's 2013
Laurent_VB
 
Apple Templates Considered Harmful
Brian Gesiak
 
openCV with python
Wei-Wen Hsu
 
Reactive, component 그리고 angular2
Jeado Ko
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Guillaume Laforge
 
Riga Dev Day 2016 - Having fun with Javassist
Anton Arhipov
 
Real world cross-platform testing
Peter Edwards
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Farshid Pirahansiah
 
Workshop 10: ECMAScript 6
Visual Engineering
 
TensorFlow XLA RPC
Mr. Vengineer
 
iOS Behavior-Driven Development
Brian Gesiak
 
TVM VTA (TSIM)
Mr. Vengineer
 
Getting started with open cv in raspberry pi
Jayaprakash Nagaruru
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
Anton Arhipov
 
Annotation processing tool
Andrzej Ludwikowski
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Nelson Glauber Leal
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Anton Arhipov
 
連邦の白いヤツ 「Objective-C」
matuura_core
 
Angular 1 + es6
장현 한
 
Developing web-apps like it's 2013
Laurent_VB
 

Similar to Everything You Should Know About the New Angular CLI (20)

PDF
Angular Schematics
Christoffer Noring
 
PDF
A Gentle Introduction to Angular Schematics - Angular SF 2019
Matt Raible
 
PPTX
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JSFestUA
 
PDF
Use Angular Schematics to Simplify Your Life - Develop Denver 2019
Matt Raible
 
PDF
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
Matt Raible
 
PPTX
Angular2
Oswald Campesato
 
PDF
Angular based enterprise level frontend architecture
Himanshu Tamrakar
 
PPTX
Talentica - JS Meetup - Angular Schematics
Krishnan Mudaliar
 
PDF
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
PPTX
Angular4 getting started
TejinderMakkar
 
PPTX
An Overview of Angular 4
Cynoteck Technology Solutions Private Limited
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PDF
Angular Notes.pdf
sagarpal60
 
PPTX
Angular CLI : HelloWorld
nikspatel007
 
PDF
Angular JS2 Training Session #1
Paras Mendiratta
 
PPTX
Advanced angular
Sumit Kumar Rakshit
 
PDF
The Angular road from 1.x to 2.0
Vassilis Pitsounis
 
PDF
How to Implement Micro Frontend Architecture using Angular Framework
RapidValue
 
PPTX
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
PDF
Getting Started with the Angular 2 CLI
Jim Lynch
 
Angular Schematics
Christoffer Noring
 
A Gentle Introduction to Angular Schematics - Angular SF 2019
Matt Raible
 
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JSFestUA
 
Use Angular Schematics to Simplify Your Life - Develop Denver 2019
Matt Raible
 
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
Matt Raible
 
Angular based enterprise level frontend architecture
Himanshu Tamrakar
 
Talentica - JS Meetup - Angular Schematics
Krishnan Mudaliar
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
Angular4 getting started
TejinderMakkar
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Angular Notes.pdf
sagarpal60
 
Angular CLI : HelloWorld
nikspatel007
 
Angular JS2 Training Session #1
Paras Mendiratta
 
Advanced angular
Sumit Kumar Rakshit
 
The Angular road from 1.x to 2.0
Vassilis Pitsounis
 
How to Implement Micro Frontend Architecture using Angular Framework
RapidValue
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Getting Started with the Angular 2 CLI
Jim Lynch
 
Ad

Recently uploaded (20)

PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PPTX
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
PDF
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PDF
65811_Introducing the Fusion AI Agent Studio (1).pdf
g6129590
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Rewards and Recognition (2).pdf
ethan Talor
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Dealing with JSON in the relational world
Andres Almiray
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
65811_Introducing the Fusion AI Agent Studio (1).pdf
g6129590
 
Ad

Everything You Should Know About the New Angular CLI