SlideShare a Scribd company logo
3
Most read
8
Most read
17
Most read
An Intro into
webpack
Mohanapriya.R
Software Engineer,
Squash Apps.
1
● What is webpack?
● Understanding the Core concepts
● Configure webpack
● Working Examples
● Why is webpack necessary?
OUTLINE
2
What is webpack?
● A Module Bundler.
● A Task Runner.
3
Understanding Core Concepts
● Entry
● Output
● Loaders
● Plugin
● Mode
4
Entry Point
● Defines a module for webpack to
begin with.
● Generates Dependency graph.
● Figure out Entry point’s dependencies.
● By default, ./src/index.js
module.exports = {
entry: './path/to/my/entry/file.js'
};
webpack.config.js
5
Output
webpack.config.js
● Defines where to emit the created bundles.
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
}
};
6
Loaders
● Webpack Understands JS & JSON files.
● Loaders allow webpack to process other
files.
● Two props:
○ Test - Identifies file to be transformed.
○ Use - Indicates loaders to be used.
const path = require('path');
module.exports = {
output: {
filename: 'my-first-webpack.bundle.js'
},
module: {
rules: [{
test: /.txt$/,
use: 'raw-loader'
}]
}
};
webpack.config.js
7
Plugin
● Bundle optimization
● Asset Management
● Injection of env variables.
● Customizable through options.
○ require() a plugin to use it.
○ Create an instance of the plugin with
new operator
const HtmlWebpackPlugin =
require('html-webpack-plugin');
//installed via npm
const webpack = require('webpack');
//to access built-in plugins
module.exports = {
module: {
rules: [
{ test: /.txt$/, use: 'raw-loader' }
]
},
plugins: [
new HtmlWebpackPlugin({template:
'./src/index.html'})
]
};
webpack.config.js
8
Mode
● Development
● Production
● None
● By default, mode: production.
module.exports = {
mode: 'production'
};
webpack.config.js
9
Configure Webpack
● webpack.config.js
● Webpack is configuration driven & Highly configurable.
● Install node.js & verify npm is working.
● mkdir <dirname> && cd <dirname>
● npm init -y
● npm i -D webpack webpack-cli
● code .
● Add build in package.json
10
● Bundling JS
● Bundling HTML
● Bundling Images
● Bundling Scss
Working Examples
11
● Create src folder
● Add js files under src
Bundling JS
npm run build
● Generates Dist
folder
● Generates main.js
12
● Create index.html
● Add script file to src
Bundling HTML
http-server -o Syntax error
Because, Webpack
has ZERO
configurations..!
● Configure Webpack
● Create webpack.config.js
● npm i -D html-webpack-plugin
html-loader
● Initialize the loader in webpack
config file.
13
const HtmlWebpackPlugin = require("html-
webpack-plugin");
module.exports = {
module: {
rules: [{
test: /.html$/,
use: [{
loader: "html-loader",
options: { minimize: true}
}]
},]
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "./index.html"
}),
]}
Bundling HTML contd...
npm run build Generates index.html
14
● Install webpack server
○ npm i -D webpack-dev-server
● Add scripts to package.json
○ “start:dev” : “webpack-dev-server”
● npm run start:dev
Install Webpack server
15
● Create folder => images.
● Add image in to the folder.
● Insert image in img tag of
index.html
Bundling Images
npm run build Nothing happens!
● npm i -D file-loader
● webpack.config.js
{
test: /.(png|svg|jpg|gif)$/,
use: [ 'file-loader' ]
}
npm run build Creates images in dist
16
● npm i -D node-sass style-loader css-loader
sass-loader mini-css-extract-plugin
● Create folder => styles
● Include main.scss file.
● Import the file.
● In webpack.config.js
{
test: /.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}
Bundling SCSS
npm run build
Scss variables found in js
under dist folder.
17
Why is webpack necessary?
● Cares about Performance & Load time
● Provides best possible experience
● Improved readability & maintainability of the project.
● Provides features like,
○ Hot Module Replacement
○ Lazy Loading
○ Bundle splitting
○ Hashing
○ Source maps
● Integral part of JS Ecosystem.
18
Any Queries..?
19
Thank you..!
20

More Related Content

What's hot (20)

PDF
webpack 101 slides
mattysmith
 
PPTX
Express js
Manav Prasad
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
Getting started with Next.js
Gökhan Sarı
 
PDF
Introduction to React JS
Bethmi Gunasekara
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PDF
Vue.js
Jadson Santos
 
PDF
Angular
Lilia Sfaxi
 
PDF
Spring Framework - AOP
Dzmitry Naskou
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
Introduction to NodeJS
Cere Labs Pvt. Ltd
 
PDF
Spring Boot
Jaran Flaath
 
PPTX
React js programming concept
Tariqul islam
 
PDF
Spring boot introduction
Rasheed Waraich
 
PDF
Introduction to ReactJS
Hoang Long
 
PDF
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
Edureka!
 
