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

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Dernier (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

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