SlideShare a Scribd company logo
1 of 18
- Anjali Chawla
SDE-I, Expedia
“Every static asset should be able to be a module”
2 of 18
Not just js; css, images, fonts, … all are modules
By the end of the presentation
3 of 18
• What is webpack
• Why should I use web pack
• How do I use webpack
• Features
4 of 18
What is webpack?
• Webpack is a module bundler. It takes modules with dependencies
and generates static assets representing those modules.
• You can use webpack for both your client side JS files as well as your
server side node JS files.
Image source: https://webpack.github.io/docs
What does webpack do
5 of 18
• Manage dependencies
• require
• import (e.g. CommonJS, AMD, ES6, etc.)
• Build tasks - convert and preprocess
• Minify
• Combine
• Sass / less conversion
• Babel transpile
• It combines the build system and module bundling, i.e. instead of
building sass and optimizing images in one part of project, and then
combining the script files in another, it combines everything in the
module itself
What does webpack do
6 of 18
Wraps everything that is a part of the module in the module itself, and creates a bundle of it.
• Code Splitting : Split the dependency tree into chunks and load on
demand
• Maintain the dependency tree
• Create chunks of the modules and load them from webpack runtime
environment
• Reduce initial loading time
• Reduce the number of HTTP requests / for HTTP 2.0 use plugins to reduce the
chunk size to optimize it for caching
• Optimize the combined file so as to reduce the load time, while ensuring
avoiding of code redundancy
7 of 18
Why should I use webpack – The Plus Factor
Code Splitting
8 of 18
• It’s the idea that you define, in your code, “split points”: areas of your
code that could be easily split off into a separate file and then load
on-demand.
• Syntax:
// This is a split point
require.ensure([], () => { //use require for AMD
// All the code in here, and everything that is imported will be in a separate file
const library = require('some-big-library');
$('foo').click(() => library.doSomething());
}, <‘name of the chunk’>);
Code Splitting
9 of 18
• A split point creates a chunk for the dependencies.
• Chunk is automatically checked for repeatition of modules and split
accordingly.
• A chunk is loaded at runtime as jsonp and is loaded only once.
• This will remove all modules in the vendor chunk from the app chunk.
The bundle.js will now contain just your app code, without any of its
dependencies. These are in vendor.bundle.js.
var webpack = require("webpack");
module.exports = { entry: {
app: "./app.js",
vendor: ["jquery", "underscore", ...], },
output: { filename: "bundle.js" },
plugins: [
new webpack.optimize.CommonsChunkPlugin(/*chunkName=*/”vendor", /* filename=*/ "vendor.bundle.js”
) ] };
Profiling
10 of 18
Creating json file
• webpack --profile --json > stats.json
Tools to analyze profile
• http://webpack.github.io/analyse/
• http://chrisbateman.github.io/webpack-visualizer/
Multiple entry points
Understanding entry point - Webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
path: './builds',
filename: 'bundle.js'
}
};
$ = require(jquery);
…
Reads entry point and
load the dependencies
./src/index.js
node_modules Project modules
1
./builds/bundle.js
Bundles module
into a single file
2
11 of 18
Multiple entry points
12 of 18
• It will build multiple bundles at once. Additional chunks can be shared
between these entry chunks and modules are only built once.
• Every entry chunk contains the webpack runtime.
{
entry: {
a: "./a",
b: "./b",
c: ["./c", "./d"]
},
output: {
path: path.join( dirname, "dist"),
filename: "[name].entry.js"
}
}
Loaders
13 of 18
• Functions (running in node.js) that take the source of a resource file
as the parameter and return the new source.
• Loaders can be chained and the final loader is expected to return
JavaScript. They are applied right to left.
• You can write your custom loaders in node.js compatible JavaScript
{
module: {
loaders: [
{ test: /.jade$/, loader: "jade" }, // => "jade" loader is used for ".jade" files
{ test: /.css$/, loader: "style!css" }, // => "style" and "css" loader is used for ".css" files
// Alternative syntax: { test: /.css$/, loaders: ["style", "css"] },
]
}
}
Plugin System
14 of 18
• Plugins differ from loaders in the sense that instead of only executing
on a certain set of files, and being more of a “pipe”, they execute
on all files and perform more advanced actions, that aren’t
necessarily related to transformations.
• Example, CommonChunksPlugin: Analyzes your chunks for recurring
dependencies, and extracts them somewhere else. It can be a
completely separate file (like vendor.js) or it can be your main file.
15 of 18
Hot Module Replacement
• HMR is a way of exchanging modules in a running application (and
adding/removing modules). Updating changed modules without a full page
reload.
• app code asks HMR runtime to check for updates in the manifest files created by
webpack compiler.
• If an update exists, it is applied and only that part of the application is reloaded /
updated.
• Every module has to enable HMR, explicitly
var requestHandler = require("./handler.js"); var server = require("http").createServer();
server.on("request", requestHandler); server.listen(8080);
if(module.hot) {// check if HMR is enabled
module.hot.accept("./handler.js", function() {{ // accept update of dependency
server.removeListener("request", requestHandler); // replace request handler of server
requestHandler = require("./handler.js");
server.on("request", requestHandler); });
}
Extras
16 of 18
• We have pre and post loaders (e.g. for jsLint)
• Integrating webpack with gulp / grunt
var gulp = require('gulp');
var webpack = require('webpack-stream');
gulp.task('default', function(callback) {
return gulp.src('src/entry.js')
.pipe(webpack())
.pipe(gulp.dest('dist/'));
});
module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-webpack");
grunt.initConfig({
webpack: {
options: { // configuration for all builds },
build: { // configuration for this build }
},
};
Getting started
17 of 18
• Required: node, npm
$ npm install webpack –g
webpack // for building once for development
webpack -p // for building once for production (minification)
webpack --watch // for continuous incremental build in development (fast!)
webpack -d // to include source maps
References
• Documentation: http://webpack.github.io/docs/
• Loaders: http://webpack.github.io/docs/list-of-loaders.html
• Plugins: http://webpack.github.io/docs/list-of-plugins.html
• https://blog.madewithlove.be/post/webpack-your-bags/
18 of 18

More Related Content

Similar to webpack introductionNotice Demystifyingf

Web Components v1
Web Components v1Web Components v1
Web Components v1Mike Wilcox
 
Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with WebpackJake Peyser
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageAndrii Lundiak
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done RightMariusz Nowak
 
Social Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedSocial Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedClaudio Procida
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - WebpackRazvan Rosu
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS MeetupLINAGORA
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
Webpack presentation
Webpack presentationWebpack presentation
Webpack presentationRAHUL SHARMA
 
Building a production ready meteor app
Building a production ready meteor appBuilding a production ready meteor app
Building a production ready meteor appRitik Malhotra
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orgAgelos Pikoulas
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureColin Mackay
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Docker based Architecture by Denys Serdiuk
Docker based Architecture by Denys SerdiukDocker based Architecture by Denys Serdiuk
Docker based Architecture by Denys SerdiukLohika_Odessa_TechTalks
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample ChapterSyed Shahul
 

Similar to webpack introductionNotice Demystifyingf (20)

Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with Webpack
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm package
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
Social Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedSocial Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes Demystified
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
JS Module Server
JS Module ServerJS Module Server
JS Module Server
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Webpack presentation
Webpack presentationWebpack presentation
Webpack presentation
 
Building a production ready meteor app
Building a production ready meteor appBuilding a production ready meteor app
Building a production ready meteor app
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Docker based Architecture by Denys Serdiuk
Docker based Architecture by Denys SerdiukDocker based Architecture by Denys Serdiuk
Docker based Architecture by Denys Serdiuk
 
JavaScript Module Loaders
JavaScript Module LoadersJavaScript Module Loaders
JavaScript Module Loaders
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample Chapter
 

More from MrVMNair

Chapter_01_Introduction Two differen.ppt
Chapter_01_Introduction Two differen.pptChapter_01_Introduction Two differen.ppt
Chapter_01_Introduction Two differen.pptMrVMNair
 
DIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdg
DIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdgDIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdg
DIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdgMrVMNair
 
Lecture05.pptx
Lecture05.pptxLecture05.pptx
Lecture05.pptxMrVMNair
 
Event Loop Node js.pptx
Event Loop Node js.pptxEvent Loop Node js.pptx
Event Loop Node js.pptxMrVMNair
 
EN Childhood Anxiety Disorder by Slidesgo.pptx
EN Childhood Anxiety Disorder by Slidesgo.pptxEN Childhood Anxiety Disorder by Slidesgo.pptx
EN Childhood Anxiety Disorder by Slidesgo.pptxMrVMNair
 
15998595.ppt
15998595.ppt15998595.ppt
15998595.pptMrVMNair
 
6.3 c-Functions.ppt
6.3 c-Functions.ppt6.3 c-Functions.ppt
6.3 c-Functions.pptMrVMNair
 
Chapter 1_NG_2020.ppt
Chapter 1_NG_2020.pptChapter 1_NG_2020.ppt
Chapter 1_NG_2020.pptMrVMNair
 

More from MrVMNair (8)

Chapter_01_Introduction Two differen.ppt
Chapter_01_Introduction Two differen.pptChapter_01_Introduction Two differen.ppt
Chapter_01_Introduction Two differen.ppt
 
DIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdg
DIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdgDIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdg
DIPsadasdasfsdfsdfdfasdfsdfsdgsdgdsfgdfgfdg
 
Lecture05.pptx
Lecture05.pptxLecture05.pptx
Lecture05.pptx
 
Event Loop Node js.pptx
Event Loop Node js.pptxEvent Loop Node js.pptx
Event Loop Node js.pptx
 
EN Childhood Anxiety Disorder by Slidesgo.pptx
EN Childhood Anxiety Disorder by Slidesgo.pptxEN Childhood Anxiety Disorder by Slidesgo.pptx
EN Childhood Anxiety Disorder by Slidesgo.pptx
 
15998595.ppt
15998595.ppt15998595.ppt
15998595.ppt
 
6.3 c-Functions.ppt
6.3 c-Functions.ppt6.3 c-Functions.ppt
6.3 c-Functions.ppt
 
Chapter 1_NG_2020.ppt
Chapter 1_NG_2020.pptChapter 1_NG_2020.ppt
Chapter 1_NG_2020.ppt
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 

webpack introductionNotice Demystifyingf

  • 2. “Every static asset should be able to be a module” 2 of 18 Not just js; css, images, fonts, … all are modules
  • 3. By the end of the presentation 3 of 18 • What is webpack • Why should I use web pack • How do I use webpack • Features
  • 4. 4 of 18 What is webpack? • Webpack is a module bundler. It takes modules with dependencies and generates static assets representing those modules. • You can use webpack for both your client side JS files as well as your server side node JS files. Image source: https://webpack.github.io/docs
  • 5. What does webpack do 5 of 18 • Manage dependencies • require • import (e.g. CommonJS, AMD, ES6, etc.) • Build tasks - convert and preprocess • Minify • Combine • Sass / less conversion • Babel transpile • It combines the build system and module bundling, i.e. instead of building sass and optimizing images in one part of project, and then combining the script files in another, it combines everything in the module itself
  • 6. What does webpack do 6 of 18 Wraps everything that is a part of the module in the module itself, and creates a bundle of it.
  • 7. • Code Splitting : Split the dependency tree into chunks and load on demand • Maintain the dependency tree • Create chunks of the modules and load them from webpack runtime environment • Reduce initial loading time • Reduce the number of HTTP requests / for HTTP 2.0 use plugins to reduce the chunk size to optimize it for caching • Optimize the combined file so as to reduce the load time, while ensuring avoiding of code redundancy 7 of 18 Why should I use webpack – The Plus Factor
  • 8. Code Splitting 8 of 18 • It’s the idea that you define, in your code, “split points”: areas of your code that could be easily split off into a separate file and then load on-demand. • Syntax: // This is a split point require.ensure([], () => { //use require for AMD // All the code in here, and everything that is imported will be in a separate file const library = require('some-big-library'); $('foo').click(() => library.doSomething()); }, <‘name of the chunk’>);
  • 9. Code Splitting 9 of 18 • A split point creates a chunk for the dependencies. • Chunk is automatically checked for repeatition of modules and split accordingly. • A chunk is loaded at runtime as jsonp and is loaded only once. • This will remove all modules in the vendor chunk from the app chunk. The bundle.js will now contain just your app code, without any of its dependencies. These are in vendor.bundle.js. var webpack = require("webpack"); module.exports = { entry: { app: "./app.js", vendor: ["jquery", "underscore", ...], }, output: { filename: "bundle.js" }, plugins: [ new webpack.optimize.CommonsChunkPlugin(/*chunkName=*/”vendor", /* filename=*/ "vendor.bundle.js” ) ] };
  • 10. Profiling 10 of 18 Creating json file • webpack --profile --json > stats.json Tools to analyze profile • http://webpack.github.io/analyse/ • http://chrisbateman.github.io/webpack-visualizer/
  • 11. Multiple entry points Understanding entry point - Webpack.config.js module.exports = { entry: './src/index.js', output: { path: './builds', filename: 'bundle.js' } }; $ = require(jquery); … Reads entry point and load the dependencies ./src/index.js node_modules Project modules 1 ./builds/bundle.js Bundles module into a single file 2 11 of 18
  • 12. Multiple entry points 12 of 18 • It will build multiple bundles at once. Additional chunks can be shared between these entry chunks and modules are only built once. • Every entry chunk contains the webpack runtime. { entry: { a: "./a", b: "./b", c: ["./c", "./d"] }, output: { path: path.join( dirname, "dist"), filename: "[name].entry.js" } }
  • 13. Loaders 13 of 18 • Functions (running in node.js) that take the source of a resource file as the parameter and return the new source. • Loaders can be chained and the final loader is expected to return JavaScript. They are applied right to left. • You can write your custom loaders in node.js compatible JavaScript { module: { loaders: [ { test: /.jade$/, loader: "jade" }, // => "jade" loader is used for ".jade" files { test: /.css$/, loader: "style!css" }, // => "style" and "css" loader is used for ".css" files // Alternative syntax: { test: /.css$/, loaders: ["style", "css"] }, ] } }
  • 14. Plugin System 14 of 18 • Plugins differ from loaders in the sense that instead of only executing on a certain set of files, and being more of a “pipe”, they execute on all files and perform more advanced actions, that aren’t necessarily related to transformations. • Example, CommonChunksPlugin: Analyzes your chunks for recurring dependencies, and extracts them somewhere else. It can be a completely separate file (like vendor.js) or it can be your main file.
  • 15. 15 of 18 Hot Module Replacement • HMR is a way of exchanging modules in a running application (and adding/removing modules). Updating changed modules without a full page reload. • app code asks HMR runtime to check for updates in the manifest files created by webpack compiler. • If an update exists, it is applied and only that part of the application is reloaded / updated. • Every module has to enable HMR, explicitly var requestHandler = require("./handler.js"); var server = require("http").createServer(); server.on("request", requestHandler); server.listen(8080); if(module.hot) {// check if HMR is enabled module.hot.accept("./handler.js", function() {{ // accept update of dependency server.removeListener("request", requestHandler); // replace request handler of server requestHandler = require("./handler.js"); server.on("request", requestHandler); }); }
  • 16. Extras 16 of 18 • We have pre and post loaders (e.g. for jsLint) • Integrating webpack with gulp / grunt var gulp = require('gulp'); var webpack = require('webpack-stream'); gulp.task('default', function(callback) { return gulp.src('src/entry.js') .pipe(webpack()) .pipe(gulp.dest('dist/')); }); module.exports = function(grunt) { grunt.loadNpmTasks("grunt-webpack"); grunt.initConfig({ webpack: { options: { // configuration for all builds }, build: { // configuration for this build } }, };
  • 17. Getting started 17 of 18 • Required: node, npm $ npm install webpack –g webpack // for building once for development webpack -p // for building once for production (minification) webpack --watch // for continuous incremental build in development (fast!) webpack -d // to include source maps
  • 18. References • Documentation: http://webpack.github.io/docs/ • Loaders: http://webpack.github.io/docs/list-of-loaders.html • Plugins: http://webpack.github.io/docs/list-of-plugins.html • https://blog.madewithlove.be/post/webpack-your-bags/ 18 of 18