Sample WordPress plugin for setting up a project with Yarn, Webpack, BrowserSync and React. Tailored to creating a wp-admin page, but completely flexible and can be used for themes as well.
Companion blog post: https://deliciousbrains.com/develop-wordpress-plugin-webpack-3-react/
- Fork repo to your Github account
- Clone repo to your
wp-content/plugins
folder - In
config.json
change theproxyURL
to match the admin url of the plugin page,http://pmpro.local/wp-admin/index.php?page=pmpro-react-demo
. - In your host WordPress
wp-config.php
file adddefine( 'PMPRO_AJAX_BASE', 'http://pmpro.local/wp-json/pmpro/v1' );
and update it to point to your REST API base - Modify any WordPress config in
pmpro-react-demo.php
. Rename files/methods/strings as necessary. - Activate the plugin in wp-admin
- Navigate to the the admin url of the plugin page,
http://pmpro.local/wp-admin/index.php?page=pmpro-react-demo
. - The page should be blank.
- Open Terminal.
cd
into your plugin's folder and runyarn
- Run
yarn start
to get Webpack and BrowserSync running - A proxy window should open your plugin page,
http://pmpro.local/wp-admin/index.php?page=pmpro-react-demo
, athttp://localhose:3000/wp-admin/index.php?page=pmpro-react-demo
, and you should see your WP Options in an editable table.
yarn build
A production-ready WordPress plugin will be built in the pmpro-react-demo-built
folder.