Webpack Cheatsheet - Frontend Build Tool Configuration Reference
Webpack’s power is real and its config is where that power lives or hides. This reference covers entry/output, Loaders for each asset type, Plugins, dev-server/HMR, code splitting and optimizations, plus mode/environment. Use it when a new asset type won't load, HMR dies, or a bundle is inexplicably huge. Rather than echo boilerplate, it points to the flag or plugin that addresses the failure. After reading you configure and tune a build without reading the full Webpack docs.
Entry & Output 6
entry: "./src/index.js"entry: { app: "./src/app.js", vendor: "./src/vendor.js" }output.filename: "[name].[contenthash].js"output.path: path.resolve(__dirname, "dist")output.publicPath: "/assets/"output.clean: trueLoaders 8
{ test: /\.css$/, use: ["style-loader", "css-loader"] }{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"] }{ test: /\.js$/, exclude: /node_modules/, use: "babel-loader" }{ test: /\.tsx?$/, use: "ts-loader" }{ test: /\.(png|jpg|gif)$/, type: "asset/resource" }{ test: /\.svg$/, type: "asset/source" }{ test: /\.(woff2?|ttf|eot)$/, type: "asset/resource" }{ test: /\.(js|ts)$/, enforce: "pre", use: "source-map-loader" }Plugins 7
new HtmlWebpackPlugin({ template: "./src/index.html" })new MiniCssExtractPlugin({ filename: "[name].[contenthash].css" })new DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") })new CopyWebpackPlugin({ patterns: [{ from: "public", to: "." }] })new ProvidePlugin({ _: "lodash" })new HotModuleReplacementPlugin()new BannerPlugin({ banner: "Built at " + new Date().toISOString() })Dev Server 6
devServer.hot: truedevServer.historyApiFallback: truedevServer.port: 5000, open: truedevServer.static: path.join(__dirname, "public")devServer.proxy: { "/api": "http://localhost:3000" }devServer.proxy: { "/api": { target: "http://localhost:3000", pathRewrite: { "^/api": "" } } }Optimization 7
optimization.splitChunks: { chunks: "all" }optimization.minimize: trueoptimization.minimizer: [new TerserPlugin({ extractComments: false })]optimization.runtimeChunk: "single"import("./module").then(m => m.default)/* webpackChunkName: "vendor" *//* webpackPrefetch: true */Mode & Environment 6
mode: "production" | "development" | "none"webpack --config webpack.prod.js --mode productionmodule.exports = (env, argv) => ({ mode: argv.mode })devtool: argv.mode === "development" ? "eval-cheap-source-map" : "source-map"const { merge } = require("webpack-merge"); merge(common, prodConfig)new webpack.EnvironmentPlugin(["NODE_ENV", "API_URL"])Build Analysis 5
new BundleAnalyzerPlugin({ analyzerMode: "static" })stats: "minimal" | "normal" | "detailed"performance: { hints: "warning", maxAssetSize: 250000 }webpack --json > stats.jsondevtool: "source-map" | "eval-cheap-module-source-map"Tips
- Webpack 5 has built-in asset modules, replacing file-loader and url-loader.
- devServer.hot enables HMR for a smoother dev experience.
- splitChunks splits code by vendor/common to shrink first-load size.
- webpack-bundle-analyzer visualizes bundle size.
- Production mode enables tree shaking, which needs ESM imports/exports.
- [name].[contenthash].js gives long-term caching; unchanged files keep their hash and hit the browser cache.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us