SlideShare a Scribd company logo
What’s new in Angular with
JHipster ?
William Marques - JHipster Conf
About me
William MARQUES
24 years old
JHipster Core Team Member
Java lover <3
Ippon Technologies
@wylmarq
Script lover <3
JHipster objectives
Keep the configuration simple
Provide the best practices
Make your production build as small as possible
Make your dev workflow fast
What did we do ?
1. Upgrade to Webpack 4
2. Setup Lazy Loading
3. Add some optimizations
4. Migrate to Jest
Webpack 4 upgrade
Upgrade to Webpack 4
Webpack 4 announced main features:
● Better performances => Faster build times
● Easier configuration
● Many others !
Build times
JHipster 4 (webpack 3.10.0) JHipster 5 (webpack 4.8.0)
yarn start (dev) 12s 7s
Incremental (dev) 2s 0.7s
yarn build (prod) 29s 49s
target/www size 3,6M 2,9M
Let’s explore Webpack !
Lazy Loading
Why Lazy Loading ?
Purpose: Render only what’s useful for the user
ie: A normal user shouldn’t have to wait for the admin module !
Results:
● Smaller files to load on application startup
● Faster loading
Why smaller files ?
https://www.thinkwithgoogle.com/marketing-resources/data-measurement/mobile-page-speed-new-industry-benchmarks/
How do I do that in Angular ?
Lazy Loading in Angular
Easy as 1, 2, 3 !
1. Make sure you don’t import same providers in many places
2. Use loadChildren in your route config
3. Remove your Module imports from AppModule
The importance of a Core Module
Angular will create one provider instance per Lazy Loaded Modules if your import
your providers into them.
This can be annoying if you think your providers as singletons !
Solution:
● Import your singletons providers in a Core Module
● Import this Core Module only in your App Module
A Core Module is already present in JHipster 5 !
Example Architecture
Core Module
App Module
(root)
Feature Module B
Shared Module
Feature Module A
Core Module Providers are accessibl
from Lazy Loaded Modules via the
root injection tree
JHipster Routing Module
Other optimizations
MomentJS Optimizations
Moment is an awesome library…
But it’s HUGE
By default, it includes all the locales
Source: https://bundlephobia.com/result?p=moment@2.22.2
MomentJS Optimizations
We used the moment-locales-plugin for Webpack
=> Keep only the used locales in your prod build !
Julien is happy now !
Font Awesome v5
Has been rewritten from scratch
Now uses SVG with JS instead of plain CSS
≈ 420kb minified !
≈ 3s to load on 3G
Font Awesome v5 in JHipster
Imports only the icons you need in the generated app in vendor.ts
Then Webpack does the magic tree shaking
Jest Migration
Jest vs Karma/Jasmine
Uses a Virtual DOM Uses a real browser
Run tests in parallel Run tests one by one
All In One (Runner, framework, coverage) One tool for each thing
Uses preprocessor Uses webpack
Jest Migration in JHipster
Remove webpack.test.js and karma.conf.js
Add Jest Config file from a fresh generated app
Use jest-codemods to migrate from Jasmine to Jest
See: https://facebook.github.io/jest/docs/en/migration-guide.html
JHipster PR: https://github.com/jhipster/generator-jhipster/pull/7663/files
Time Comparison
Time Comparison
First run 15s 37s
Second run 10s 37s
What about “real browser” tests ?
Jest uses a virtual DOM (jsdom) instead of a real browser
You can still have end-to-end tests with Protractor with various real browsers
The point of Unit Tests is to test your code, not the browser
TypeScript already compiles your code into ES5 so it will be compatible with most
browsers
https://caniuse.com/#feat=es5
Thank you !

More Related Content

PDF
Introduction to node js - From "hello world" to deploying on azure
PPTX
Node js Global Packages
PPTX
Packing for the Web with Webpack
PPTX
#2 Hanoi Magento Meetup - Part 2: Knockout JS
PDF
Nodejs
PDF
Node4J: Running Node.js in a JavaWorld
PDF
Node, express & sails
PPTX
Node js Introduction
Introduction to node js - From "hello world" to deploying on azure
Node js Global Packages
Packing for the Web with Webpack
#2 Hanoi Magento Meetup - Part 2: Knockout JS
Nodejs
Node4J: Running Node.js in a JavaWorld
Node, express & sails
Node js Introduction

What's hot (20)

PPTX
3 Things Everyone Knows About Node JS That You Don't
PDF
Understanding Non Blocking I/O with Python
PDF
Best node js course
PPTX
PDF
Advanced front-end automation with npm scripts
PDF
Webpack
PDF
Frontend Build Tools - CC FE & UX
PDF
Web Applications with Eclipse RT and Docker in the Cloud
PPTX
Node js for beginners
PPTX
Javascript Bundling and modularization
PPT
Nodejs - Building a RESTful API
PDF
[Js hcm] Deploying node.js with Forever.js and nginx
PDF
Build your first DApp using Substrate Framework - Part I
PDF
Nightwatch.js (vodQA Shots - Pune 2017)
PDF
S&T What I know about Node 110817
PDF
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
PPTX
PHP Indonesia - Nodejs Web Development
PPTX
006. React - Redux framework
PPTX
Grunt and Bower
PDF
WordPress development checklist
3 Things Everyone Knows About Node JS That You Don't
Understanding Non Blocking I/O with Python
Best node js course
Advanced front-end automation with npm scripts
Webpack
Frontend Build Tools - CC FE & UX
Web Applications with Eclipse RT and Docker in the Cloud
Node js for beginners
Javascript Bundling and modularization
Nodejs - Building a RESTful API
[Js hcm] Deploying node.js with Forever.js and nginx
Build your first DApp using Substrate Framework - Part I
Nightwatch.js (vodQA Shots - Pune 2017)
S&T What I know about Node 110817
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
PHP Indonesia - Nodejs Web Development
006. React - Redux framework
Grunt and Bower
WordPress development checklist
Ad

