SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
HELLO WORLD
IN ANGULAR
Angular 2 Apps for Production
ABOUT ME
Iris Grace Endozo

Software Engineer, Mobile Web

Freelancer.com

irise@freelancer.com

@IrisEndozo
A simple, unoptimized “Hello World” app
bundle in Angular 2 is ~1.9MB!
What’s the plan?
Bundling and Minification

Tree-shaking

AoT compilation
Hello World!
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<hello-world-app></hello-world—app>
<script src=“/node_modules/zone.js/dist/zone.js">
</script>
<script src="dist/bundle.js"></script>
</body>
</html>
// main.ts
import { platformBrowserDynamic } from
‘@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from
'@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule],
bootstrap: [AppComponent],
declarations: [AppComponent],
})
export class AppModule {}
// app.component.ts
import { Component } from '@angular/core';
@Component({
selector: ‘hello-world-app',
template: 'Hello world!'
})
export class AppComponent {}
What’s the plan?
Bundling and Minification
Browserify and UglifyJS

Tree-shaking

AoT compilation
# Compile TS files using Typescript compiler to JS and
# Build a bundle using Browserify
$ tsc && browserify -s main dist/main.js > dist/bundle.js
# Minify using Uglify
$ uglifyjs dist/bundle.js --compress —mangle --output
dist/bundle.min.js
$ ls -lah dist/bundle.js
-rw-r--r-- 1 Nesiri staff 1.9M Feb 19 02:47 dist/bundle.js
# Compile TS files using Typescript compiler to JS and
# Build a bundle using Browserify
$ tsc && browserify -s main dist/main.js > dist/bundle.js
# Minify using Uglify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
$ ls -lah dist/bundle.min.js
-rw-r--r-- 1 Nesiri staff 582K Feb 19 03:01 dist/bundle.min.js
What’s the plan?
Bundling and Minification

Tree-shaking
Rollup.js

AoT compilation
Tree-shaking with Rollup.js
➤ supports ES2015 modules

➤ excludes unused exports from bundles
import {Form} from './forms';
import {Users} from './users';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(‘What is the type of user you want to get?’,
answer => {
const type = Users[answer];
type([1, 2, 3]);
});
# Transpile TS files to ES2015
$ tsc -t ES2015
# Rollup to bundle the ES2015 modules, use config file at
# rollup.config.js and output at bundle.es2015.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Transpile TS files to ES2015
$ tsc -t ES2015
# Rollup to bundle the ES2015 modules, use config file at
# rollup.config.js and output at bundle.es2015.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Transpile TS files to ES2015
$ tsc -t ES2015
# Rollup to bundle the ES2015 modules, use config file at
# rollup.config.js and output at bundle.es2015.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js --out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Transpile TS files to ES2015
$ tsc -t ES2015
# Rollup to bundle the ES2015 modules, use config file at
# rollup.config.js and output at bundle.es2015.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js --out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
$ ls -lah dist/bundle.min.js
-rw-r--r-- 1 Nesiri staff 532K Feb 19 04:14 dist/bundle.min.js
What’s the plan?
Bundling and Minification

Tree-shaking

AoT compilation
ngc
Ahead of Time Compilation
➤ Why?

➤ Faster rendering - no need to wait for the app to be compiled
before executing code

➤ Smaller NG framework download - no need for the NG
compiler as the stuff is already compiled, drastically reducing
the size of NG needed

