Skip to content
Tutorials Center
My learning

Topics

Webpack Tutorial

Learn Webpack step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Webpack? Learn what Webpack is, which problem a module bundler solves, how the dependency graph works and when to use Webpack instead of plain script tags or newer tools.
  2. 2 Install Webpack and Build Your First Bundle Install Webpack and webpack-cli with npm, write a tiny project, add npm scripts, run your first build and read the dist output and the build summary line by line.
  3. 3 The Webpack Configuration File Understand webpack.config.js: its main keys, CommonJS versus ESM and TypeScript configs, exporting a function or array, passing env flags and validating your configuration.
  4. 4 Build Modes: Development, Production and None Learn what Webpack's mode option changes: minification, tree shaking, process.env.NODE_ENV, source maps and module names, and how to choose between development, production and none.
  5. 5 How a Bundler Works Build a tiny module bundler in Node.js to see exactly how Webpack works: dependency graph, module wrapper, the require runtime, circular imports and a tree shaking sketch.

Entry, Output and Loaders

  1. 6 Entry Points Learn Webpack's entry option: string, array and object forms, named entries for multi-page apps, entry descriptors with dependOn, dynamic entries and the context folder.
  2. 7 Output and Filenames Control where Webpack writes files and how they are named: output.path, filename templates, [contenthash], publicPath, clean, chunkFilename and building a library.
  3. 8 Loaders Basics Learn how Webpack loaders turn CSS, images, TypeScript and any file into modules: module.rules, test and include, loader chains, options, and how to write a tiny custom loader.
  4. 9 CSS and Style Loaders Import CSS in Webpack with css-loader and style-loader, add Sass and PostCSS, use CSS Modules for scoped class names and understand importLoaders, url() handling and the production alternative.
  5. 10 Babel and TypeScript Loaders Compile modern JavaScript, JSX and TypeScript in Webpack with babel-loader, preset-env and browserslist, ts-loader or swc-loader, type checking with a separate plugin, and build caching.
  6. 11 Resolve, Extensions and Aliases Understand how Webpack finds modules: resolve.extensions, alias, modules, mainFields, conditionNames, package exports, symlinks and fixes for the common Module not found error.

Plugins and Assets

  1. 12 HTML Webpack Plugin Use HtmlWebpackPlugin to generate HTML that includes your hashed bundles automatically: templates, title, chunks, multiple pages, minification, favicon and common mistakes.
  2. 13 MiniCssExtractPlugin Move CSS out of JavaScript into real .css files with MiniCssExtractPlugin, switch between style-loader and the plugin by mode, add CssMinimizerPlugin, hash names and split CSS by chunk.
  3. 14 Asset Modules: Images, Fonts and Files Handle images, fonts, SVG and text files with Webpack 5 asset modules: asset/resource, asset/inline, asset/source and the automatic asset type, size limits, generator filenames and CSS url().
  4. 15 Define, Copy and Clean Plugins Use everyday Webpack plugins: DefinePlugin and EnvironmentPlugin for build-time constants, dotenv for env files, CopyWebpackPlugin for static files, ProvidePlugin, and output.clean.
  5. 16 Writing a Webpack Plugin Learn how Webpack plugins work and write your own: the plugin class and apply method, compiler and compilation hooks, tapable, emitting a file, processAssets, options and testing ideas.

Dev Server and HMR

  1. 17 Webpack Dev Server Run webpack serve with webpack-dev-server: install and configure port, host, open, static, client overlay and compression, understand in-memory builds and how live reload works.
  2. 18 Hot Module Replacement Understand Hot Module Replacement in Webpack: how updates bubble through module.hot.accept, writing accept and dispose handlers, CSS hot updates, framework refresh and common pitfalls.
  3. 19 Source Maps Debug bundled code with Webpack source maps: what a source map is, how mappings work, choosing devtool values for development and production, hidden maps, error tracking and security.
  4. 20 Proxy and History Fallback Fix CORS and deep-link 404s in development: configure devServer.proxy for API calls, pathRewrite, WebSocket proxying, historyApiFallback for single-page apps, headers and HTTPS.

