Installation
You can install in your WordPress project using npm, yarn or pnpm.
Keep in mind that react
and react-dom
is set as peer dependencies, requires version 18 or the later. So make sure that you have them installed and set them as the dependencies in your project.
Usage
Once installed, you should be able to import and use all available components from the package.
Compiling the Source Files
Before you can enqueue the script file in your WordPress project, you’ll need to compile the source files so that browser would be able to render the application. We recommend using the @wordpress/scripts
package for this, as it comes with WordPress-specific configurations out of the box.
@wordpress/scripts
is an official package from the WordPress project. It contains a set of scripts to help you build, test, lint your code, and requires minimal configuration to get you started.
First, you will need to install it as the project development dependency:
Add the following scripts to your package.json
file:
Now you can run the following command to compile the source files:
By default, the script will read the entry file from src/index.js
and output the compiled files to build
directory. You can also specify the output path by passing the --output-path
flag:
To customize it more, please refer to the official documentation.