Webpack Config Generator

webpack.config.js
Results

Writing a webpack.config.js from memory means recalling the exact shape of output, the test regex for each loader and how the plugins wire up. This generator turns that into a short form: set your entry file, output folder and build mode, then tick the pieces you need, TypeScript, Babel, a CSS loader, HtmlWebpackPlugin and a dev server. It writes a clean, ready-to-copy webpack 5 config with [contenthash] filenames and output.clean already in place.

How to build a webpack config

  1. 1

    Set entry and output

    Type your entry file (default `./src/index.js`) and the output folder (default `dist`).

  2. 2

    Choose the mode

    Pick `production` or `development`. It is written straight into the `mode` field.

  3. 3

    Toggle loaders and plugins

    Turn on TypeScript (`ts-loader`), Babel (`babel-loader`), a CSS loader (`style-loader` + `css-loader`), `HtmlWebpackPlugin` and a dev server as needed.

  4. 4

    Copy the config

    The `webpack.config.js` updates live. Use the copy button and paste it into your project root.

Default output

With the defaults (production mode, TypeScript, Babel, a CSS loader and HtmlWebpackPlugin), the generator writes:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.[contenthash].js',
    clean: true,
  },
  resolve: { extensions: ['.ts','.tsx','.js'] },
  module: {
    rules: [
      { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
      { test: /\.jsx?$/, exclude: /node_modules/, use: 'babel-loader' },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({ template: './src/index.html' }),
  ],
};

What each option writes

Option What it adds to the config
entry The entry value, e.g. entry: './src/index.js'.
output folder output.path, resolved with path.resolve(__dirname, 'dist').
mode mode: 'production' or mode: 'development'.
TypeScript A ts-loader rule for .ts/.tsx, plus those extensions in resolve.
Babel A babel-loader rule for .js/.jsx.
CSS loader A rule chaining style-loader and css-loader for .css.
HtmlWebpackPlugin The require line plus new HtmlWebpackPlugin({ template: './src/index.html' }).
dev server A devServer block serving the output folder on port 3000 with hot reload.

Fixed choices in the output

To keep the starter config clean, a few values are set for you rather than exposed as fields:

  • Hashed filenames. output.filename is always bundle.[contenthash].js, which busts the browser cache whenever the bundle changes.
  • Clean output. output.clean: true empties the output folder on each build, the webpack 5 replacement for clean-webpack-plugin.
  • CSS is bundled, not extracted. style-loader injects styles through JavaScript. To emit a separate .css file for production, add MiniCssExtractPlugin yourself.
  • Dev server basics. When enabled, devServer sets static, port: 3000 and hot: true. Add options such as historyApiFallback or proxy by hand if your app needs them.

Extending it further

The generated file is a starting point, not a full production setup. Common next steps you add by hand: MiniCssExtractPlugin for extracted CSS, sass-loader for .scss, webpack 5 asset modules for images and fonts, a devtool value for source maps, and a splitChunks block for code splitting.

Frequently Asked Questions

Webpack 5. The output uses output.clean and [contenthash] filenames, the modern webpack 5 conventions, so no extra clean plugin is needed.

No, it always writes a JavaScript webpack.config.js. Enabling the TypeScript toggle adds a ts-loader rule so webpack can compile your .ts/.tsx source; it does not change the format of the config file itself.

The generated devServer block uses port 3000 with hot reload. Change the port value in the copied file if you need a different one.

Yes. Each toggle adds its own rule (ts-loader for .tsx?, babel-loader for .jsx?), so you can enable one, the other or both depending on how your project transpiles.

Related Tools

Tool available in other languages