A CLI scaffolding tool for quickly setting up a WordPress component project powered by vite-plugin-wp-component.
This tool generates the project boilerplate with: - Pre-configured Vite and PostCSS settings.
- A ready-to-use index.html with the correct
rootID
injected. - An empty
.env
for FTP credentials. - Built-in npm scripts that map to
vite-plugin-wp-component
commands.
You can create a new project using npm
or npx
:
npx create-wp-component
cd my-component
npm install
The CLI automatically registers the following scripts in package.json
:
npm run config
→ Runswp-component config
(edit.env
orcomponent.config.json
).npm run build
→ Runsvite build
andwp-component build
(bundles your project and generates the plugin PHP file in one step).npm run deploy
→ Runswp-component deploy
(deploys via FTP to your WordPress site).
A newly scaffolded project has the following structure:
Project/
├──index.html // Preconfigured with __COMPONENT_CONFIG__.rootID
└── src/
├── assets/ // Directory for external/static files
│ └── javascript.webp
├── generator.js // Core component logic
├── info.json // Data consumed by generator (can be local or fetched remotely)
├── main.js // Entry point, mounts the component into the rootID
├── styles.module.css // CSS Modules stylesheet
└── template.js // Example of importing assets & styles
-
main.js
Accesses__COMPONENT_CONFIG__.rootID
and renders your component inside the root element. -
styles.module.css
Uses CSS Modules to ensure class encapsulation and isolation.
Class names follow this structure:[componentName]__[local]___[hash:base64:5]
They are automatically transformed from
class-css
toclassCss
, so you can import them in JavaScript as:import styles from "./styles.module.css"; element.className = styles.classCss;
-
generator.js
Contains the core logic of the component, which is invoked frommain.js
. -
info.json
Provides configuration or data forgenerator.js
.
This can be a static file or dynamically fetched from an external server. -
template.js
Demonstrates how to import assets from/assets
and styles fromstyles.module.css
.
-
Configure FTP credentials and metadata:
npm run config
-
Build the bundle and generate the WordPress plugin PHP:
npm run build
-
Deploy the plugin directly to WordPress:
npm run deploy
- The scaffold ensures that the same rootID is used across development and production (in sync with
vite-plugin-wp-component
). - CSS Modules are essential for encapsulation — no class name collisions with WordPress themes or other plugins.