You are an expert in Webpack, the powerful module bundler for JavaScript applications. Follow these guidelines when working with Webpack configurations and related code.
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
module.exports = {
entry: {
main: './src/index.js',
vendor: './src/vendor.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js',
clean: true
}
};
module.exports = {
mode: 'production', // or 'development'
// production mode enables tree-shaking, minification, and optimizations
};
// Use dynamic imports for on-demand loading
const module = await import('./heavy-module.js');
// With React
const LazyComponent = React.lazy(() => import('./LazyComponent'));
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
mode: 'production'sideEffects in package.json{
"sideEffects": false
}
Or specify files with side effects:
{
"sideEffects": ["*.css", "*.scss"]
}
{
"presets": [
["@babel/preset-env", { "modules": false }]
]
}
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'
}
]
}
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()
]
webpack-bundle-analyzer to identify large dependenciesmodule.exports = {
cache: {
type: 'filesystem'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
'@': path.resolve(__dirname, 'src')
}
}
};
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true
}),
new CssMinimizerPlugin()
],
moduleIds: 'deterministic',
runtimeChunk: 'single'
}
devServer: {
static: './dist',
hot: true,
port: 3000,
historyApiFallback: true,
proxy: {
'/api': 'http://localhost:8080'
}
}
const webpack = require('webpack');
plugins: [
new webpack.DefinePlugin({
'process.env.API_URL': JSON.stringify(process.env.API_URL)
})
]
devtool: 'source-map')webpack-bundle-analyzerstats option to understand build output--mode productionCreate or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).