SlideShare ist ein Scribd-Unternehmen logo
1 von 20
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

Weitere ähnliche Inhalte

Was ist angesagt?

Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjsmanojbkalla
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react nativeDani Akash
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
State management in react applications (Statecharts)
State management in react applications (Statecharts)State management in react applications (Statecharts)
State management in react applications (Statecharts)Tomáš Drenčák
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data AccessDzmitry Naskou
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...Edureka!
 
Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring BootVincent Kok
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 

Was ist angesagt? (20)

Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react native
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
State management in react applications (Statecharts)
State management in react applications (Statecharts)State management in react applications (Statecharts)
State management in react applications (Statecharts)
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data Access
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
 
Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
ReactJS
ReactJSReactJS
ReactJS
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
NestJS
NestJSNestJS
NestJS
 

Ähnlich wie An Intro into webpack

Introduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationIntroduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationKnoldus Inc.
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
WEBPACK
WEBPACKWEBPACK
WEBPACKhome
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausWomen in Technology Poland
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4Vijay Shukla
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - WebpackRazvan Rosu
 
How to install ReactJS software
How to install ReactJS software How to install ReactJS software
How to install ReactJS software VigneshVijay21
 
ReactJS software installation
ReactJS software installationReactJS software installation
ReactJS software installationHopeTutors1
 
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
 
ITB2019 Containerizing ContentBox CMS - Gavin Pickin
ITB2019 Containerizing ContentBox CMS - Gavin PickinITB2019 Containerizing ContentBox CMS - Gavin Pickin
ITB2019 Containerizing ContentBox CMS - Gavin PickinOrtus Solutions, Corp
 
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi   SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi Sencha
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice DemystifyingfMrVMNair
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMSGavin Pickin
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.orgTed Husted
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end WorkflowPagepro
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Webpack presentation
Webpack presentationWebpack presentation
Webpack presentationRAHUL SHARMA
 

Ähnlich wie An Intro into webpack (20)

Introduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 PresentationIntroduction to Webpack 5.0 Presentation
Introduction to Webpack 5.0 Presentation
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
WEBPACK
WEBPACKWEBPACK
WEBPACK
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - Webpack
 
How to install ReactJS software
How to install ReactJS software How to install ReactJS software
How to install ReactJS software
 
ReactJS software installation
ReactJS software installationReactJS software installation
ReactJS software installation
 
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
 
ITB2019 Containerizing ContentBox CMS - Gavin Pickin
ITB2019 Containerizing ContentBox CMS - Gavin PickinITB2019 Containerizing ContentBox CMS - Gavin Pickin
ITB2019 Containerizing ContentBox CMS - Gavin Pickin
 
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi   SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
 
webpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingfwebpack introductionNotice Demystifyingf
webpack introductionNotice Demystifyingf
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMS
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.org
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Rails + Webpack
Rails + WebpackRails + Webpack
Rails + Webpack
 
Webpack presentation
Webpack presentationWebpack presentation
Webpack presentation
 

Mehr von Squash Apps Pvt Ltd

Mehr von Squash Apps Pvt Ltd (15)

The Critical role of Copyright
The Critical role of CopyrightThe Critical role of Copyright
The Critical role of Copyright
 
Please review and merge
Please review and mergePlease review and merge
Please review and merge
 
Angular Lifecycle Hooks
Angular Lifecycle HooksAngular Lifecycle Hooks
Angular Lifecycle Hooks
 
Next Generation of Javascript
Next Generation of JavascriptNext Generation of Javascript
Next Generation of Javascript
 
Hybrid app development frameworks
Hybrid app development frameworksHybrid app development frameworks
Hybrid app development frameworks
 
API Gateway with legend lambada
API Gateway with legend lambadaAPI Gateway with legend lambada
API Gateway with legend lambada
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
 
Lets vue(view) Vuex from the Top Vue(View)
Lets vue(view) Vuex from the Top Vue(View)Lets vue(view) Vuex from the Top Vue(View)
Lets vue(view) Vuex from the Top Vue(View)
 
An Overview on Nuxt.js
An Overview on Nuxt.jsAn Overview on Nuxt.js
An Overview on Nuxt.js
 
NPM
NPMNPM
NPM
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
AWS Jungle - Lambda
AWS Jungle - LambdaAWS Jungle - Lambda
AWS Jungle - Lambda
 
Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
 
Basics of NGINX
Basics of NGINXBasics of NGINX
Basics of NGINX
 
Basics of VueJS
Basics of VueJSBasics of VueJS
Basics of VueJS
 

Kürzlich hochgeladen

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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 WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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 WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Kürzlich hochgeladen (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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