SlideShare a Scribd company logo
Webpack: from 0 to 2(.3.3)
Milano_JS
04.04.2017
Alessandro Bellini
frontend developer @ Spryker
- web: ilmente.com
- github: github.com/ilmente
- twitter: @ilmente
Agenda
- grunt, gulp and webpack
- webpack modules
- entry points
- loaders and plugins
- configuration - code overview
- code splitting - code overview
- tree shaking - code overview
in the beginning it was grunt
grunt
- focus on configurations
- built around a set of built-in commonly used tasks
- extension using plugins
- each plugin has its own custom configuration
- every task is an array of different plugin configurations, that
simply get executed one after another, in a strictly independent, and
sequential fashion
https://medium.com/@preslavrachev/gulp-vs-grunt-why-one-why-the-other-f5d3b398edc4
then came gulp
gulp
- focus on code
- micro-tasks connected to each other (agnostic about their nature)
- extension using plugins
- plugins use API to be programmed
- streams and pipelines
https://medium.com/@preslavrachev/gulp-vs-grunt-why-one-why-the-other-f5d3b398edc4
and now webpack
grunt
- focus on configurations
- built around a set of built-in commonly used tasks
- extension using plugins
- each plugin has its own custom configuration
- every task is an array of different plugin configurations, that
simply get executed one after another, in a strictly independent, and
sequential fashion
https://medium.com/@preslavrachev/gulp-vs-grunt-why-one-why-the-other-f5d3b398edc4
grunt webpack
- focus on configurations
- built around a set of built-in commonly used tasks
- extension using plugins
- each plugin has its own custom configuration
- every task is an array of different plugin configurations, that
simply get executed one after another, in a strictly independent, and
sequential fashion
close, but it’s not exactly like this...
grunt webpack
- focus on configurations
- built around a set of built-in commonly used tasks features
- extension using plugins and loaders
- each plugin/loader has its own custom configuration
- every task compile process (or step) is an array of different plugin
loaders (eventually configured/extend using plugins) configurations,
that simply get executed one after another, in a strictly
independent, and sequential fashion
- loaders can be chained together: this is helpful for applying
multiple transformations to a file in a pipeline
https://webpack.github.io/docs/loaders.html (webpack 1.x docs)
grunt - gulp - webpack
- grunt and gulp are task runners
- webpack is a module bundler
- gulp and webpack are not necessary enemies
You can use webpack with grunt/gulp:
- https://webpack.js.org/guides/task-test-runner/
(almost useless page)
- http://webpack.github.io/docs/usage-with-grunt.html
- http://webpack.github.io/docs/usage-with-gulp.html
Webpack: from 0 to 2
webpack modules
not just modules
modules
- discrete chunk of functionality a program is broken into
- abstraction
- single responsability
- reusability
- better debugging and testing
webpack modules
- a dependency expressed by:
- import (es2015)
- require() (CommonJS)
- define() and require() (AMD)
- @import (css/sass/less)
- url() (stylesheet)
- <img src=””> (html)
(!) Please refer to https://webpack.js.org/concepts: it’s well done and explained
entry points
the root of the tree
- root of the tree
loaders and plugins
is this a kind of magic?
loaders
- functions
- transform the source code of a module
- synchronous or asynchronous
- can be configured with options
- can be chained
- can emit additional arbitrary files
https://webpack.js.org/concepts/loaders
plugins
- webpack backbone
- “anything else that a loader cannot do” (cit.)
- it’s wizardry
- can you do everything?
- may I have a coffee?
- hooks into the whole webpack build system
- allow you to access, change, extend any phase of the build process,
from resolving a module to bundling the output
https://webpack.github.io/docs/plugins.html
in a nutshell
- if you want to tell webpack how to load that specific type of
resource: use loaders
- everything else: use plugins
in a nutshell
- if you want to tell webpack how to load that specific type of
resource: use loaders
- everything else: use plugins
- if you want to change how this module is resolved and compiled: use
plugins
a real configuration
let’s switch to the code
code splitting
introducing performance superheroes
code splitting
- it’s a features
- split your code into various bundles
- smaller bundle size
- resource load prioritization control
- on-demand loading
- may have significant performance impact
- on build/rebuild time
- on application/site load time
- you have the freedom to choose and implement your own strategy to
optimise the assets management
https://webpack.js.org/guides/code-splitting/
- root of the tree
code splitting superheroes
- css
- style-loader
- ExtractTextWebpackPlugin
- vendor
- CommonsChunkPlugin
- on-demand
- import()
- require.ensure()
https://webpack.js.org/guides/code-splitting/
tree shaking
bullshit, myth
or shut-up-and-take-my-money feature?
tree shaking
- positive selection of actual used code (live code)
- in opposition to dead code removal (UglifyJs plugin)
- introduced in bundlers world by github.com/rollup/rollup
Known limitations for webpack:
- static structure
- relies on es2015 module import/export
https://webpack.js.org/guides/tree-shaking
the code said…
- babel:
- use preset babel-preset-es2015 with { “modules”: false }
- use plugin babel-plugin-syntax-dynamic-import
- limited to es2015 source code
- unable to shake objects or inside statements
- capable of dropping functions, but not classes
- uglifyJS plugin needed
https://webpack.js.org
it’s my main source
thanks
yes, it’s finally over…

