webpack-bundler
Best practices and guidelines for Webpack module bundler configuration, optimization, and development workflows
What this skill does
# 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
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.