webpack-bundler by mindrally/skills
npx skills add https://github.com/mindrally/skills --skill webpack-bundler您是 Webpack 专家,Webpack 是用于 JavaScript 应用程序的强大模块打包工具。在处理 Webpack 配置和相关代码时,请遵循以下准则。
project/
├── src/
│ ├── index.js # 主入口点
│ ├── components/ # UI 组件
│ ├── utils/ # 工具函数
│ ├── styles/ # CSS/SCSS 文件
│ └── assets/ # 图片、字体等资源
├── dist/ # 构建输出目录(被 git 忽略)
├── webpack.config.js # 主配置文件
├── webpack.dev.js # 开发环境配置
├── webpack.prod.js # 生产环境配置
└── 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', // 或 'development'
// production 模式启用 tree-shaking、代码压缩和优化
};
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// 使用动态导入实现按需加载
const module = await import('./heavy-module.js');
// 在 React 中使用
const LazyComponent = React.lazy(() => import('./LazyComponent'));
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
mode: 'production'sideEffects{
"sideEffects": false
}
或者指定具有副作用的文件:
{
"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'
}),
// 用于包分析
new BundleAnalyzerPlugin()
]
webpack-bundle-analyzer 识别大型依赖项module.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-analyzer 分析包stats 选项来理解构建输出--mode production 运行生产构建每周安装数
114
代码仓库
GitHub 星标数
42
首次出现
2026 年 1 月 25 日
安全审计
安装于
opencode94
gemini-cli92
cursor89
codex88
github-copilot83
claude-code78
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 productionWeekly Installs
114
Repository
GitHub Stars
42
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode94
gemini-cli92
cursor89
codex88
github-copilot83
claude-code78
Flutter应用架构设计指南:分层结构、数据层实现与最佳实践
4,500 周安装
lp-agent:自动化流动性提供策略工具 | Hummingbot API 与 Solana DEX 集成
211 周安装
Encore.ts 声明式基础设施:PostgreSQL、Redis、Pub/Sub、定时任务、对象存储
213 周安装
SkyPilot 多云编排指南:跨 AWS/GCP/Azure 自动优化机器学习成本与分布式训练
213 周安装
Flash Attention优化指南:PyTorch快速内存高效注意力机制实现2-4倍加速
209 周安装
邮件序列设计指南:自动化营销策略、模板与最佳实践 | 提升转化率
214 周安装
网页转Markdown工具 - 支持JS渲染页面,一键转换并清理内容
212 周安装