webpack-bundler
БесплатноБез исполняемых скриптовНе проверенBest practices and guidelines for Webpack module bundler configuration, optimization, and development workflows
от Mindrally★ 323 звезды на GitHubОб этом скилле
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
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
module.exports = {
mode: 'production', // or 'development'
// production mode enables tree-shaking, minification, and optimizations
};
Code Splitting
Dynamic Imports
// Use dynamic imports for on-demand loading
const module = await import('./heavy-module.js');
// With React
const LazyComponent = React.lazy(() => import('./LazyComponent'));
SplitChunks Configuration
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
Tree Shaking
Enable Tree Shaking
- Use ES6 module syntax (import/export)
- Set
mode: 'production' - Configure
sideEffectsin package.json
{
"sideEffects": false
}
Or specify files with side effects:
{
"sideEffects": ["*.css", "*.scss"]
}
Babel Configuration for Tree Shaking
{
"presets": [
["@babel/preset-env", { "modules": false }]
]
}
Loaders
Common Loader Configuration
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
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-analyzerto identify large dependencies - Enable tree shaking to remove unused code
- Replace large dependencies with smaller alternatives
- Enable Gzip or Brotli compression
Build Performance
module.exports = {
cache: {
type: 'filesystem'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
'@': path.resolve(__dirname, 'src')
}
}
};
Production Optimization
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true
}),
new CssMinimizerPlugin()
],
moduleIds: 'deterministic',
runtimeChunk: 'single'
}
Development Server
devServer: {
static: './dist',
hot: true,
port: 3000,
historyApiFallback: true,
proxy: {
'/api': 'http://localhost:8080'
}
}
Environment Variables
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
statsoption to understand build output
Security Considerations
- Keep Webpack and plugins up to date
Установить webpack-bundler в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл webpack-bundler?
Best practices and guidelines for Webpack module bundler configuration, optimization, and development workflows
Как установить скилл webpack-bundler?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл webpack-bundler запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic