Professional Documents
Culture Documents
Web Pack
Web Pack
2. Features of WWebpack
+ Assets module:
* is a new feature introduced in Webpack five.
* It allows you to easily use asset files in your JavaScript
application without installing additional dependencies (such as image, fonts, etc.)
* Have 4 types of assets module:
- asset/resource
- asset/inline
- asset => combine two assets above, if file < 8kb then use
asset/inline else use asset/inline
- asset/source
+ Asset/resource:
* To handle images with webpack, need add rules in module in
webpack config file, if dont have it, webpack dont know how to handle image
* Public Path tell webpack which URL to use in order to load all
the generated files in the browser
+ Asset/inline:
* dont generate new files in the output directory, instead it
will generate base 64 a representation of your file and bake it directly into the
JS bundle
* some time Asset/inline is better than Asset/resource, when use
Asset/resource, webpack generates a separate file for every image, this make
browser make a separate HTTP request for each image it need to display. If u have
20 image so browser need to make 20 HTTP requests to display those images
+ Asset:
* combine two assets above, if file < 8kb then use asset/inline
else use asset/inline
* we can change file size 8kb to any number we want by use parser
in rule
+ Asset/source:
* dont generate new files in the output directory, similiar
asset/inline but no modify file
* read the contents of the file into a JS string and injects that
string directly into the JS bundle as is without any modifications similiar to
asset/inline
+ Loaders:
* It's allows to import all other kinds of files that you can not
handle by using Asset Modules (ex css files)
* To teach webpack handle with css file, we need to configure in rules,
different type modules asset, with css we use "use" property call "style-loader",
"css-loader"
/ Css loader read the contents of the css file and returns this
content but it doesn't do anything
/ Then style loader takes the Css and injects it into the page
using style tag