一键导入
wp-packages-strategy
Prioritize official @wordpress packages over external dependencies. Detect React conflicts, use aliasing, and validate package usage.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Prioritize official @wordpress packages over external dependencies. Detect React conflicts, use aliasing, and validate package usage.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Apply approved architecture refactors by updating plan and task artifacts directly.
Perform a framework-agnostic architecture review validating implementation against spec.md, plan.md, tasks.md, and the governance and architecture constitutions.
Perform an architecture-aware verification gate validating implementation against spec.md, plan.md, tasks.md, and the Architecture Constitution.
Run a single architecture workflow that prefers memory-first context and can incorporate security review when available.
Run implementation with memory context, then review the produced implementation against security and architecture constraints.
Orchestrate a governed planning workflow that coordinates flash-mem, Security Review, and Architecture Guard validation.
| name | wp-packages-strategy |
| description | Prioritize official @wordpress packages over external dependencies. Detect React conflicts, use aliasing, and validate package usage. |
| compatibility | WordPress 6.0+, PHP 8.1+, @wordpress/scripts build pipeline |
Use this skill whenever:
@wordpress/* packagespackage.json lives).@wordpress/scripts, custom webpack, Vite, etc.).package.json → dependencies and devDependencies.node_modules/ is present (needed for duplicate-version detection).Before writing any interactive UI code:
references/wordpress-packages.md — does an official @wordpress/* package already cover the need?@wordpress/element is used instead of importing react directly.@wordpress/components is used for UI primitives before pulling in a UI library.@wordpress/data / @wordpress/store is used for state instead of Redux/Zustand.@wordpress/api-fetch is used for REST calls instead of axios/fetch wrappers.webpack.config.js aliases react → @wordpress/element if third-party libs are present.node skills/wp-packages-strategy/scripts/validate-packages.mjs --dir=.Before reaching for any external package, consult references/wordpress-packages.md.
WordPress ships ~70 packages as part of the block editor. Most common needs are covered:
| Need | Use this |
|---|---|
| React / JSX runtime | @wordpress/element |
| UI components | @wordpress/components |
| State management | @wordpress/data |
| REST API calls | @wordpress/api-fetch |
| Utility functions | @wordpress/compose, @wordpress/hooks |
| Icons | @wordpress/icons |
| Notices | @wordpress/notices |
See: references/wordpress-packages.md
Scan for direct React imports in the project:
node skills/wp-packages-strategy/scripts/validate-packages.mjs --dir=.
Or manually:
grep -r "from 'react'" src/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
grep -r "from \"react\"" src/ --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx"
grep -r "require('react')" src/ --include="*.js"
For every direct React import found, apply the replacement:
| Found | Replace with |
|---|---|
import React from 'react' | import { createElement } from '@wordpress/element' |
import { useState } from 'react' | import { useState } from '@wordpress/element' |
import { useEffect } from 'react' | import { useEffect } from '@wordpress/element' |
import ReactDOM from 'react-dom' | import { render, unmountComponentAtNode } from '@wordpress/element' |
import { createRoot } from 'react-dom/client' | import { createRoot } from '@wordpress/element' |
import { createPortal } from 'react-dom' | import { createPortal } from '@wordpress/element' |
See: references/wordpress-packages.md for the full replacement map.
If a third-party library (e.g. an Elementor React UI kit) imports react internally and
you cannot change its source, add webpack aliases so it resolves to the WordPress copy:
// webpack.config.js
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const path = require('path');
module.exports = {
...defaultConfig,
resolve: {
...defaultConfig.resolve,
alias: {
...defaultConfig.resolve?.alias,
'react': path.resolve('./node_modules/@wordpress/element'),
'react-dom': path.resolve('./node_modules/@wordpress/element'),
'react-dom/client': path.resolve('./node_modules/@wordpress/element'),
},
},
};
See: references/webpack-aliasing.md
Apply replacements across the codebase. For a plugin with a src/ directory:
# Preview changes (macOS/Linux)
grep -rn "from 'react'" src/
grep -rn "from 'react-dom'" src/
# Replace (example using sed on macOS)
find src -name "*.js" -o -name "*.jsx" | xargs sed -i '' \
"s/import React from 'react'/import { createElement } from '@wordpress\/element'/g"
Always verify the build still passes after replacements.
node skills/wp-packages-strategy/scripts/validate-packages.mjs --dir=.
The script checks:
react / react-dom imports in JS/JSX/TS/TSX source files@wordpress/element is present in package.jsonnode_modules/ (if present)Exit 0 = clean. Exit 1 = conflicts found with a remediation list.
After changes:
npm run build — must complete with no errors.npx webpack-bundle-analyzer build/stats.json
— confirm react is not in the bundle (only @wordpress/element should appear).node skills/wp-packages-strategy/scripts/validate-packages.mjs --dir=. exits 0.npm run build succeeds with no duplicate-React warnings.grep -r "from 'react'" src/ returns no results.react chunk.react. Add webpack aliases (Step 4) so all imports resolve to @wordpress/element.path.resolve(...)) not just a package name string.@wordpress/element missing from node_modules/ — run npm install; ensure @wordpress/scripts or @wordpress/element is in devDependencies.webpack.config.js spreads defaultConfig.resolve.alias before adding new entries; missing the spread drops built-in WP aliases.null due to missing data. Check browser console errors.@wordpress/element version in package.json must match the WordPress version running the site. Use @wordpress/dependency-extraction-webpack-plugin and wp_enqueue_script with the generated .asset.php manifest to let WordPress supply the correct version at runtime instead of bundling.See: references/webpack-aliasing.md, references/package-hierarchy.md
agents.md: https://github.com/WPBoilerplate/wordpress-plugin-boilerplate/blob/main/agents.md@wordpress packages list: https://developer.wordpress.org/block-editor/reference-guides/packages/@wordpress/scripts docs: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/@wordpress/element docs: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-element/