Code Splitting and Lazy Loading

  1. 21 Code Splitting Learn webpack code splitting: why one giant bundle hurts, how entry points, dynamic import() and splitChunks create chunks, and how to read the chunk graph.
  2. 22 Dynamic Imports and Lazy Loading Master webpack dynamic import(): lazy-load routes and heavy features, name chunks with magic comments, use prefetch and preload, and handle loading errors.
  3. 23 The SplitChunksPlugin Configure webpack optimization.splitChunks: chunks, minSize, minChunks, cacheGroups for vendor code, naming, runtimeChunk, and how to avoid too many requests.

Optimization and Caching

  1. 24 Production Mode and Minification Learn what webpack mode production switches on: minification with Terser, DefinePlugin constants, dead-code removal, CSS minification and the right devtool setting.
  2. 25 Tree Shaking and Side Effects Understand webpack tree shaking: how usedExports and the sideEffects flag remove unused code, why ES modules matter, and the mistakes that keep dead code in your bundle.
  3. 26 Long-Term Caching with Content Hashes Make returning visitors download less: webpack contenthash file names, deterministic module ids, runtimeChunk, cache headers, and the persistent build cache.
  4. 27 Bundle Analysis and Performance Budgets Find what bloats your webpack bundle: stats.json, webpack-bundle-analyzer, performance hints and budgets, duplicate packages, and a repeatable size-reduction routine.

Webpack with Frameworks

  1. 28 Webpack with React Set up webpack for a React app: babel-loader with preset-react, the automatic JSX runtime, CSS, React Fast Refresh, React.lazy code splitting and a production config.
  2. 29 Webpack with Vue and Svelte Configure webpack for Vue single-file components with vue-loader and VueLoaderPlugin, and for Svelte with svelte-loader. Learn how SFC blocks are split, styled and hot reloaded.
  3. 30 Webpack with TypeScript Compile TypeScript with webpack using ts-loader, babel-loader or swc-loader, set up tsconfig for bundlers, run type checks in parallel with fork-ts-checker, and resolve path aliases.
  4. 31 Module Federation Learn webpack 5 Module Federation: hosts, remotes, exposes, shared dependencies and version negotiation, with a config walkthrough and the pitfalls of micro-frontends.

Migration and Alternatives

  1. 32 Upgrading from Webpack 4 to 5 A step-by-step migration guide from webpack 4 to 5: asset modules replace file-loader, Node polyfills are gone, persistent caching, new ids and the removed options.
  2. 33 Webpack vs Vite, Rollup, esbuild and Rspack Compare webpack with Vite, Rollup, esbuild, Rspack, Parcel and Turbopack: how each works, where each is strongest, and a practical decision guide for new and existing projects.
  3. 34 Migrating from Webpack to Vite Move a webpack project to Vite step by step: entry HTML, aliases, env variables, DefinePlugin, dev server proxy, asset imports, require calls and CommonJS gotchas.

Projects and Practice

  1. 35 Project: Build a Mini Bundler Project: write a tiny JavaScript bundler in Node.js that reads a dependency graph, wraps modules in a runtime and shakes unused exports. A hands-on way to understand webpack.
  2. 36 Project: A Production-Ready Webpack Config Project: assemble a complete, production-ready webpack 5 setup with common, dev and prod configs, merging, content hashes, split chunks, CSS extraction, budgets and a config audit.
  3. 37 Project: A Lazy-Loaded Dashboard Project: design a dashboard whose routes and widgets load on demand with webpack dynamic imports, hover prefetch, loading and error states, retries and a size budget per route.
  4. 38 Troubleshooting and Practice Fix common webpack errors fast: module not found, loader and export errors, HMR and cache problems, slow builds and oversized bundles, plus practice exercises and interview questions.