This repository demonstrates how the vite-wordpress node package and vite-wordpress-php composer package can be used within a WordPress plugin to create a block.
-
Clone repo into a new plugin folder called
create-vite-block -
Install the composer package
composer install
-
In your local environment, install the node packages via npm or yarn:
npm install # or yarn install -
Create an initial build from the uncompiled files.
npm run build # or yarn build -
Start development server on your local environment
npm run start # or yarn start -
Ensure you refresh the WordPress page you're on (once) so the page loads the injected Vite client.
If you're not using a traditional WordPress setup or want to use a different plugin folder/name, update the base in vite.config.js.
When using a local environment like DDEV, make sure to install the Node packages on the server via SSH and ensure the ports are exposed.
(Default port configured in Vite: 5173).
For DDEV, you can use the following addon: https://github.com/mrOttoW/ddev-wordpress-vite