SlideShare a Scribd company logo
1 of 27
Download to read offline
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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

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