More Related Content

PDF
Webpack DevTalk
PDF
Webpack Tutorial, Uppsala JS
PPTX
An Intro into webpack
PDF
webpack 101 slides
PDF
Hey webpack
PDF
Webpack
PPTX
Improving build solutions dependency management with webpack
Webpack DevTalk
Webpack Tutorial, Uppsala JS
An Intro into webpack
webpack 101 slides
Hey webpack
Webpack
Improving build solutions dependency management with webpack

What's hot (20)

PPTX
Webpack
PDF
Bundle your modules with Webpack
PPTX
Webpack Introduction
PDF
Packing it all: JavaScript module bundling from 2000 to now
PPTX
Packing for the Web with Webpack
PPTX
PDF
Production optimization with React and Webpack
PDF
Bower & Grunt - A practical workflow
PDF
Once upon a time, there were css, js and server-side rendering
PPTX
Webpack and Web Performance Optimization
PDF
Advanced front-end automation with npm scripts
PDF
Andrew Mykhaliuk - Sorry, I need to make a build for frontend
PPTX
Grunt and Bower
PPTX
Bundling your front-end with Webpack
PDF
Grunt.js and Yeoman, Continous Integration
PDF
Introduction to Express and Grunt
PPTX
#2 Hanoi Magento Meetup - Part 2: Knockout JS
PPTX
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
PDF
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
PDF
Angular2 ecosystem
Webpack
Bundle your modules with Webpack
Webpack Introduction
Packing it all: JavaScript module bundling from 2000 to now
Packing for the Web with Webpack
Production optimization with React and Webpack
Bower & Grunt - A practical workflow
Once upon a time, there were css, js and server-side rendering
Webpack and Web Performance Optimization
Advanced front-end automation with npm scripts
Andrew Mykhaliuk - Sorry, I need to make a build for frontend
Grunt and Bower
Bundling your front-end with Webpack
Grunt.js and Yeoman, Continous Integration
Introduction to Express and Grunt
#2 Hanoi Magento Meetup - Part 2: Knockout JS
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Angular2 ecosystem
Ad

Similar to Webpack: from 0 to 2 (20)

PPTX
Building JavaScript
PDF
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
PDF
Multi modularized project setup with gulp, typescript and angular.js
PDF
DevHub 3 - Composer plus Magento
PDF
PPT
Maven 2.0 - Project management and comprehension tool
PPT
Maven Introduction
PPTX
Alfresco DevCon 2018: SDK 3 Multi Module project using Nexus 3 for releases a...
PDF
PPTX
Tribal Nova Docker feedback
PPTX
Decrease build time and application size
PDF
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
PPTX
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
PDF
ESIGate dev meeting #4 21-11-2013
PDF
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
PPTX
Webpack/Parcel: What’s Happening Behind the React App?
PPTX
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
PPTX
Tutorial 1: Your First Science App - Araport Developer Workshop
PDF
Michal Havryluk: How To Speed Up Android Gradle Builds
PDF
Create ReactJS Component & publish as npm package
Building JavaScript
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
Multi modularized project setup with gulp, typescript and angular.js
DevHub 3 - Composer plus Magento
Maven 2.0 - Project management and comprehension tool
Maven Introduction
Alfresco DevCon 2018: SDK 3 Multi Module project using Nexus 3 for releases a...
Tribal Nova Docker feedback
Decrease build time and application size
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
ESIGate dev meeting #4 21-11-2013
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
Webpack/Parcel: What’s Happening Behind the React App?
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Tutorial 1: Your First Science App - Araport Developer Workshop
Michal Havryluk: How To Speed Up Android Gradle Builds
Create ReactJS Component & publish as npm package
Ad

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PDF
Digital Strategies for Manufacturing Companies
PDF
AI in Product Development-omnex systems
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administraation Chapter 3
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
history of c programming in notes for students .pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPT
Introduction Database Management System for Course Database
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
medical staffing services at VALiNTRY
Digital Strategies for Manufacturing Companies
AI in Product Development-omnex systems
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms II-SECS-1021-03
Understanding Forklifts - TECH EHS Solution
Introduction to Artificial Intelligence
System and Network Administraation Chapter 3
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
history of c programming in notes for students .pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
ManageIQ - Sprint 268 Review - Slide Deck
Introduction Database Management System for Course Database
Online Work Permit System for Fast Permit Processing
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