PPTX
Introduction to react and redux
Cuong Ho
 
webpack 101 slides
mattysmith
 
Express js
Manav Prasad
 
ReactJS presentation
Thanh Tuong
 
Getting started with Next.js
Gökhan Sarı
 
Introduction to React JS
Bethmi Gunasekara
 
Introduction Node.js
Erik van Appeldoorn
 
Angular
Lilia Sfaxi
 
Spring Framework - AOP
Dzmitry Naskou
 
Introduction to spring boot
Santosh Kumar Kar
 
Introduction to Redux
Ignacio Martín
 
Introduction to NodeJS
Cere Labs Pvt. Ltd
 
Spring Boot
Jaran Flaath
 
React js programming concept
Tariqul islam
 
Spring boot introduction
Rasheed Waraich
 
Introduction to ReactJS
Hoang Long
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
Edureka!
 
Introduction to react and redux
Cuong Ho
 

Similar to An Intro into webpack (20)

PPTX
Introduction to Webpack 5.0 Presentation
Knoldus Inc.
 
PDF
Webpack presentation
RAHUL SHARMA
 
PPTX
Introduction to Webpack : A Beginners Giude
Srijan Singh
 
PDF
Webpack DevTalk
Alessandro Bellini
 
PPTX
Improving build solutions dependency management with webpack
NodeXperts
 
PDF
Front-end build tools - Webpack
Razvan Rosu
 
PDF
Bundle your modules with Webpack
Jake Peyser
 
PPTX
WEBPACK
home
 
PDF
Installing Webpack with React JS from Scratch.pdf
Sufalam Technologies
 
PPT
Webpack
Mallikarjuna G D
 
PPTX
webpack introductionNotice Demystifyingf
MrVMNair
 
PPTX
Lecture: Webpack 4
Sergei Iastrebov
 
PDF
Introduction to Webpack - Ordina JWorks - CC JS & Web
JWORKS powered by Ordina
 
PPTX
Packing for the Web with Webpack
Thiago Temple
 
PPTX
Webpack and Web Performance Optimization
Chen-Tien Tsai
 
PDF
Keeping the frontend under control with Symfony and Webpack
Ignacio Martín
 
PDF
Create a module bundler from scratch
Sing Ming Chen
 
PPTX
002. Working with Webpack
Binh Quan Duc
 
PDF
Webpack 살펴보기
Sangwon Lee
 
PDF
Webpack Tutorial, Uppsala JS
Emil Öberg
 
Introduction to Webpack 5.0 Presentation
Knoldus Inc.
 
Webpack presentation
RAHUL SHARMA
 
Introduction to Webpack : A Beginners Giude
Srijan Singh
 
Webpack DevTalk
Alessandro Bellini
 
Improving build solutions dependency management with webpack
NodeXperts
 
Front-end build tools - Webpack
Razvan Rosu
 
Bundle your modules with Webpack
Jake Peyser
 
WEBPACK
home
 
Installing Webpack with React JS from Scratch.pdf
Sufalam Technologies
 
webpack introductionNotice Demystifyingf
MrVMNair
 
Lecture: Webpack 4
Sergei Iastrebov
 
Introduction to Webpack - Ordina JWorks - CC JS & Web
JWORKS powered by Ordina
 
Packing for the Web with Webpack
Thiago Temple
 
Webpack and Web Performance Optimization
Chen-Tien Tsai
 
Keeping the frontend under control with Symfony and Webpack
Ignacio Martín
 
Create a module bundler from scratch
Sing Ming Chen
 
002. Working with Webpack
Binh Quan Duc
 
Webpack 살펴보기
Sangwon Lee
 
Webpack Tutorial, Uppsala JS
Emil Öberg
 
Ad

More from Squash Apps Pvt Ltd (15)

PPTX
The Critical role of Copyright
Squash Apps Pvt Ltd
 
PPTX
Please review and merge
Squash Apps Pvt Ltd
 
PPTX
Angular Lifecycle Hooks
Squash Apps Pvt Ltd
 
PPTX
Next Generation of Javascript
Squash Apps Pvt Ltd
 
PPTX
Hybrid app development frameworks
Squash Apps Pvt Ltd
 
PPTX
API Gateway with legend lambada
Squash Apps Pvt Ltd
 
PPTX
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
PPTX
Lets vue(view) Vuex from the Top Vue(View)
Squash Apps Pvt Ltd
 
PPTX
An Overview on Nuxt.js
Squash Apps Pvt Ltd
 
PPTX
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
PPTX
AWS Jungle - Lambda
Squash Apps Pvt Ltd
 
PPTX
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd
 
PPTX
Basics of NGINX
Squash Apps Pvt Ltd
 
ODP
Basics of VueJS
Squash Apps Pvt Ltd
 
The Critical role of Copyright
Squash Apps Pvt Ltd
 
Please review and merge
Squash Apps Pvt Ltd
 
