协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
webpack-plugin-recipes【开发与工程】Use whenever you face a webpack-build problem that ends with needing to write a plugin — 26 production-shaped recipes covering bundle-size budgets, forbidden architectural imports, env-var validation, secret-leak prevention, build-info injection, asset manifests, license walking, SRI hashes, virtual modules (Vite-style), filesystem routing (Next.js-s…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Cookbook of 26 production-shaped webpack 5 plugins, organized by the problem they solve. Each recipe starts with a clearly defined problem statement ("here's what hurts without this"), shows the naive non-plugin approach, then provides a complete working plugin (60-150 lines) with explanation, variations, and "when NOT to use" guidance.
Companion to webpack-plugin-authoring — authoring teaches how to write any plugin correctly; recipes teach which plugin to write for a specific pain point. Recipes cross-reference the authoring rules they apply.
Reference these recipes whenever:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Build-time Guardrails | CRITICAL | guard- |
| 2 | Build Metadata & Manifests | HIGH | meta- |
| 3 | Virtual Modules & Codegen | HIGH | virtual- |
| 4 | Code Transformation | MEDIUM-HIGH | transform- |
| 5 | Developer Experience | MEDIUM | dx- |
| 6 | Asset Pipeline | MEDIUM | assets- |
guard-bundle-budget — Fail builds when initial JS exceeds a per-entry gzipped budgetguard-forbidden-imports — Fail builds when forbidden imports cross architectural boundariesguard-required-env-vars — Fail builds when required environment variables are missingguard-no-secrets-bundled — Fail builds when secret-shaped strings leak into client bundlesmeta-inject-build-info — Inject __COMMIT__/__BUILD_TIME__ into source via DefinePlugin + emit build-info.jsonmeta-asset-manifest — Emit chunk-grouped manifest mapping logical names → hashed filenamesmeta-license-notice — Generate LICENSES.txt by walking the module graph (not node_modules/)meta-sri-manifest — Compute SHA-384 SRI hashes per asset for CSP compliancevirtual-module-from-memory — Resolve virtual:X imports to in-memory strings (Vite-style)virtual-routes-from-filesystem — Generate route map from pages/ directory (Next.js-style)virtual-barrel-from-directory — Auto-generate barrel re-exports from a directoryvirtual-types-from-runtime — Emit .d.ts from runtime data (config files, JSON schemas)transform-replace-library — Replace react with preact/compat at resolve (with subpath handling)transform-strip-debug-helpers — Strip devAssert()/devLog() calls + dev-only imports from productiontransform-conditional-polyfill — Inject only the polyfills target browsers actually need (browserslist + core-js-compat)transform-banner-with-dynamic-content — Per-chunk banners with current year, version, git committransform-define-from-config — Drive DefinePlugin substitutions from a flags/staging.json-style filedx-build-duration-report — Persist build durations, warn when current build is >30% slower than mediandx-notify-on-done — Desktop notification (local) + Slack webhook (CI) on build completedx-diff-changed-chunks — Print only the chunks that actually changed between rebuildsdx-open-browser-on-first-build — Open the dev-server URL AFTER first successful build (not before)assets-pre-compress-gzip-brotli — Emit .gz/.br siblings for CDN-served pre-compressionassets-optimize-images — Optimize PNG/JPEG with imagemin + cache reuse across rebuildsassets-route-by-type — Organize emitted assets into js//css//img//fonts/ subdirectoriesassets-skip-empty-chunks — Delete the 0-byte chunks webpack/splitChunks/mini-css emit unnecessarilyassets-add-cache-busting-query — Append ?v=<hash> to references of fixed-name assets (manifest.json, sw.js)When the user describes a webpack problem (or asks for a plugin):
For learning plugin authoring patterns more broadly, pair with the webpack-plugin-authoring skill — its 44 rules teach the underlying APIs every recipe in this skill applies.
| File | Description |
|---|---|
| references/_sections.md | Category definitions and impact levels |
| assets/templates/_template.md | Template for authoring new recipes |
| metadata.json | Version and source references |