---
name: webpack-config-architect
description: "Lays down a full webpack setup for a project type with separate development and production configs: shared rules, hot reload in dev, hashing and chunk splitting in prod, and a comment on every major decision. Use when a project needs a complete webpack setup with separate development and production configs, chunk splitting, hashing, and hot reload decided. Do not use for a single quick config for one mode and target, explaining a config you already have, or fixing a broken build. Related topics: coding, webpack."
---

# Webpack Config Architect

Lays down a full webpack setup for a project type with separate development and production configs: shared rules, hot reload in dev, hashing and chunk splitting in prod, and a comment on every major decision.

## When to use

Use this skill when a project needs a complete webpack setup with separate development and production configs, chunk splitting, hashing, and hot reload decided. Do not use it for a single quick config for one mode and target, explaining a config you already have, or fixing a broken build.

## 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. Write webpack.common.js with entry, output, resolve, and module rules chosen for the project type and CSS approach.
3. Write webpack.dev.js merging development mode, devServer with hot module replacement, and cheap source maps.
4. Write webpack.prod.js merging production mode, content-hashed filenames, splitChunks for vendor and shared code, minimizer, and the chosen source-map setting.
5. Apply project-type specifics: library output and externals, SSR node target, one HtmlWebpackPlugin per entry for multi-page.
6. Comment every major decision and list the install command with packages matching the webpack major version.

## Inputs

- **Project type** (choose one: Single-page app, Library, Server-side rendering, Multi-page app)
- **Entry points** (longer free text)
- **Output directory** (free text, e.g. "./dist")
- **Target browsers** (choose any: Chrome, Firefox, Safari, Edge, Legacy browsers)
- **Use TypeScript** (choose one: Yes, No)
- **CSS approach** (choose one: Plain CSS, Sass, PostCSS with Tailwind, CSS modules)
- **Enable source maps** (choose one: Yes, No)
- **Additional plugins** (longer free text)
- **Webpack version** (choose one: 5, 4)

## Output

Three javascript code blocks (common, dev, prod) with decision comments, then one install command naming every required package.

## Prompt template

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

### Webpack Config Architect

Create the webpack configuration set for the project below.

- Project type: {{Project type}}
- Entry points: {{Entry points}}
- Output directory: {{Output directory}}
- Target browsers: {{Target browsers}}
- Use TypeScript: {{Use TypeScript}}
- CSS approach: {{CSS approach}}
- Enable source maps: {{Enable source maps}}
- Additional plugins: {{Additional plugins}}
- Webpack version: {{Webpack version}}

Structure the configuration as three files so the environments cannot drift: webpack.common.js with entry, output, resolve, and module rules; webpack.dev.js merging devServer with hot module replacement, cheap source maps, and development mode; webpack.prod.js merging production mode, content hashing in filenames, splitChunks for vendor and shared code, minimizer settings, and the source-map choice the user made. Pick rules by project type: a library sets output.library and externals; SSR builds a node target with externals for node_modules; a multi-page app gets one HtmlWebpackPlugin per entry. Match the browser targets through the transpiler's targets so legacy support costs nothing when not requested. Add the TypeScript loader and resolve.extensions only when TypeScript is on. Include DefinePlugin for the environment flag and the user's extra plugins with their options.

Comment each major section with the reason for the choice, and list the npm packages the configs require with versions matching the webpack major.

### Output
Return three fenced javascript blocks (webpack.common.js, webpack.dev.js, webpack.prod.js) with comments on each major decision, followed by the install command listing every required package.

## Pitfalls

- Duplicating rules across dev and prod instead of merging from a common file, so they drift within a month.
- Content-hashing filenames in development, which defeats hot module replacement and fills the output folder.
- Adding IE-era transpilation targets by default, which inflates every bundle for users nobody has.
