Skip to main content
skill CX Codex

webpack-bundler — Claude Code skill: Webpack config guide

A skill that tells the agent how to write and fix Webpack configs: chunk splitting, tree shaking, loaders and plugins. Useful when your bundle grows or builds drag.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill webpack-bundler -a claude-code
Open on GitHub

What webpack-bundler does

The skill sets rules for editing webpack.config.js and the code around it. It covers entry and output setup, production versus development mode, dynamic imports, and a splitChunks cache group that pulls node_modules into its own chunk.

Tree shaking gets its own section: ES module syntax, sideEffects in package.json, and @babel/preset-env with modules: false. Ready-made config blocks are included for babel-loader, ts-loader, css-loader with style-loader, sass-loader, and images handled by asset/resource. Among plugins it names HtmlWebpackPlugin, MiniCssExtractPlugin and BundleAnalyzerPlugin.

For build speed the skill points to a filesystem cache, TerserPlugin with parallel, and runtimeChunk: 'single'. Anti-patterns are listed outright: don't ship one giant file, don't import a whole library for a couple of functions, don't drop source maps during development. Some examples won't run unless webpack-bundle-analyzer and terser-webpack-plugin are already in your dependencies, so check package.json before letting the agent rewrite the config.

What it helps with

  • split the bundle into a vendor chunk and app code
  • turn on tree shaking and drop dead code
  • wire up loaders for SCSS and image files
  • speed up rebuilds with a filesystem cache
  • spot heavy dependencies with a bundle analyzer

Example prompts for the agent

  • Split the bundle: move everything from node_modules into a vendors chunk via splitChunks
  • Why is tree shaking not working? Check sideEffects in package.json and the Babel setup
  • Add webpack-bundle-analyzer to the config and show me what takes up the most space

How to install webpack-bundler

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill webpack-bundler -a claude-code

2Manually: put the files in place

~/.claude/skills/webpack-bundler/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/webpack-bundler/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about webpack-bundler

How do I install webpack-bundler in Claude Code?

Run npx skills add Mindrally/skills --skill webpack-bundler -a claude-code. The skill file lands at ~/.claude/skills/webpack-bundler/SKILL.md.

What does webpack-bundler do?

It gives the agent a set of Webpack rules: entry points, code splitting, tree shaking, loaders, plugins, and production build optimization.

Which Webpack versions does this skill target?

It relies on Webpack 5 and newer features, including asset/resource and the filesystem cache.

Source text

SKILL.md · Apache-2.0
---
name: webpack-bundler
description: Best practices and guidelines for Webpack module bundler configuration, optimization, and development workflows
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Webpack Bundler

You are an expert in Webpack, the powerful module bundler for JavaScript applications. Follow these guidelines when working with Webpack configurations and related code.

## Core Principles

- Webpack is a static module bundler that builds a dependency graph from entry points
- Focus on optimal bundle size, build performance, and developer experience
- Use Webpack 5+ features for best practices and performance
- Understand the plugin and loader ecosystem

## Project Structure

```
project/
├── src/
│   ├── index.js          # Main entry point
│   ├── components/       # UI components
│   ├── utils/            # Utility functions
│   ├── styles/           # CSS/SCSS files
│   └── assets/           # Images, fonts, etc.
├── dist/                 # Build output (gitignored)
├── webpack.config.js     # Main configuration
├── webpack.dev.js        # Development config
├── webpack.prod.js       # Production config
└── package.json
```

## Configuration Best Practices

### Entry and Output

```javascript
module.exports = {
  entry: {
    main: './src/index.js',
    vendor: './src/vendor.js'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].[contenthash].js',
    clean: true
  }
};
```

### Mode Configuration

```javascript
module.exports = {
  mode: 'production', // or 'development'
  // production mode enables tree-shaking, minification, and optimizations
};
```

## Code Splitting

### Dynamic Imports

```javascript
// Use dynamic imports for on-demand loading
const module = await import('./heavy-module.js');

// With React
const LazyComponent = React.lazy(() => import('./LazyComponent'));
```

### SplitChunks Configuration

```javascript
optimization: {
  splitChunks: {
    chunks: 'all',
    cacheGroups: {
      vendor: {
        test: /[\\/]node_modules[\\/]/,
        name: 'vendors',
        chunks: 'all'
      }
    }
  }
}
```

## Tree Shaking

### Enable Tree Shaking

1. Use ES6 module syntax (import/export)
2. Set `mode: 'production'`
3. Configure `sideEffects` in package.json

```json
{
  "sideEffects": false
}
```

Or specify files with side effects:

```json
{
  "sideEffects": ["*.css", "*.scss"]
}
```

### Babel Configuration for Tree Shaking

```json
{
  "presets": [
    ["@babel/preset-env", { "modules": false }]
  ]
}
```

## Loaders

### Common Loader Configuration

```javascript
module: {
  rules: [
    {
      test: /\.jsx?$/,
      exclude: /node_modules/,
      use: 'babel-loader'
    },
    {
      test: /\.tsx?$/,
      exclude: /node_modules/,
      use: 'ts-loader'
    },
    {
      test: /\.css$/,
      use: ['style-loader', 'css-loader']
    },
    {
      test: /\.scss$/,
      use: ['style-loader', 'css-loader', 'sass-loader']
    },
    {
      test: /\.(png|svg|jpg|jpeg|gif)$/i,
      type: 'asset/resource'
    }
  ]
}
```

## Plugins

### Essential Plugins

```javascript
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

plugins: [
  new HtmlWebpackPlugin({
    template: './src/index.html'
  }),
  new MiniCssExtractPlugin({
    filename: '[name].[contenthash].css'
  }),
  // Use for bundle analysis
  new BundleAnalyzerPlugin()
]
```

## Performance Optimization

### Bundle Size Optimization

- Use `webpack-bundle-analyzer` to identify large dependencies
- Enable tree shaking to remove unused code
- Replace large dependencies with smaller alternatives
- Enable Gzip or Brotli compression

### Build Performance

```javascript
module.exports = {
  cache: {
    type: 'filesystem'
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  }
};
```

### Production Optimization

```javascript
optimization: {
  minimize: true,
  minimizer: [
    new TerserPlugin({
      parallel: true
    }),
    new CssMinimizerPlugin()
  ],
  moduleIds: 'deterministic',
  runtimeChunk: 'single'
}
```

## Development Server

```javascript
devServer: {
  static: './dist',
  hot: true,
  port: 3000,
  historyApiFallback: true,
  proxy: {
    '/api': 'http://localhost:8080'
  }
}
```

## Environment Variables

```javascript
const webpack = require('webpack');

plugins: [
  new webpack.DefinePlugin({
    'process.env.API_URL': JSON.stringify(process.env.API_URL)
  })
]
```

## Common Anti-Patterns to Avoid

- Do not bundle everything into a single file
- Avoid importing entire libraries when only specific functions are needed
- Do not skip source maps in development
- Avoid hardcoding environment-specific values
- Do not ignore bundle size warnings

## Testing and Debugging

- Use source maps for debugging (`devtool: 'source-map'`)
- Analyze bundles regularly with `webpack-bundle-analyzer`
- Test production builds locally before deployment
- Use `stats` option to understand build output

## Security Considerations

- Keep Webpack and plugins up to date
- Validate and sanitize all user inputs
- Use Content Security Policy headers
- Avoid exposing sensitive data in bundles

## Integration with CI/CD

- Cache node_modules and Webpack cache
- Run production builds with `--mode production`
- Fail builds on bundle size budget violations
- Generate and store bundle analysis reports

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

Everything for Frontend and UI →

From the same set236

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor