webpack JS module bundler
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
npm i -D webpack webpack-cli
npx webpacknpx webpack --mode production
npx webpack watch
npx webpack serve --open
npx webpack configtest
npx webpack --analyze
npx webpack info
Concepts
- Entry ./src/index.js
- Loaders module.rules
- Plugins whole bundle
- Output dist/
Commands
npx webpack [entries...]
npx webpack build
npx webpack watch
npx webpack serve
npx webpack configtest [path]
npx webpack info
npx webpack version
npx webpack help [cmd]
npx create-webpack-app [dir]
npx create-webpack-app plugin [dir]
npx create-webpack-app loader [dir]
Build options
--mode <mode>
-c, --config <file>
--entry <path>
--entry-reset <path>
-o, --output-path <dir>
-t, --target <target>
-d, --devtool <type>
--no-devtool--name <name>
--fail-on-warnings
-w, --watch--no-watchConfig and env
--env <key>[=<value>]
--config-node-env <env>
--config-name <name>
--merge-e, --extends <file>
--disable-interpret
WEBPACK_SERVE / WEBPACK_BUILD / WEBPACK_WATCH
NODE_OPTIONS=--max-old-space-size=4096 npx webpack
Output and analysis
--stats <preset>
--no-stats--json [file]--analyze--progress[=profile]
--color / --no-color
--help=verboseDev server
npx webpack serve --open
npx webpack serve --static <dir>
npx webpack serve --no-hot
npx webpack serve --mode development
Config files
| Base name | Extensions |
|---|---|
webpack.config |
js mjs cjs ts cts mts |
.webpack/webpack.config |
same |
.webpack/webpackfile |
same |
Recipes
const path = require('path');module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js' }, module: { rules: [{ test: /\.css$/, use: ['style-loader', 'css-loader'] }] }, plugins: [], devServer: { static: './dist', hot: true },};
# webpack.config.js exports (env, argv) => ({...})npx webpack --env production --mode productionnpx webpack serve --env port=3000
npx webpack --mode production --json stats.json# upload stats.json to an analyzer, or:npx webpack --mode production --analyze
npx webpack configtestnpx webpack --mode production --fail-on-warnings



