Wk-notes-02-06-more-webpack
Last updated
Was this helpful?
Last updated
Was this helpful?
Problems html loading scripts
It is not immediately apparent that the script depends on an external library.
If a dependency is missing, or included in the wrong order, the application will not function properly.
If a dependency is included but not used, the browser will be forced to download unnecessary code.
Webpack is a bundler, it by default only do moduling with esmodule.
Note that webpack will not alter any code other than
import
andexport
statements.
webpack will dynamically bundle all dependencies (creating a dependency graph). Every module now explicitly states its dependencies and we'll avoid bundling modules that aren't in use.
Assets
css: style-loader
, css-loader
; css url('URL')
will be transform to output bundled assets(img url/font url)
img: jpg/png/gif/svg > file-loader
font: woff/eoft... > file-loader
data:
json built-in
, default import only import data from './data.json';
csv/tsv > csv-loader
xml > xml-loader
Use entry
and output
, we can create separate bundles, from different entry files. Using output.filename = [name].bundle.js
is the simplest way to generate bundle name with app/bundle name intepolation.
For complex multi bundling, we use HtmlWebpackPlugin
. It auto links script src names with webpack bundles entry app name.
Source-map devtool: inline-source-map
webpack --watch
webpack-dev-server --open
: With config in devServer
, it offers simple live reloading over webpack bundling
webpack-dev-middleware
: use middleware to set up a express server for more customizable dev-server.