SlideShare a Scribd company logo
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 remarks
Damian 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 Install
Steve Taylor
 
遠端團隊專案建立與管理 remote team management 2016
遠端團隊專案建立與管理 remote team management 2016遠端團隊專案建立與管理 remote team management 2016
遠端團隊專案建立與管理 remote team management 2016
Caesar Chi
 
Die .htaccess richtig nutzen
Die .htaccess richtig nutzenDie .htaccess richtig nutzen
Die .htaccess richtig nutzen
Walter 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-nagios
Lindsay 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 arbeitet
Per 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 28
Gabriel Araceli
 
Matthew fuller city datastructure
Matthew fuller city datastructureMatthew fuller city datastructure
Matthew fuller city datastructure
luruiyang
 
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 portafolio
Roman Lata Ares
 
Microbiologia parte 1
Microbiologia parte 1Microbiologia parte 1
Microbiologia parte 1
Elisângela Bispo
 
Kalyani_Gonde_Dec16
Kalyani_Gonde_Dec16Kalyani_Gonde_Dec16
Kalyani_Gonde_Dec16
Kalyani Anil Gonde
 

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.pdf
sagarpal60
 
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
Simon 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 like
Damien 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-xM
Dalton Valadares
 
Composer, putting dependencies on the score
Composer, putting dependencies on the scoreComposer, putting dependencies on the score
Composer, putting dependencies on the score
Rafael 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 RPM
Alexander 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 Overview
Leo 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 Guides
Aidan Foster
 
Composer: putting dependencies on the score
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the score
Rafael 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 Story
Kon Soulianidis
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to android
Owen 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 Gulp
Matthew Davis
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
Norberto Leite
 
Angular2 - In Action
Angular2  - In ActionAngular2  - In Action
Angular2 - In Action
Sebastian Pożoga
 
MeaNstack on Docker
MeaNstack on DockerMeaNstack on Docker
MeaNstack on Docker
Daniel Ku
 
Scripting for infosecs
Scripting for infosecsScripting for infosecs
Scripting for infosecs
nancysuemartin
 
appledoc_style
appledoc_styleappledoc_style
appledoc_style
Ziku Spartan
 
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
DrupalDay
 
nuxt-en.pdf
nuxt-en.pdfnuxt-en.pdf
nuxt-en.pdf
ssuser65180a
 

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

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 

Recently uploaded (20)

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 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