SlideShare a Scribd company logo
1 of 106
Download to read offline
Webpack
Packing it all
–See no evil monkey
“Webpack is just a module bundler.”
!
Why do we need a
module bundler?
Why we need
module bundling
early web
<html>
<head>
<script src="header.js"></script>
<script src="menu.js"></script>
<script src="sidebar.js"></script>
<script src="fancy-button.js"></script>
<script src="carousel.js"></script>
</head>
<body>
</body>
</html>
2003
JSMin
The JavaScript Minifier
Douglas Crockford
www.crockford.com
2003-12-04
JSMin is a filter which removes comments and unnecessary whitespace from JavaScript files. It typically reduces filesize by half, resulting
in faster downloads. It also encourages a more expressive programming style because it eliminates the download cost of clean, literate
self-documentation.
What JSMin Does
JSMin is a filter that omits or modifies some characters. This does not change the behavior of the program that it is minifying. The result
may be harder to debug. It will definitely be harder to read.
JSMin first replaces carriage returns ('r') with linefeeds ('n'). It replaces all other control characters (including tab) with spaces. It
replaces comments in the // form with linefeeds. It replaces comments in the /* */ form with spaces. All runs of spaces are replaced with
a single space. All runs of linefeeds are replaced with a single linefeed.
It omits spaces except when a space is preceded and followed by a non-ASCII character or by an ASCII letter or digit, or by one of these
characters:
 $ _
It is more conservative in omitting linefeeds, because linefeeds are sometimes treated as semicolons. A linefeed is not omitted if it
precedes a non-ASCII character or an ASCII letter or digit or one of these characters:
 $ _ { [ ( + -
and if it follows a non-ASCII character or an ASCII letter or digit or one of these characters:
 $ _ } ] ) + - " '
No other characters are omitted or modified.
<html>
<head>
<script src="header.min.js"></script>
<script src="menu.min.js"></script>
<script src="sidebar.min.js"></script>
<script src="fancy-button.min.js"></script>
<script src="carousel.min.js"></script>
</head>
<body>
</body>
</html>
still too many files
use all browser
connections
add request overhead
hard to invalidate cache
let’s concatenate files
wrap every file with an IIFE
;(function () {
var counter = 0
...
})();
;(function () {
var xpto = 0
...
})();
to isolate file scope
each file is now a module
concatenate all files
now you have the bundle
<html>
<head>
<script src="app.min.js"></script>
</head>
<body>
</body>
</html>
2006
jQuery
New Wave Javascript
jQuery is a new type of Javascript library. It is not a huge, bloated, framework
promising the best in AJAX - nor is just a set of needlessly complex
enhancements - jQuery is designed to change the way that you write
Javascript.
New: The jQuery Mailing List is now up - join and discuss!
New: The jQuery Blog has just been opened - subscribe now!
What is jQuery?
jQuery is a Javascript library that takes this motto to heart: Writing Javascript
code should be fun. jQuery acheives this goal by taking common, repetitive,
tasks, stripping out all the unnecessary markup, and leaving them short, smart
and understandable.
What does jQuery code look like? The quick and dirty:
The above code snippet looks for all paragraphs that have a class of 'surprise',
adds the class 'ohmy' to them, then slowly reveals them. Click the 'Run' button
to see it in action!
Quick Facts:
jQuery supports CSS 1-3 and basic XPath.
jQuery is about 10kb in size.
jQuery works in Internet Explorer, Firefox, Safari, and Opera.
Getting Started:
$("p.surprise").addClass("ohmy").show("slow");
Congratulations! You just ran a snippet of jQuery code - wasn't that
easy? There's lots of example code throughout the documentation, on
this site - be sure to give all the code a test run, to see what happens.
jQuery popularized AJAX
lots of community plugins
some problems too
<html>
<head>
<script src="jquery.min.js"></script>
...
<script src="jquery.soundy.min.js"></script>
<script src="jquery.fancy.min.js"></script>
<script src="jquery.blinky.min.js"></script>
<script src="photo-gallery.min.js"></script>
</head>
<body>
</body>
</html>
<html>
<head>
<script src="jquery.min.js"></script>
...
<script src="jquery.soundy.min.js"></script>
<script src="jquery.fancy.min.js"></script>
<script src="jquery.blinky.min.js"></script>
<script src="about-us.min.js"></script>
</head>
<body>
</body>
</html>
<html>
<head>
<script src="jquery.min.js"></script>
...
<script src="jquery.soundy.min.js"></script>
<script src="jquery.fancy.min.js"></script>
<script src=“jquery.blinky.min.js"></script>
<script src="contact-us.min.js"></script>
</head>
<body>
</body>
</html>
manual dependency order
script tag ordering hell
2007
and it included…
a real browser!
web apps had to be light
they had to be smooth
we already had async http
let’s do more single page
<html>
<head>
<script src="jquery.min.js"></script>
...
<script src="jquery.soundy.min.js"></script>
<script src="jquery.fancy.min.js"></script>
<script src="jquery.blinky.min.js"></script>
<script src="app.min.js"></script>
</head>
<body>
</body>
</html>
in this new approach
full app was downloaded
even unneeded code
we needed lazy load
dependency ordering
2009
commonjs is born
hello async modules
<html>
<head>
<script src="r.js"></script>
<script>
require(["app.js"])
</script>
</head>
<body>
</body>
</html>
index.html
app.js
require(["jquery.fancy", "jquery.soundy"], function () {
$(".target").fancy()
})
now single page apps
could load app code
progressively
but with dependencies
comes managing
we used to
download and drop .min.js
in the project
version control was hard
2010
JavaScript outside browser
module based from day 0
set us free from browser
brought sane packages
a package manager
with the power of node
lots of tools were created
solving pains from the past
also in the same year
suddenly we were writing
not just web pages
but entire applications
2012
after lots of nasty scripts
a boom of task managers
we created extensive
gruntfiles
gulpfiles
2014
React became popular
Webpack had its glory
since then
we have been doing nice
lots of overhead is over
2017
const path = require('path')
module.exports = {
entry: './index.js',
output: {
path: path.join(__dirname, 'dist'),
filename: "bundle.js",
},
module: {
rules: [
{
test: /.js$/,
use: ['babel-loader'],
},
{
test: /.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /.(svg|otf|woff|woff2|ttf|otf|png|jpg|gif)$/,
use: ['file-loader'],
}
]
}
}
module
bundler
builds a dependency tree
by walking though imports
every single dependency
of your system is a module
loaders are the key point
have standard interface
take an input
output transformed
content
J S X J S ( E S 5 )
babel-loader
S C S S C S S
postcss-loader
P N G B A S E 6 4
url-loader
B U N D L E . J S
outputs can be
chunks or files
chunks are text modules
concatenated in bundle
files are emitted in
output directory
a handful of loaders
url-loader
file-loader
json-loader
json5-loader
script-loader
babel-loader
coffee-loader
html-loader
pug-loader
jade-loader
style-loader
css-loader
sass-loader
less-loader
postcss-loader
eslint-loader
loaders can be piped
const path = require('path')
module.exports = {
entry: './index.js',
output: {
path: path.join(__dirname, 'dist'),
filename: "bundle.js",
},
module: {
rules: [
{
test: /.js$/,
use: ['babel-loader'],
},
{
test: /.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /.(svg|otf|woff|woff2|ttf|otf|png|jpg|gif)$/,
use: ['file-loader'],
}
]
}
}
what all this means?
demo time