Webpack: from 0 to 2

  • 1. Webpack: from 0 to 2(.3.3) Milano_JS 04.04.2017
  • 2. Alessandro Bellini frontend developer @ Spryker - web: ilmente.com - github: github.com/ilmente - twitter: @ilmente
  • 3. Agenda - grunt, gulp and webpack - webpack modules - entry points - loaders and plugins - configuration - code overview - code splitting - code overview - tree shaking - code overview
  • 4. in the beginning it was grunt
  • 5. grunt - focus on configurations - built around a set of built-in commonly used tasks - extension using plugins - each plugin has its own custom configuration - every task is an array of different plugin configurations, that simply get executed one after another, in a strictly independent, and sequential fashion https://medium.com/@preslavrachev/gulp-vs-grunt-why-one-why-the-other-f5d3b398edc4
  • 7. gulp - focus on code - micro-tasks connected to each other (agnostic about their nature) - extension using plugins - plugins use API to be programmed - streams and pipelines https://medium.com/@preslavrachev/gulp-vs-grunt-why-one-why-the-other-f5d3b398edc4
  • 9. grunt - focus on configurations - built around a set of built-in commonly used tasks - extension using plugins - each plugin has its own custom configuration - every task is an array of different plugin configurations, that simply get executed one after another, in a strictly independent, and sequential fashion https://medium.com/@preslavrachev/gulp-vs-grunt-why-one-why-the-other-f5d3b398edc4
  • 10. grunt webpack - focus on configurations - built around a set of built-in commonly used tasks - extension using plugins - each plugin has its own custom configuration - every task is an array of different plugin configurations, that simply get executed one after another, in a strictly independent, and sequential fashion close, but it’s not exactly like this...
  • 11. grunt webpack - focus on configurations - built around a set of built-in commonly used tasks features - extension using plugins and loaders - each plugin/loader has its own custom configuration - every task compile process (or step) is an array of different plugin loaders (eventually configured/extend using plugins) configurations, that simply get executed one after another, in a strictly independent, and sequential fashion - loaders can be chained together: this is helpful for applying multiple transformations to a file in a pipeline https://webpack.github.io/docs/loaders.html (webpack 1.x docs)
  • 12. grunt - gulp - webpack - grunt and gulp are task runners - webpack is a module bundler - gulp and webpack are not necessary enemies You can use webpack with grunt/gulp: - https://webpack.js.org/guides/task-test-runner/ (almost useless page) - http://webpack.github.io/docs/usage-with-grunt.html - http://webpack.github.io/docs/usage-with-gulp.html
  • 15. modules - discrete chunk of functionality a program is broken into - abstraction - single responsability - reusability - better debugging and testing
  • 16. webpack modules - a dependency expressed by: - import (es2015) - require() (CommonJS) - define() and require() (AMD) - @import (css/sass/less) - url() (stylesheet) - <img src=””> (html) (!) Please refer to https://webpack.js.org/concepts: it’s well done and explained
  • 17. entry points the root of the tree
  • 18. - root of the tree
  • 19. loaders and plugins is this a kind of magic?
  • 20. loaders - functions - transform the source code of a module - synchronous or asynchronous - can be configured with options - can be chained - can emit additional arbitrary files https://webpack.js.org/concepts/loaders
  • 21. plugins - webpack backbone - “anything else that a loader cannot do” (cit.) - it’s wizardry - can you do everything? - may I have a coffee? - hooks into the whole webpack build system - allow you to access, change, extend any phase of the build process, from resolving a module to bundling the output https://webpack.github.io/docs/plugins.html
  • 22. in a nutshell - if you want to tell webpack how to load that specific type of resource: use loaders - everything else: use plugins
  • 23. in a nutshell - if you want to tell webpack how to load that specific type of resource: use loaders - everything else: use plugins - if you want to change how this module is resolved and compiled: use plugins
  • 24. a real configuration let’s switch to the code
  • 26. code splitting - it’s a features - split your code into various bundles - smaller bundle size - resource load prioritization control - on-demand loading - may have significant performance impact - on build/rebuild time - on application/site load time - you have the freedom to choose and implement your own strategy to optimise the assets management https://webpack.js.org/guides/code-splitting/
  • 27. - root of the tree
  • 28. code splitting superheroes - css - style-loader - ExtractTextWebpackPlugin - vendor - CommonsChunkPlugin - on-demand - import() - require.ensure() https://webpack.js.org/guides/code-splitting/
  • 29. tree shaking bullshit, myth or shut-up-and-take-my-money feature?
  • 30. tree shaking - positive selection of actual used code (live code) - in opposition to dead code removal (UglifyJs plugin) - introduced in bundlers world by github.com/rollup/rollup Known limitations for webpack: - static structure - relies on es2015 module import/export https://webpack.js.org/guides/tree-shaking
  • 31. the code said… - babel: - use preset babel-preset-es2015 with { “modules”: false } - use plugin babel-plugin-syntax-dynamic-import - limited to es2015 source code - unable to shake objects or inside statements - capable of dropping functions, but not classes - uglifyJS plugin needed