技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
webpack-plugin-authoring【数据与研究】Writing webpack 5 plugins — hook selection (compiler vs compilation, tap vs tapAsync, processAssets stages), the asset pipeline (emitAsset, source classes, info metadata, source maps), watch-mode and persistent caching (file/context/missing/buildDependencies), plugin lifecycle (constructor purity, multi-compiler isolation, shutdown cleanup), schema-u…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
apply(compiler) method is being written, hooks are being tapped, or a plugin imports from webpack-sources, the rules in this skill apply.Comprehensive guide for writing correct, performant webpack 5 plugins. Contains 44 rules across 8 categories (8 hook + 7 asset + 5 cache + 5 life + 4 schema + 5 diag + 5 perf + 5 compat = 44), ordered by the authoring lifecycle: hook choice is the foundation, then asset manipulation, then caching/watch-mode correctness, then lifecycle hygiene, then user-facing concerns (schema validation, error reporting), then performance, then packaging.
Patterns are derived from webpack/webpack, the webpack-contrib plugin suite (mini-css-extract, terser, compression, copy, css-minimizer), and Next.js's webpack integration in vercel/next.js.
Reference these rules whenever:
apply(compiler), picking which hook to tap)processAssets, emitAsset, updateAsset)| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Hook Selection & Tap Patterns | CRITICAL | hook- |
| 2 | Asset Pipeline | CRITICAL | asset- |
| 3 | Caching & Watch Mode | HIGH | cache- |
| 4 | Plugin Lifecycle & State | HIGH | life- |
| 5 | Schema & Options Validation | MEDIUM-HIGH | schema- |
| 6 | Errors, Warnings & Logging | MEDIUM-HIGH | diag- |
| 7 | Performance & Parallelism | MEDIUM | perf- |
| 8 | Compatibility & Packaging | LOW-MEDIUM | compat- |
hook-tap-method-matches-hook-type — Match tap/tapAsync/tapPromise to the hook's Sync/Async typehook-thiscompilation-vs-compilation — Use thisCompilation to skip child compilationshook-process-assets-stage — Pick the right PROCESS_ASSETS_STAGE_* for your mutationhook-prefer-process-assets-over-emit — Mutate in processAssets, not emithook-bail-hook-return-semantics — Return undefined from bail hooks unless intentionally stoppinghook-tap-once-not-per-compilation — Register compiler hooks once in apply, not inside compilation hookshook-name-matches-class-name — Use a stable tap name equal to the class namehook-normal-module-factory-stages — Tap normalModuleFactory at the right resolution stage (beforeResolve vs resolve vs afterResolve)asset-emit-asset-not-direct-assignment — Use emitAsset/updateAsset, never compilation.assets[name] = ...asset-source-from-compiler-webpack — Import source classes from compiler.webpack.sourcesasset-preserve-source-maps — Use SourceMapSource/ReplaceSource to keep maps attachedasset-set-info-metadata — Set info.immutable, info.contenthash, info.related when emittingasset-content-hash-via-output-options — Hash via compilation.outputOptions.hashFunction, not hardcoded md5asset-delete-then-emit-loses-info — Use renameAsset to move; deleteAsset+emitAsset severs chunk referencesasset-buffer-not-source-for-binary — Use buffer() not source() for binary assetscache-add-file-dependencies — Add read files to compilation.fileDependenciescache-context-dependencies-for-directories — Use contextDependencies for directory scanscache-missing-dependencies-for-optional-files — Add probed-but-absent paths to missingDependenciescache-build-dependencies-for-persistent-cache — Declare buildDependencies for persistent cache invalidationcache-use-input-file-system — Read via compiler.inputFileSystem, not Node fslife-constructor-stores-options-only — Constructor only validates and stores; side effects belong in apply()life-no-mutable-state-across-builds — Scope mutable state per-compilation via local const or WeakMaplife-multi-compiler-isolation — One plugin instance per compiler; or use WeakMap<Compiler, T>life-cleanup-in-shutdown-hook — Clean up workers, watchers, fds in compiler.hooks.shutdownlife-defensively-copy-user-options — Never mutate the user's options objectschema-validate-with-schema-utils — Validate via schema-utils.validate() and a JSON Schemaschema-name-and-base-data-path — Set name and baseDataPath for navigable error messagesschema-additional-properties-false — Set additionalProperties: false on every object to catch typosschema-tap-into-validate-hook — Defer cross-field validation to compiler.hooks.validate (5.106+)diag-push-webpack-error-not-throw — Push WebpackError to compilation.errors, don't throwdiag-use-compilation-get-logger — Log via compilation.getLogger('Plugin'), not consolediag-attach-loc-to-errors — Attach loc and module to errors for IDE click-throughdiag-warnings-vs-errors-exit-codes — Errors fail the build; warnings don't — choose intentionallydiag-progress-reporting — Report progress via context.reportProgress (opt in with context: true)perf-jest-worker-for-cpu-bound-work — Offload CPU-bound work to a jest-worker poolperf-cache-results-with-compilation-cache — Cache expensive work via compilation.getCache(name).providePromiseperf-traverse-chunks-not-modules — Iterate compilation.chunks not compilation.modules when possibleperf-avoid-source-toString-in-hot-paths — Avoid source().toString() for assets you only inspectperf-respect-experimental-options — Honor experiments.cacheUnaffected / incrementalcompat-webpack-as-peer-dependency — Declare webpack as peerDependencies, not dependenciescompat-use-compiler-webpack-namespace — Use compiler.webpack.* instead of require('webpack')compat-custom-hooks-via-weakmap — Expose custom hooks via static getCompilationHooks + WeakMapcompat-feature-detection-not-version-check — Detect APIs directly; don't parse webpack/package.json versioncompat-export-shape-and-cjs-esm — Export the plugin class as default; provide CJS/ESM interopWhen writing or reviewing plugin code, scan AGENTS.md for the relevant category, then read the individual rule file for the full pattern and rationale.
references/_sections.md for category definitions and impact levelsassets/templates/_template.md for the rule template if you want to extend this skillAGENTS.md for a compact navigation index| File | Description |
|---|---|
| references/_sections.md | Category definitions, impact levels, descriptions |
| assets/templates/_template.md | Template for authoring new rules |
| metadata.json | Version, discipline, source references |