More Related Content

What's hot

[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
Christopher Schmitt
 
AngularJS for Legacy Apps
AngularJS for Legacy AppsAngularJS for Legacy Apps
AngularJS for Legacy Apps
Peter Drinnan
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
Spike Brehm
 

What's hot (20)

Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
 
Webpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSWebpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JS
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Nuxt.js - Introduction
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - Introduction
 
Nuxt Talk
Nuxt TalkNuxt Talk
Nuxt Talk
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
 
Require js
Require jsRequire js
Require js
 
HTTP 2.0 - Web Unleashed 2015
HTTP 2.0 - Web Unleashed 2015HTTP 2.0 - Web Unleashed 2015
HTTP 2.0 - Web Unleashed 2015
 
State of jQuery June 2013 - Portland
State of jQuery June 2013 - PortlandState of jQuery June 2013 - Portland
State of jQuery June 2013 - Portland
 
Rapid Testing, Rapid Development
Rapid Testing, Rapid DevelopmentRapid Testing, Rapid Development
Rapid Testing, Rapid Development
 
AngularJS for Legacy Apps
AngularJS for Legacy AppsAngularJS for Legacy Apps
AngularJS for Legacy Apps
 
High Performance Snippets
High Performance SnippetsHigh Performance Snippets
High Performance Snippets
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Vue JS Intro
Vue JS IntroVue JS Intro
Vue JS Intro
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MIT
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 

Similar to Webpack

Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 

Similar to Webpack (20)

JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
JavaScript Perfomance
JavaScript PerfomanceJavaScript Perfomance
JavaScript Perfomance
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"
 
Building high performance web apps.
Building high performance web apps.Building high performance web apps.
Building high performance web apps.
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
Web-Performance
Web-PerformanceWeb-Performance
Web-Performance
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 

More from Sofian Hadiwijaya

More from Sofian Hadiwijaya (20)

Workshop Web3 Weekend Social Impact
Workshop Web3 Weekend Social ImpactWorkshop Web3 Weekend Social Impact
Workshop Web3 Weekend Social Impact
 
Warung Pintar Social Impact Report 2018
Warung Pintar Social Impact Report 2018Warung Pintar Social Impact Report 2018
Warung Pintar Social Impact Report 2018
 
Agile and Scrum 101
Agile and Scrum 101Agile and Scrum 101
Agile and Scrum 101
 
Execute Idea
Execute Idea Execute Idea
Execute Idea
 
Product market fit and Scale
Product market fit and ScaleProduct market fit and Scale
Product market fit and Scale
 
Entrepreneur Story
Entrepreneur StoryEntrepreneur Story
Entrepreneur Story
 
Pathway became data scientist
Pathway became data scientistPathway became data scientist
Pathway became data scientist
 
Keynote Speaker PyConID 2018
Keynote Speaker PyConID 2018Keynote Speaker PyConID 2018
Keynote Speaker PyConID 2018
 
Building Startups
Building StartupsBuilding Startups
Building Startups
 
Big data and digital marketing
Big data  and digital marketingBig data  and digital marketing
Big data and digital marketing
 
Data Driven Organization
Data Driven OrganizationData Driven Organization
Data Driven Organization
 
Data Driven Company
Data Driven CompanyData Driven Company
Data Driven Company
 
serverless web application
serverless web applicationserverless web application
serverless web application
 
Startup 101
Startup 101Startup 101
Startup 101
 
IoT and AI for Retail Industry
IoT and AI for Retail IndustryIoT and AI for Retail Industry
IoT and AI for Retail Industry
 
Growth in Startup
Growth in StartupGrowth in Startup
Growth in Startup
 
Technology Industry
Technology Industry Technology Industry
Technology Industry
 
What you can get with data
What you can get with dataWhat you can get with data
What you can get with data
 
DeepLearning with Neon
DeepLearning with NeonDeepLearning with Neon
DeepLearning with Neon
 
How BigData Affects Business
How BigData Affects BusinessHow BigData Affects Business
How BigData Affects Business
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Webpack