---
name: webpack-config-optimizer
description: "Production webpack settings that bring bundles under a size budget: code splitting, vendor chunks, tree shaking, caching, and minification chosen for your project type and webpack version, with the config and the expected effect of each change. Use when a webpack production build ships bundles over a size budget or builds too slowly and needs code splitting, vendor chunks, tree shaking, caching, and minification configured for its project type. Do not use for explaining an existing config, fixing a build error, or reorganising files without changing output. Related topics: coding, frontend, webpack."
---

# Webpack Config Optimizer

Production webpack settings that bring bundles under a size budget: code splitting, vendor chunks, tree shaking, caching, and minification chosen for your project type and webpack version, with the config and the expected effect of each change.

## When to use

Use this skill when a webpack production build ships bundles over a size budget or builds too slowly and needs code splitting, vendor chunks, tree shaking, caching, and minification configured for its project type. Do not use it for explaining an existing config, fixing a build error, or reorganising files without changing output.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Set performance budgets from the size threshold so the build itself fails or warns on regressions.
3. Configure splitChunks with a vendor cache group when requested and async chunks for every dynamic import, so lazy routes ship as separate files.
4. Make tree shaking effective by confirming production mode, sideEffects flags, and ES module output from the transpiler.
5. Wire up the chosen minifier, build caching for the webpack version, and content-hashed filenames for long-term caching.
6. Add each selected feature as an exact config snippet with one line on its effect, then assemble the full config and a change table with expected gains and trade-offs.

## Inputs

- **Project type** (choose one: React SPA, Vue.js, Vanilla JS, TypeScript, Library/Package)
- **Entry point** (free text, e.g. "./src/index.js")
- **Output path** (free text, e.g. "./dist")
- **Webpack version** (choose one: Webpack 4, Webpack 5)
- **Current config** (longer free text)
- **Features** (choose any: Code splitting, Lazy loading, Tree shaking, CSS/SCSS modules, Asset optimisation, Source maps, Hot Module Replacement (HMR), Bundle analyser, Environment variables, PWA/Service Worker)
- **Enable build caching** (choose one: Yes, No)
- **Bundle size warning threshold** (free text, e.g. "250kb")
- **Separate vendor chunks** (choose one: Yes, No)
- **Minification** (choose one: Terser, ESBuild, Default, None)

## Output

The complete optimised webpack config in a javascript code block, followed by a table with one row per change: setting, expected effect on bundle size or build time, and trade-off.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Webpack Config Optimizer

Tune my webpack configuration for a fast, small production build.

#### Project
- Project type: {{Project type}}
- Entry point: {{Entry point}}
- Output path: {{Output path}}
- Webpack version: {{Webpack version}}
- Current config: {{Current config}}

#### Features to configure
- Features: {{Features}}

#### Performance goals
- Enable build caching: {{Enable build caching}}
- Bundle size warning threshold: {{Bundle size warning threshold}}
- Separate vendor chunks: {{Separate vendor chunks}}
- Minification: {{Minification}}

Start from where the bytes go: set performance.maxAssetSize and maxEntrypointSize to the threshold so the build itself reports regressions. Then splitChunks: a vendor cacheGroup for node_modules when requested, and async chunks for every dynamic import so lazy routes ship separately. Make tree shaking real, not nominal: mode production, sideEffects declared in package.json, and ES module output from Babel or TypeScript, since CommonJS output silently disables it. For a library target, set output.library and mark peer dependencies as externals so consumers do not bundle React twice. Configure the chosen minifier, filesystem cache on webpack 5 (cache-loader on 4) when caching is on, and content hashes in filenames so long-term caching works. Add only the selected features; for each, give the exact config snippet and one line on what it changes. Return the full optimised config in a javascript code block, then a short table listing each change, the expected effect on bundle size or build time, and any trade-off (source maps add build time, ESBuild minifies faster but mangles less).

## Pitfalls

- Declaring tree shaking done while Babel still emits CommonJS, so no dead code is actually removed.
- Splitting vendors into one giant chunk that changes on every dependency bump, which defeats long-term caching.
- Bundling peer dependencies into a library build, so consumers end up with two copies of React.
- Turning on eval source maps in production for faster builds, which ships readable source to users.