Recently uploaded (20)

PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
The Internet -By the Numbers, Sri Lanka Edition
PPTX
Digital Literacy And Online Safety on internet
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPT
tcp ip networks nd ip layering assotred slides
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
Funds Management Learning Material for Beg
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
E -tech empowerment technologies PowerPoint
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
Unit-1 introduction to cyber security discuss about how to secure a system
Cloud-Scale Log Monitoring _ Datadog.pdf
The Internet -By the Numbers, Sri Lanka Edition
Digital Literacy And Online Safety on internet
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Paper PDF World Game (s) Great Redesign.pdf
WebRTC in SignalWire - troubleshooting media negotiation
522797556-Unit-2-Temperature-measurement-1-1.pptx
Slides PPTX World Game (s) Eco Economic Epochs.pptx
tcp ip networks nd ip layering assotred slides
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Funds Management Learning Material for Beg
Sims 4 Historia para lo sims 4 para jugar
Slides PDF The World Game (s) Eco Economic Epochs.pdf
E -tech empowerment technologies PowerPoint
Job_Card_System_Styled_lorem_ipsum_.pptx
Power Point - Lesson 3_2.pptx grad school presentation
RPKI Status Update, presented by Makito Lay at IDNOG 10
Ad

Angular + JHipster - JHipster Conf

  • 1. What’s new in Angular with JHipster ? William Marques - JHipster Conf
  • 2. About me William MARQUES 24 years old JHipster Core Team Member Java lover <3 Ippon Technologies @wylmarq Script lover <3
  • 3. JHipster objectives Keep the configuration simple Provide the best practices Make your production build as small as possible Make your dev workflow fast
  • 4. What did we do ? 1. Upgrade to Webpack 4 2. Setup Lazy Loading 3. Add some optimizations 4. Migrate to Jest
  • 6. Upgrade to Webpack 4 Webpack 4 announced main features: ● Better performances => Faster build times ● Easier configuration ● Many others !
  • 7. Build times JHipster 4 (webpack 3.10.0) JHipster 5 (webpack 4.8.0) yarn start (dev) 12s 7s Incremental (dev) 2s 0.7s yarn build (prod) 29s 49s target/www size 3,6M 2,9M
  • 10. Why Lazy Loading ? Purpose: Render only what’s useful for the user ie: A normal user shouldn’t have to wait for the admin module ! Results: ● Smaller files to load on application startup ● Faster loading
  • 11. Why smaller files ? https://www.thinkwithgoogle.com/marketing-resources/data-measurement/mobile-page-speed-new-industry-benchmarks/
  • 12. How do I do that in Angular ?
  • 13. Lazy Loading in Angular Easy as 1, 2, 3 ! 1. Make sure you don’t import same providers in many places 2. Use loadChildren in your route config 3. Remove your Module imports from AppModule
  • 14. The importance of a Core Module Angular will create one provider instance per Lazy Loaded Modules if your import your providers into them. This can be annoying if you think your providers as singletons ! Solution: ● Import your singletons providers in a Core Module ● Import this Core Module only in your App Module A Core Module is already present in JHipster 5 !
  • 15. Example Architecture Core Module App Module (root) Feature Module B Shared Module Feature Module A Core Module Providers are accessibl from Lazy Loaded Modules via the root injection tree
  • 18. MomentJS Optimizations Moment is an awesome library… But it’s HUGE By default, it includes all the locales Source: https://bundlephobia.com/result?p=moment@2.22.2
  • 19. MomentJS Optimizations We used the moment-locales-plugin for Webpack => Keep only the used locales in your prod build ! Julien is happy now !
  • 20. Font Awesome v5 Has been rewritten from scratch Now uses SVG with JS instead of plain CSS ≈ 420kb minified ! ≈ 3s to load on 3G
  • 21. Font Awesome v5 in JHipster Imports only the icons you need in the generated app in vendor.ts Then Webpack does the magic tree shaking
  • 23. Jest vs Karma/Jasmine Uses a Virtual DOM Uses a real browser Run tests in parallel Run tests one by one All In One (Runner, framework, coverage) One tool for each thing Uses preprocessor Uses webpack
  • 24. Jest Migration in JHipster Remove webpack.test.js and karma.conf.js Add Jest Config file from a fresh generated app Use jest-codemods to migrate from Jasmine to Jest See: https://facebook.github.io/jest/docs/en/migration-guide.html JHipster PR: https://github.com/jhipster/generator-jhipster/pull/7663/files
  • 26. Time Comparison First run 15s 37s Second run 10s 37s
  • 27. What about “real browser” tests ? Jest uses a virtual DOM (jsdom) instead of a real browser You can still have end-to-end tests with Protractor with various real browsers The point of Unit Tests is to test your code, not the browser TypeScript already compiles your code into ES5 so it will be compatible with most browsers https://caniuse.com/#feat=es5