Naveen Reddy
I ❤️ building useful stuff!! Passionate about coding and design.
Utah
Pearson
WebPack is a module bundler for Javascript
JavaScript History
Using script tag in head or referring to an external file
Solution for Scope Issues:- IIFE
var x = "Hello"
(function(){
var x = "World";
console.log(x);
})() // This is what an IIFE is
console.log(x);
Revealing Module Pattern
Concatenate Files using IIFE's
Solution to no of files:
Task Runners
Module Bundlers
-- prefixing css rules
-- compiling css - preprocessors - SASS to CSS
-- Converting JSX to js
-- Minifying JS
-- Concatenating files
Module bundling refers to bundle Javascript modules (ex:- ES2015 modules, CommonJs, AMD, UMD) into a single file (or bundles) for use in production environments.
How do we load JavaScript if there is no DOM ??
Reuse any module using NPM + node_modues
ESM Modules - Also called as Harmony modules
http://2ality.com/2014/09/es6-modules-final.html
Problems
Let's see in Practical
module.exports = {
entry: './src/index.js',
output: {
path: './dist',
filename: './bundle.js'
},
module:{
rules: [
{
test: '/\.(js|jsx)$/',
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './dist/index.html',
}),
]
}
Loaders work at a file level during/before bundle generation (Ex:- babel-loader - ES6-ES5)
Plugins work at a bundle/chunk level at the end of bundle generation (ex;- UglifyJSPlugin for minification)
By Naveen Reddy