SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
The new rock star of build tools
Webpack
Andrii Vandakurov
Hi, I’m Andrii Vandakurov
Senior Frontend developer at
We create cool things
Andrii Vandakurov
What is the base of every project ?
Assets !
Andrii Vandakurov
Of course
you can
manage this
by yourself
Andrii Vandakurov
But why ? There are lot of tools
that can help you !
Andrii Vandakurov
Diving into webpack
Andrii Vandakurov
Webpack suits well for
really big projects
because of it’s flexibility ( support for AMD, CommonJs, UMD modules ) Andrii Vandakurov
Installation and use
Andrii Vandakurov
npm install webpack
Could be runned from CLI:
Install as npm package:
webpack <entry.js> <result.js>
or as Node.js package from script:
var webpack = require("webpack");
webpack({ //configuration... }, function(err, stats) { … });
Webpack Config
you don’t need to write pure JSON
into the configuration. Use any
JavaScript you want. It’s just a
node.js (CommonJs) module…
Andrii VandakurovAndrii Vandakurov
What is CommonJs module ?
Each file has
isolated scope
Andrii Vandakurov
* so we need to module.export
everything we want to be public
module.export = 2;
File1.js
var two = require(“./File1.js”);
console.log(2 + two); // 4
File2.js
Code splitting
Andrii Vandakurov
All in one request
+ one request, less latency
- get all bunch
Request per module
+ get only what you need
- many requests => much overhead
- requests latency
Code splitting
Andrii Vandakurov
Modules to chunks
+ get only what you need
+ less requests, less overhead
But let check
how webpack
can help us with
simple example
project
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="module1.css">
<link rel="stylesheet" href="module2.css">
<link rel="stylesheet" href="module3.css">
</head>
<body>
Hello world
<script src="module1.js"></script>
<script src="module2.js"></script>
<script src="module3.js"></script>
</body>
</html>
Andrii Vandakurov
module.exports = {
entry: {
app: [
"./app/js/module1",
"./app/js/module2"
]
},
output: {
path: "./public/js/",
filename: "bundle.js"
}
};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="module1.css">
<link rel="stylesheet" href="module2.css">
<link rel="stylesheet" href="module3.css">
</head>
<body>
Hello world
<script src="bundle.js"></script>
<script src="module3.js"></script>
</body>
</html>
Andrii Vandakurov
webpack.config.js
What about
other files??
.css .png .jsx .woff .svg .
json .styl .eot .html .scss .
jpeg .jade ...
Andrii VandakurovAndrii Vandakurov
Loaders
Loaders allow you to preprocess files
as you require() or “load” them.
Loaders are kind of like “tasks” are in
other build tools
code -> loaders -> plugins -> output
Andrii Vandakurov
Continue with styles
module.exports = {
...
module: {
loaders: [
{ test: /.scss$/, loader: "style!css!autoprefixer!sass" }
]}
};
npm install style-loader css-loader sass-loader autoprefixer-loader
Andrii Vandakurov
require(“style!css!autoprefixer!sass!./mystyles.scss”);
Andrii Vandakurov
Optimize workflow with
images !
npm install url-loader
require("url?limit=10000!./file.png");
Insert image in the bundle (via Base64) if it’s
smaller than 10kb
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
Hello world
<script src="bundle.js"></script>
<script src="module3.js"></script>
</body>
</html>
Modularity
module1.js
require("module1.scss");
console.log("module1 js code");
module3.js
require("module3.scss");
console.log("module3 js code");
Andrii Vandakurov
module.exports = {
...
entry: {
app: "./app/js/module1"
},
...
};
document
.querySelector(".btn-require-module")
.addEventListener("click", function(){
require.ensure(["./module3"], function(require){
var module3 = require("./module3");
}, "module3")
})
Andrii Vandakurov
Code splitting
webpack.config.js module1.js
Webpack
loaders
60+
ES6
ESLint
JSCS
Mocha
Karma React
Riot
Polymer
Vue
Plugins
Andrii Vandakurov
code -> loaders -> plugins -> output
CommonChunkPlugin
Andrii Vandakurov
smart common chunks extraction
Chunk1.js
Chunk2.js
Chunk3.js
common.chunk.js
var webpack = require("webpack");
module.exports = {
...
plugins: [
new webpack.optimize.CommonsChunkPlugin("commons", "commons.js")
]
};
require(“./module4”)
console.log(“This is module 1”);
Andrii Vandakurov
module1.js
require(“./module4”)
console.log(“This is module 3”);
module3.js
CommonChunkPlugin
var webpack = require("webpack");
module.exports = {
…
plugins: [
new webpack.DefinePlugin({
ENV: JSON.stringify("dev")
})
]
};
Somewhere in your code:
if(ENV === "dev"){
console.log("Its dev");
}else{
console.log("Its NOT dev");
}
Andrii Vandakurov
DefinePlugin
injects free variables into your code without using global scope
webpack.config.js
var webpack = require("webpack");
module.exports = {
…
plugins: [
new webpack.ProvidePlugin({
"React": "react"
})
]
};
Somewhere in your code:
module.export = React.createClass({
...
})
Andrii Vandakurov
ProvidePlugin
Prevent from ‘require’ module in each file
ExtractTextPlugin
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
…
plugins: [
new ExtractTextPlugin("module1.scss", "[name].[contenthash].css")
]
};
Andrii Vandakurov
extract styles from bundle
var webpack = require("webpack");
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = { …
plugins: [
new HtmlWebpackPlugin({
title: "Webpack",
"filename": "../index.html",
"inject": true,
"template": "app/index.html",
"chunks": ["commons", "module1"]
})
]
};
Andrii Vandakurov
Simplifies creation of
HTML files to serve
your webpack
bundles
HtmlWebpackPlugin
DevServer
Andrii Vandakurov
Express.js (NodeJs) server which has a little
runtime which is connected to the server via
Socket.IO. The server emits information about
the compilation state to the client, which reacts
to those events.
Andrii Vandakurov
exchanges, adds, or removes modules while
an application is running without a page
reload.
Hot Module
Replacement
It’s like LiveReload for every module.
Dependencies
visualization
1. webpack --json > stats.json
2. go to http://goo.gl/b0kzNZ
3. Check your dependencies graph
Andrii VandakurovAndrii Vandakurov
QA ?
Andrii Vandakurov
Links
Andrii Vandakurov
1. Webpack official site
2. Examples
Inspired by
● Алексадр Ткаленко slides
● Alexandrine Boissière slides
Andrii Vandakurov

Contenu connexe

Tendances

React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners Varun Raj
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
Introduction to docker and docker compose
Introduction to docker and docker composeIntroduction to docker and docker compose
Introduction to docker and docker composeLalatendu Mohanty
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced RoutingLaurent Duveau
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.jsEmanuele DelBono
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjsmanojbkalla
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.jsSmile Gupta
 

Tendances (20)

Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
 
React JS part 1
React JS part 1React JS part 1
React JS part 1
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Docker
DockerDocker
Docker
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
React Hooks
React HooksReact Hooks
React Hooks
 
Vue Vuex 101
Vue Vuex 101Vue Vuex 101
Vue Vuex 101
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Docker on Docker
Docker on DockerDocker on Docker
Docker on Docker
 
Introduction to docker and docker compose
Introduction to docker and docker composeIntroduction to docker and docker compose
Introduction to docker and docker compose
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Docker basics
Docker basicsDocker basics
Docker basics
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
React hooks
React hooksReact hooks
React hooks
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.js
 

Similaire à Webpack slides

WEBPACK
WEBPACKWEBPACK
WEBPACKhome
 
Lightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with GradleLightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with GradleMario-Leander Reimer
 
Lightweight developer provisioning with gradle and seu as-code
Lightweight developer provisioning with gradle and seu as-codeLightweight developer provisioning with gradle and seu as-code
Lightweight developer provisioning with gradle and seu as-codeQAware GmbH
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackIgnacio Martín
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
Shopware PWA - a technical overview of
Shopware PWA - a technical overview ofShopware PWA - a technical overview of
Shopware PWA - a technical overview ofSander Mangel
 
Get MEAN! Node.js and the MEAN stack
Get MEAN!  Node.js and the MEAN stackGet MEAN!  Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stackNicholas McClay
 
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 GulpMatthew Davis
 
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...Alain Hippolyte
 
Hybrid app development frameworks
Hybrid app development frameworksHybrid app development frameworks
Hybrid app development frameworksSquash Apps Pvt Ltd
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - IntroductionWebStackAcademy
 
EnterJS 2015 - Continuous Integration for Frontend Code
EnterJS 2015 - Continuous Integration for Frontend CodeEnterJS 2015 - Continuous Integration for Frontend Code
EnterJS 2015 - Continuous Integration for Frontend CodeMarcel Birkner
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureIgalia
 
Node.js Crash Course
Node.js Crash CourseNode.js Crash Course
Node.js Crash CourseDavid Neal
 
Angularjs Tutorial for Beginners
Angularjs Tutorial for BeginnersAngularjs Tutorial for Beginners
Angularjs Tutorial for Beginnersrajkamaltibacademy
 
AFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreEngineor
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...tdc-globalcode
 

Similaire à Webpack slides (20)

WEBPACK
WEBPACKWEBPACK
WEBPACK
 
Lightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with GradleLightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with Gradle
 
Lightweight developer provisioning with gradle and seu as-code
Lightweight developer provisioning with gradle and seu as-codeLightweight developer provisioning with gradle and seu as-code
Lightweight developer provisioning with gradle and seu as-code
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Shopware PWA - a technical overview of
Shopware PWA - a technical overview ofShopware PWA - a technical overview of
Shopware PWA - a technical overview of
 
Get MEAN! Node.js and the MEAN stack
Get MEAN!  Node.js and the MEAN stackGet MEAN!  Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
 
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
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
 
Hybrid app development frameworks
Hybrid app development frameworksHybrid app development frameworks
Hybrid app development frameworks
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
EnterJS 2015 - Continuous Integration for Frontend Code
EnterJS 2015 - Continuous Integration for Frontend CodeEnterJS 2015 - Continuous Integration for Frontend Code
EnterJS 2015 - Continuous Integration for Frontend Code
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
 
Node.js Crash Course
Node.js Crash CourseNode.js Crash Course
Node.js Crash Course
 
Angularjs Tutorial for Beginners
Angularjs Tutorial for BeginnersAngularjs Tutorial for Beginners
Angularjs Tutorial for Beginners
 
B875.pptx
B875.pptxB875.pptx
B875.pptx
 
AFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack Encore
 
Why NodeJS
Why NodeJSWhy NodeJS
Why NodeJS
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 

Plus de Андрей Вандакуров (7)

Lviv js2017 (eleks)
Lviv js2017 (eleks)Lviv js2017 (eleks)
Lviv js2017 (eleks)
 
Rare frontend testing
Rare frontend testingRare frontend testing
Rare frontend testing
 
Opensourceman ( url for slides with animations https://goo.gl/R638tW )
Opensourceman ( url for slides with animations https://goo.gl/R638tW )Opensourceman ( url for slides with animations https://goo.gl/R638tW )
Opensourceman ( url for slides with animations https://goo.gl/R638tW )
 
Pivorak.javascript.global domination
Pivorak.javascript.global dominationPivorak.javascript.global domination
Pivorak.javascript.global domination
 
Frontend. Global domination.
Frontend. Global domination.Frontend. Global domination.
Frontend. Global domination.
 
Design and Code. Work should be fun.
Design and Code. Work should be fun.Design and Code. Work should be fun.
Design and Code. Work should be fun.
 
Kharkivjs javascript debugging. know your enemy
Kharkivjs   javascript debugging. know your enemyKharkivjs   javascript debugging. know your enemy
Kharkivjs javascript debugging. know your enemy
 

Dernier

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 

Dernier (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

Webpack slides

  • 1. The new rock star of build tools Webpack Andrii Vandakurov
  • 2. Hi, I’m Andrii Vandakurov Senior Frontend developer at We create cool things Andrii Vandakurov
  • 3. What is the base of every project ? Assets ! Andrii Vandakurov
  • 4. Of course you can manage this by yourself Andrii Vandakurov
  • 5. But why ? There are lot of tools that can help you ! Andrii Vandakurov
  • 7. Webpack suits well for really big projects because of it’s flexibility ( support for AMD, CommonJs, UMD modules ) Andrii Vandakurov
  • 8. Installation and use Andrii Vandakurov npm install webpack Could be runned from CLI: Install as npm package: webpack <entry.js> <result.js> or as Node.js package from script: var webpack = require("webpack"); webpack({ //configuration... }, function(err, stats) { … });
  • 9. Webpack Config you don’t need to write pure JSON into the configuration. Use any JavaScript you want. It’s just a node.js (CommonJs) module… Andrii VandakurovAndrii Vandakurov
  • 10. What is CommonJs module ? Each file has isolated scope Andrii Vandakurov * so we need to module.export everything we want to be public module.export = 2; File1.js var two = require(“./File1.js”); console.log(2 + two); // 4 File2.js
  • 11. Code splitting Andrii Vandakurov All in one request + one request, less latency - get all bunch Request per module + get only what you need - many requests => much overhead - requests latency
  • 12. Code splitting Andrii Vandakurov Modules to chunks + get only what you need + less requests, less overhead
  • 13. But let check how webpack can help us with simple example project <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="module1.css"> <link rel="stylesheet" href="module2.css"> <link rel="stylesheet" href="module3.css"> </head> <body> Hello world <script src="module1.js"></script> <script src="module2.js"></script> <script src="module3.js"></script> </body> </html> Andrii Vandakurov
  • 14. module.exports = { entry: { app: [ "./app/js/module1", "./app/js/module2" ] }, output: { path: "./public/js/", filename: "bundle.js" } }; <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="module1.css"> <link rel="stylesheet" href="module2.css"> <link rel="stylesheet" href="module3.css"> </head> <body> Hello world <script src="bundle.js"></script> <script src="module3.js"></script> </body> </html> Andrii Vandakurov webpack.config.js
  • 15. What about other files?? .css .png .jsx .woff .svg . json .styl .eot .html .scss . jpeg .jade ... Andrii VandakurovAndrii Vandakurov
  • 16. Loaders Loaders allow you to preprocess files as you require() or “load” them. Loaders are kind of like “tasks” are in other build tools code -> loaders -> plugins -> output Andrii Vandakurov
  • 17. Continue with styles module.exports = { ... module: { loaders: [ { test: /.scss$/, loader: "style!css!autoprefixer!sass" } ]} }; npm install style-loader css-loader sass-loader autoprefixer-loader Andrii Vandakurov require(“style!css!autoprefixer!sass!./mystyles.scss”);
  • 18. Andrii Vandakurov Optimize workflow with images ! npm install url-loader require("url?limit=10000!./file.png"); Insert image in the bundle (via Base64) if it’s smaller than 10kb
  • 19. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> Hello world <script src="bundle.js"></script> <script src="module3.js"></script> </body> </html> Modularity module1.js require("module1.scss"); console.log("module1 js code"); module3.js require("module3.scss"); console.log("module3 js code"); Andrii Vandakurov
  • 20. module.exports = { ... entry: { app: "./app/js/module1" }, ... }; document .querySelector(".btn-require-module") .addEventListener("click", function(){ require.ensure(["./module3"], function(require){ var module3 = require("./module3"); }, "module3") }) Andrii Vandakurov Code splitting webpack.config.js module1.js
  • 22. Plugins Andrii Vandakurov code -> loaders -> plugins -> output
  • 23. CommonChunkPlugin Andrii Vandakurov smart common chunks extraction Chunk1.js Chunk2.js Chunk3.js common.chunk.js
  • 24. var webpack = require("webpack"); module.exports = { ... plugins: [ new webpack.optimize.CommonsChunkPlugin("commons", "commons.js") ] }; require(“./module4”) console.log(“This is module 1”); Andrii Vandakurov module1.js require(“./module4”) console.log(“This is module 3”); module3.js CommonChunkPlugin
  • 25. var webpack = require("webpack"); module.exports = { … plugins: [ new webpack.DefinePlugin({ ENV: JSON.stringify("dev") }) ] }; Somewhere in your code: if(ENV === "dev"){ console.log("Its dev"); }else{ console.log("Its NOT dev"); } Andrii Vandakurov DefinePlugin injects free variables into your code without using global scope webpack.config.js
  • 26. var webpack = require("webpack"); module.exports = { … plugins: [ new webpack.ProvidePlugin({ "React": "react" }) ] }; Somewhere in your code: module.export = React.createClass({ ... }) Andrii Vandakurov ProvidePlugin Prevent from ‘require’ module in each file
  • 27. ExtractTextPlugin var webpack = require("webpack"); var ExtractTextPlugin = require("extract-text-webpack-plugin"); module.exports = { … plugins: [ new ExtractTextPlugin("module1.scss", "[name].[contenthash].css") ] }; Andrii Vandakurov extract styles from bundle
  • 28. var webpack = require("webpack"); var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { … plugins: [ new HtmlWebpackPlugin({ title: "Webpack", "filename": "../index.html", "inject": true, "template": "app/index.html", "chunks": ["commons", "module1"] }) ] }; Andrii Vandakurov Simplifies creation of HTML files to serve your webpack bundles HtmlWebpackPlugin
  • 29. DevServer Andrii Vandakurov Express.js (NodeJs) server which has a little runtime which is connected to the server via Socket.IO. The server emits information about the compilation state to the client, which reacts to those events.
  • 30. Andrii Vandakurov exchanges, adds, or removes modules while an application is running without a page reload. Hot Module Replacement It’s like LiveReload for every module.
  • 31. Dependencies visualization 1. webpack --json > stats.json 2. go to http://goo.gl/b0kzNZ 3. Check your dependencies graph Andrii VandakurovAndrii Vandakurov
  • 33. Links Andrii Vandakurov 1. Webpack official site 2. Examples Inspired by ● Алексадр Ткаленко slides ● Alexandrine Boissière slides Andrii Vandakurov