➤ Template error detection - template binding errors are
determined during build steps
# Compile application (including HTML templates) to TS
$ ngc -p tsconfig.json && cp app/* compiled
# Transpile TS files to ES2015
$ tsc -p tsconfig-tsc.json --rootDir compiled
# Treeshaking with Rollup.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Compile application (including HTML templates) to TS
$ ngc -p tsconfig.json && cp app/* compiled
# Transpile TS files to ES2015
$ tsc -p tsconfig-tsc.json --rootDir compiled
# Treeshaking with Rollup.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Compile application (including HTML templates) to TS
$ ngc -p tsconfig.json && cp app/* compiled
# Transpile TS files to ES2015
$ tsc -p tsconfig-tsc.json --rootDir compiled
# Treeshaking with Rollup.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Compile application (including HTML templates) to TS
$ ngc -p tsconfig.json && cp app/* compiled
# Transpile TS files to ES2015
$ tsc -p tsconfig-tsc.json --rootDir compiled
# Treeshaking with Rollup.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
# Compile application (including HTML templates) to TS
$ ngc -p tsconfig.json && cp app/* compiled
# Transpile TS files to ES2015
$ tsc -p tsconfig-tsc.json --rootDir compiled
# Treeshaking with Rollup.js
$ rollup -c rollup.config.js -o dist/bundle.es2015.js
# Transpile resulting bundle to ES5
$ tsc --target es5 --allowJs dist/bundle.es2015.js —out
dist/bundle.js
# Minify
$ uglifyjs dist/bundle.js --compress --mangle --output
dist/bundle.min.js
$ ls -lah dist/bundle.min.js
-rw-r--r-- 1 Nesiri staff 199K Feb 19 06:25 dist/bundle.min.js
$ ls -lah dist/bundle.min.js
-rw-r--r-- 1 Nesiri staff 582K Feb 19 03:01 dist/bundle.min.js
$ ls -lah dist/bundle.min.js
-rw-r--r-- 1 Nesiri staff 199K Feb 19 06:25 dist/bundle.min.js
Reduced it by 65%!
All of these are in Angular CLI!
https://github.com/angular/angular-cli
# Build app with production config
ng build --prod --env=prod
Thanks and Qs?
Related stuff:

https://angular.io/docs/ts/latest/cookbook/aot-compiler.html

https://www.typescriptlang.org/docs/handbook/compiler-options.html

https://github.com/angular/angular-cli#usage

https://medium.com/@Rich_Harris/tree-shaking-versus-dead-code-
elimination-d3765df85c80#.p47uwmwev

http://rollupjs.org/guide/#what-is-rollup

Contenu connexe

Tendances

Gradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksGradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksDamian Mee
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Maurizio Pelizzone
 
Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]Erhwen Kuo
 
Beyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallBeyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallSteve Taylor
 
遠端團隊專案建立與管理 remote team management 2016
遠端團隊專案建立與管理 remote team management 2016遠端團隊專案建立與管理 remote team management 2016
遠端團隊專案建立與管理 remote team management 2016Caesar Chi
 
Die .htaccess richtig nutzen
Die .htaccess richtig nutzenDie .htaccess richtig nutzen
Die .htaccess richtig nutzenWalter Ebert
 
Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]Erhwen Kuo
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosLindsay Holmwood
 
Cookbook refactoring & abstracting logic to Ruby(gems)
Cookbook refactoring & abstracting logic to Ruby(gems)Cookbook refactoring & abstracting logic to Ruby(gems)
Cookbook refactoring & abstracting logic to Ruby(gems)Chef Software, Inc.
 
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitetKubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitetPer Bernhardt
 

Tendances (10)

Gradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksGradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarks
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]
 
Beyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallBeyond the WordPress 5 minute Install
Beyond the WordPress 5 minute Install
 
遠端團隊專案建立與管理 remote team management 2016
遠端團隊專案建立與管理 remote team management 2016遠端團隊專案建立與管理 remote team management 2016
遠端團隊專案建立與管理 remote team management 2016
 
Die .htaccess richtig nutzen
Die .htaccess richtig nutzenDie .htaccess richtig nutzen
Die .htaccess richtig nutzen
 
Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagios
 
Cookbook refactoring & abstracting logic to Ruby(gems)
Cookbook refactoring & abstracting logic to Ruby(gems)Cookbook refactoring & abstracting logic to Ruby(gems)
Cookbook refactoring & abstracting logic to Ruby(gems)
 
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitetKubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
 

En vedette

ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...
ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...
ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...Gabriel Araceli
 
ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28
ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28
ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28Gabriel Araceli
 
Matthew fuller city datastructure
Matthew fuller city datastructureMatthew fuller city datastructure
Matthew fuller city datastructureluruiyang
 
Ppt.co op.i coop+korea-20160927_수정+(1)
Ppt.co op.i coop+korea-20160927_수정+(1)Ppt.co op.i coop+korea-20160927_수정+(1)
Ppt.co op.i coop+korea-20160927_수정+(1)luruiyang
 
παράδειγμα και άσκηση στις επαναλήψεις
παράδειγμα και άσκηση στις επαναλήψειςπαράδειγμα και άσκηση στις επαναλήψεις
παράδειγμα και άσκηση στις επαναλήψειςKaterina Drimili
 
Codigo genético.
Codigo genético.Codigo genético.
Codigo genético.morejitos
 
Creative direction portafolio
Creative direction portafolioCreative direction portafolio
Creative direction portafolioRoman Lata Ares
 

En vedette (9)

ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...
ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...
ELECTRÓNICA+RADIO+TV. Tomo II: VÁLVULAS DE VACÍO I. ELECTROMETRÍA TEÓRICO-PRÁ...
 
ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28
ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28
ELECTRÓNICA+RADIO+TV. Tomo V: SUPERHETERODINO DE A.M. Lecciones 26, 27 y 28
 
Matthew fuller city datastructure
Matthew fuller city datastructureMatthew fuller city datastructure
Matthew fuller city datastructure
 
Ppt.co op.i coop+korea-20160927_수정+(1)
Ppt.co op.i coop+korea-20160927_수정+(1)Ppt.co op.i coop+korea-20160927_수정+(1)
Ppt.co op.i coop+korea-20160927_수정+(1)
 
παράδειγμα και άσκηση στις επαναλήψεις
παράδειγμα και άσκηση στις επαναλήψειςπαράδειγμα και άσκηση στις επαναλήψεις
παράδειγμα και άσκηση στις επαναλήψεις
 
Codigo genético.
Codigo genético.Codigo genético.
Codigo genético.
 
Creative direction portafolio
Creative direction portafolioCreative direction portafolio
Creative direction portafolio
 
Microbiologia parte 1
Microbiologia parte 1Microbiologia parte 1
Microbiologia parte 1
 
Kalyani_Gonde_Dec16
Kalyani_Gonde_Dec16Kalyani_Gonde_Dec16
Kalyani_Gonde_Dec16
 

Similaire à ngManila - Codename: Fireball - Hello World in Angular

Angular Notes.pdf
Angular Notes.pdfAngular Notes.pdf
Angular Notes.pdfsagarpal60
 
Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterSimon Brüggen
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeDamien Seguin
 
How to configure an environment to cross-compile applications for beagleboard-xM
How to configure an environment to cross-compile applications for beagleboard-xMHow to configure an environment to cross-compile applications for beagleboard-xM
How to configure an environment to cross-compile applications for beagleboard-xMDalton Valadares
 
Composer, putting dependencies on the score
Composer, putting dependencies on the scoreComposer, putting dependencies on the score
Composer, putting dependencies on the scoreRafael Dohms
 
Bundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMBundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMAlexander Shopov
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis OverviewLeo Lorieri
 
OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...
OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...
OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...NETWAYS
 
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style GuidesAdvanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style GuidesAidan Foster
 
Composer: putting dependencies on the score
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the scoreRafael Dohms
 
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StoryKon Soulianidis
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to androidOwen Hsu
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpMatthew Davis
 
MeaNstack on Docker
MeaNstack on DockerMeaNstack on Docker
MeaNstack on DockerDaniel Ku
 
Scripting for infosecs
Scripting for infosecsScripting for infosecs
Scripting for infosecsnancysuemartin
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupalDay
 

Similaire à ngManila - Codename: Fireball - Hello World in Angular (20)

Angular Notes.pdf
Angular Notes.pdfAngular Notes.pdf
Angular Notes.pdf
 
Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matter
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the like
 
How to configure an environment to cross-compile applications for beagleboard-xM
How to configure an environment to cross-compile applications for beagleboard-xMHow to configure an environment to cross-compile applications for beagleboard-xM
How to configure an environment to cross-compile applications for beagleboard-xM
 
Composer, putting dependencies on the score
Composer, putting dependencies on the scoreComposer, putting dependencies on the score
Composer, putting dependencies on the score
 
Bundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMBundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPM
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...
OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...
OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architectu...
 
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style GuidesAdvanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
 
Composer: putting dependencies on the score
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the score
 
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to android
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Angular2 - In Action
Angular2  - In ActionAngular2  - In Action
Angular2 - In Action
 
MeaNstack on Docker
MeaNstack on DockerMeaNstack on Docker
MeaNstack on Docker
 
Scripting for infosecs
Scripting for infosecsScripting for infosecs
Scripting for infosecs
 
appledoc_style
appledoc_styleappledoc_style
appledoc_style
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
nuxt-en.pdf
nuxt-en.pdfnuxt-en.pdf
nuxt-en.pdf
 

Dernier

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

ngManila - Codename: Fireball - Hello World in Angular

  • 1. HELLO WORLD IN ANGULAR Angular 2 Apps for Production
  • 2. ABOUT ME Iris Grace Endozo Software Engineer, Mobile Web Freelancer.com irise@freelancer.com @IrisEndozo
  • 3. A simple, unoptimized “Hello World” app bundle in Angular 2 is ~1.9MB!
  • 4. What’s the plan? Bundling and Minification Tree-shaking AoT compilation
  • 5. Hello World! <!-- index.html --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <hello-world-app></hello-world—app> <script src=“/node_modules/zone.js/dist/zone.js"> </script> <script src="dist/bundle.js"></script> </body> </html>
  • 6. // main.ts import { platformBrowserDynamic } from ‘@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule);
  • 7. // app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; @NgModule({ imports: [BrowserModule], bootstrap: [AppComponent], declarations: [AppComponent], }) export class AppModule {}
  • 8. // app.component.ts import { Component } from '@angular/core'; @Component({ selector: ‘hello-world-app', template: 'Hello world!' }) export class AppComponent {}
  • 9. What’s the plan? Bundling and Minification Browserify and UglifyJS Tree-shaking AoT compilation
  • 10. # Compile TS files using Typescript compiler to JS and # Build a bundle using Browserify $ tsc && browserify -s main dist/main.js > dist/bundle.js # Minify using Uglify $ uglifyjs dist/bundle.js --compress —mangle --output dist/bundle.min.js $ ls -lah dist/bundle.js -rw-r--r-- 1 Nesiri staff 1.9M Feb 19 02:47 dist/bundle.js
  • 11. # Compile TS files using Typescript compiler to JS and # Build a bundle using Browserify $ tsc && browserify -s main dist/main.js > dist/bundle.js # Minify using Uglify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js $ ls -lah dist/bundle.min.js -rw-r--r-- 1 Nesiri staff 582K Feb 19 03:01 dist/bundle.min.js
  • 12. What’s the plan? Bundling and Minification Tree-shaking Rollup.js AoT compilation
  • 13. Tree-shaking with Rollup.js ➤ supports ES2015 modules ➤ excludes unused exports from bundles import {Form} from './forms'; import {Users} from './users'; const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question(‘What is the type of user you want to get?’, answer => { const type = Users[answer]; type([1, 2, 3]); });
  • 14. # Transpile TS files to ES2015 $ tsc -t ES2015 # Rollup to bundle the ES2015 modules, use config file at # rollup.config.js and output at bundle.es2015.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 15. # Transpile TS files to ES2015 $ tsc -t ES2015 # Rollup to bundle the ES2015 modules, use config file at # rollup.config.js and output at bundle.es2015.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 16. # Transpile TS files to ES2015 $ tsc -t ES2015 # Rollup to bundle the ES2015 modules, use config file at # rollup.config.js and output at bundle.es2015.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js --out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 17. # Transpile TS files to ES2015 $ tsc -t ES2015 # Rollup to bundle the ES2015 modules, use config file at # rollup.config.js and output at bundle.es2015.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js --out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js $ ls -lah dist/bundle.min.js -rw-r--r-- 1 Nesiri staff 532K Feb 19 04:14 dist/bundle.min.js
  • 18. What’s the plan? Bundling and Minification Tree-shaking AoT compilation ngc
  • 19. Ahead of Time Compilation ➤ Why? ➤ Faster rendering - no need to wait for the app to be compiled before executing code ➤ Smaller NG framework download - no need for the NG compiler as the stuff is already compiled, drastically reducing the size of NG needed ➤ Template error detection - template binding errors are determined during build steps
  • 20. # Compile application (including HTML templates) to TS $ ngc -p tsconfig.json && cp app/* compiled # Transpile TS files to ES2015 $ tsc -p tsconfig-tsc.json --rootDir compiled # Treeshaking with Rollup.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 21. # Compile application (including HTML templates) to TS $ ngc -p tsconfig.json && cp app/* compiled # Transpile TS files to ES2015 $ tsc -p tsconfig-tsc.json --rootDir compiled # Treeshaking with Rollup.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 22. # Compile application (including HTML templates) to TS $ ngc -p tsconfig.json && cp app/* compiled # Transpile TS files to ES2015 $ tsc -p tsconfig-tsc.json --rootDir compiled # Treeshaking with Rollup.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 23. # Compile application (including HTML templates) to TS $ ngc -p tsconfig.json && cp app/* compiled # Transpile TS files to ES2015 $ tsc -p tsconfig-tsc.json --rootDir compiled # Treeshaking with Rollup.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js
  • 24. # Compile application (including HTML templates) to TS $ ngc -p tsconfig.json && cp app/* compiled # Transpile TS files to ES2015 $ tsc -p tsconfig-tsc.json --rootDir compiled # Treeshaking with Rollup.js $ rollup -c rollup.config.js -o dist/bundle.es2015.js # Transpile resulting bundle to ES5 $ tsc --target es5 --allowJs dist/bundle.es2015.js —out dist/bundle.js # Minify $ uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js $ ls -lah dist/bundle.min.js -rw-r--r-- 1 Nesiri staff 199K Feb 19 06:25 dist/bundle.min.js
  • 25. $ ls -lah dist/bundle.min.js -rw-r--r-- 1 Nesiri staff 582K Feb 19 03:01 dist/bundle.min.js $ ls -lah dist/bundle.min.js -rw-r--r-- 1 Nesiri staff 199K Feb 19 06:25 dist/bundle.min.js Reduced it by 65%!
  • 26. All of these are in Angular CLI! https://github.com/angular/angular-cli # Build app with production config ng build --prod --env=prod
  • 27. Thanks and Qs? Related stuff: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html https://www.typescriptlang.org/docs/handbook/compiler-options.html https://github.com/angular/angular-cli#usage https://medium.com/@Rich_Harris/tree-shaking-versus-dead-code- elimination-d3765df85c80#.p47uwmwev http://rollupjs.org/guide/#what-is-rollup