Webpack Config Generator
Build webpack.config.js — configure loaders, plugins, devServer, and optimization
Mode
Entry & Output
Loaders
Plugins
Dev Server
webpack-dev-server with live reloading and HMR
Hot Module Replacement (HMR)
Updates modules in the browser without a full page reload
API Proxy
Optimization
Run this in your project directory to install all required packages
11 packages required
You’re setting up a webpack project from scratch. The config needs: babel-loader for JSX, css-loader + MiniCssExtractPlugin for CSS, HtmlWebpackPlugin for the HTML template, dev server with hot reload on port 3000, and production optimization with code splitting. The webpack docs are 200 pages and the config file is pure JavaScript with nested objects that are easy to misstructure.
Why This Generator (Not the Vite Config Generator)
PureDevTools has a Vite Config Generator for Vite projects. This tool generates webpack.config.js files — select mode, entry point, loaders (Babel, CSS, Sass, TypeScript), plugins (HtmlWebpackPlugin, MiniCssExtractPlugin, CleanWebpackPlugin), devServer options, and optimization settings. Also generates the corresponding npm install command. Everything runs in your browser.
What Is Webpack?
Webpack is a static module bundler for JavaScript applications. It recursively builds a dependency graph from your project’s entry point, then bundles every module into one or more output files. Beyond JavaScript, webpack handles CSS, images, fonts, and other assets through loaders, and extends the build pipeline with plugins for tasks like HTML generation, CSS extraction, and code minification.
Webpack is the build tool behind many popular frameworks and CLI tools — Create React App, Vue CLI, Next.js, and Angular CLI all use webpack under the hood.
How the Webpack Config Generator Works
This tool generates a complete webpack.config.js file based on your selections:
- Choose mode —
development(fast builds, source maps, unminified output) orproduction(optimized, minified output) - Set entry and output — define your bundle’s starting file, output directory, and output filename
- Select loaders — add support for JS/JSX, TypeScript, CSS, Sass, and file assets
- Add plugins — configure HtmlWebpackPlugin, MiniCssExtractPlugin, CleanWebpackPlugin, DefinePlugin, and CopyWebpackPlugin
- Configure devServer — set port, enable Hot Module Replacement (HMR), and add API proxy rules
- Set optimization options — enable code splitting, minimization, and Terser for production builds
- Copy the config and install command — paste into your project and run the install command
All generation happens in your browser. Nothing is sent to a server.
Configuration Sections Explained
Mode
The mode option tells webpack to apply built-in optimizations appropriate for the environment:
| Mode | Behavior |
|---|---|
development | Enables useful error messages, source maps, and fast incremental rebuilds via HMR |
production | Enables tree shaking, scope hoisting, minification, and deterministic chunk IDs |
Always set the mode explicitly. Without it, webpack defaults to production but emits a warning.
Entry and Output
The entry point is the file webpack starts from to build its dependency graph. Common values:
./src/index.js— standard JavaScript app./src/index.ts— TypeScript app./src/main.jsx— React app with JSX
The output section controls where the compiled bundle is written:
path— absolute path to the output directory (always usepath.resolve(__dirname, ...))filename— name of the output bundle file (bundle.js,[name].[contenthash].jsfor cache-busting)
Loaders
Webpack only understands JavaScript and JSON by default. Loaders transform other file types into modules:
| Loader | Purpose |
|---|---|
babel-loader (JS/JSX) | Transpiles modern JS and JSX to browser-compatible JavaScript using Babel |
babel-loader (TS/TSX) | Transpiles TypeScript and TSX using @babel/preset-typescript |
css-loader + style-loader | Imports CSS files; css-loader resolves @import and url(), style-loader injects styles into the DOM |
sass-loader | Compiles Sass/SCSS to CSS; must be used alongside css-loader |
file-loader | Emits files to the output directory and returns their public URL |
url-loader / asset modules | Webpack 5 native asset modules — inline small assets as Base64 data URLs, emit large ones as files |
Loader order matters. In a use array, loaders execute right-to-left: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'] means Sass is compiled first, then CSS resolved, then extracted.
Plugins
Plugins extend webpack’s capabilities beyond module transformation:
| Plugin | Purpose |
|---|---|
HtmlWebpackPlugin | Generates an index.html from a template and automatically injects <script> and <link> tags |
MiniCssExtractPlugin | Extracts CSS into separate .css files instead of injecting inline via style-loader (required for production) |
CleanWebpackPlugin | Removes old files from the output directory before each build |
DefinePlugin | Replaces global constants at compile time — typically used to inject process.env.NODE_ENV |
CopyWebpackPlugin | Copies static files (e.g. public/ assets) to the output directory without bundling |
Dev Server
webpack-dev-server provides a development HTTP server with live reloading:
- Port — the port the server listens on (default:
3000) - Hot reload (HMR) — Hot Module Replacement updates modules in the browser without a full page refresh, preserving application state
- Proxy — forwards API requests to a backend server, avoiding CORS issues in development (e.g. proxy
/apitohttp://localhost:8080)
Optimization
| Option | Purpose |
|---|---|
splitChunks | Splits shared dependencies into separate chunks to enable browser caching and reduce bundle size |
minimize | Enables minification (enabled by default in production mode) |
Terser | Uses TerserPlugin for JavaScript minification with configurable options like drop_console |
When to Use MiniCssExtractPlugin vs. style-loader
Use style-loader in development — it injects CSS directly into the DOM at runtime, which is faster for HMR because style updates don’t require a reload.
Use MiniCssExtractPlugin in production — it extracts CSS into separate files that the browser can cache independently. When enabled in this generator, MiniCssExtractPlugin.loader automatically replaces 'style-loader' in the generated config.
A common pattern is to select which loader to use based on mode:
const styleLoader = process.env.NODE_ENV === 'production'
? MiniCssExtractPlugin.loader
: 'style-loader';
Frequently Asked Questions
Do I need to install webpack globally?
No. Install webpack locally in your project as a dev dependency. The generated install command handles this: npm install --save-dev webpack webpack-cli. Run webpack via an npm script in package.json:
"scripts": {
"build": "webpack",
"dev": "webpack serve"
}
What is the difference between file-loader and asset modules?
file-loader is a third-party loader from webpack 4 era. In webpack 5, the equivalent is built-in as asset modules — use type: 'asset' for automatic inline/emit decisions, type: 'asset/resource' to always emit as a file, or type: 'asset/inline' to always inline as a data URL. The url-loader / asset modules option in this generator outputs Webpack 5’s native type: 'asset' syntax.
Why does my TypeScript project use babel-loader instead of ts-loader?
babel-loader with @babel/preset-typescript is faster because it strips TypeScript types without performing type checking. Use it in combination with a separate tsc --noEmit step (e.g. in CI) for type validation. If you need webpack to report TypeScript type errors during the build itself, use ts-loader or fork-ts-checker-webpack-plugin instead.
How do I add source maps?
In development mode, add devtool: 'eval-source-map' (fast, good quality). For production debugging, use devtool: 'source-map' (slower, separate .map files). Different devtool values offer different trade-offs between build speed and source map quality.
Is the generated config sent to a server? No. All config generation happens entirely in your browser. Your entry paths, output paths, and configuration choices never leave this page.