Angular Lifecycle Hooks
Squash Apps Pvt Ltd
 
Next Generation of Javascript
Squash Apps Pvt Ltd
 
Hybrid app development frameworks
Squash Apps Pvt Ltd
 
API Gateway with legend lambada
Squash Apps Pvt Ltd
 
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
Lets vue(view) Vuex from the Top Vue(View)
Squash Apps Pvt Ltd
 
An Overview on Nuxt.js
Squash Apps Pvt Ltd
 
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
AWS Jungle - Lambda
Squash Apps Pvt Ltd
 
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd
 
Basics of NGINX
Squash Apps Pvt Ltd
 
Basics of VueJS
Squash Apps Pvt Ltd
 
Ad

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 

An Intro into webpack

  • 2. ● What is webpack? ● Understanding the Core concepts ● Configure webpack ● Working Examples ● Why is webpack necessary? OUTLINE 2
  • 3. What is webpack? ● A Module Bundler. ● A Task Runner. 3
  • 4. Understanding Core Concepts ● Entry ● Output ● Loaders ● Plugin ● Mode 4
  • 5. Entry Point ● Defines a module for webpack to begin with. ● Generates Dependency graph. ● Figure out Entry point’s dependencies. ● By default, ./src/index.js module.exports = { entry: './path/to/my/entry/file.js' }; webpack.config.js 5
  • 6. Output webpack.config.js ● Defines where to emit the created bundles. const path = require('path'); module.exports = { entry: './path/to/my/entry/file.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'my-first-webpack.bundle.js' } }; 6
  • 7. Loaders ● Webpack Understands JS & JSON files. ● Loaders allow webpack to process other files. ● Two props: ○ Test - Identifies file to be transformed. ○ Use - Indicates loaders to be used. const path = require('path'); module.exports = { output: { filename: 'my-first-webpack.bundle.js' }, module: { rules: [{ test: /.txt$/, use: 'raw-loader' }] } }; webpack.config.js 7
  • 8. Plugin ● Bundle optimization ● Asset Management ● Injection of env variables. ● Customizable through options. ○ require() a plugin to use it. ○ Create an instance of the plugin with new operator const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm const webpack = require('webpack'); //to access built-in plugins module.exports = { module: { rules: [ { test: /.txt$/, use: 'raw-loader' } ] }, plugins: [ new HtmlWebpackPlugin({template: './src/index.html'}) ] }; webpack.config.js 8
  • 9. Mode ● Development ● Production ● None ● By default, mode: production. module.exports = { mode: 'production' }; webpack.config.js 9
  • 10. Configure Webpack ● webpack.config.js ● Webpack is configuration driven & Highly configurable. ● Install node.js & verify npm is working. ● mkdir <dirname> && cd <dirname> ● npm init -y ● npm i -D webpack webpack-cli ● code . ● Add build in package.json 10
  • 11. ● Bundling JS ● Bundling HTML ● Bundling Images ● Bundling Scss Working Examples 11
  • 12. ● Create src folder ● Add js files under src Bundling JS npm run build ● Generates Dist folder ● Generates main.js 12
  • 13. ● Create index.html ● Add script file to src Bundling HTML http-server -o Syntax error Because, Webpack has ZERO configurations..! ● Configure Webpack ● Create webpack.config.js ● npm i -D html-webpack-plugin html-loader ● Initialize the loader in webpack config file. 13
  • 14. const HtmlWebpackPlugin = require("html- webpack-plugin"); module.exports = { module: { rules: [{ test: /.html$/, use: [{ loader: "html-loader", options: { minimize: true} }] },] }, plugins: [ new HtmlWebpackPlugin({ template: "./src/index.html", filename: "./index.html" }), ]} Bundling HTML contd... npm run build Generates index.html 14
  • 15. ● Install webpack server ○ npm i -D webpack-dev-server ● Add scripts to package.json ○ “start:dev” : “webpack-dev-server” ● npm run start:dev Install Webpack server 15
  • 16. ● Create folder => images. ● Add image in to the folder. ● Insert image in img tag of index.html Bundling Images npm run build Nothing happens! ● npm i -D file-loader ● webpack.config.js { test: /.(png|svg|jpg|gif)$/, use: [ 'file-loader' ] } npm run build Creates images in dist 16
  • 17. ● npm i -D node-sass style-loader css-loader sass-loader mini-css-extract-plugin ● Create folder => styles ● Include main.scss file. ● Import the file. ● In webpack.config.js { test: /.scss$/, use: [ 'style-loader', 'css-loader', 'sass-loader' ] } Bundling SCSS npm run build Scss variables found in js under dist folder. 17
  • 18. Why is webpack necessary? ● Cares about Performance & Load time ● Provides best possible experience ● Improved readability & maintainability of the project. ● Provides features like, ○ Hot Module Replacement ○ Lazy Loading ○ Bundle splitting ○ Hashing ○ Source maps ● Integral part of JS Ecosystem. 18