This is an example plugin to showcase working of @wpackio/scripts
. It has
the following features.
- Using React and React Hot Loader for best in kind DX.
- Using Sass on react components.
- Multiple entry points along with webpack multi-compiler.
- Custom implementation of Hot Module Replacement.
-
Clone this repository.
-
Make sure you have docker and composer installed on your machine.
-
Install all composer dependency (just
wpackio/enqueue
in our case).composer install
-
Run the following command from this directory
examples/plugin
.docker-compose up -d && docker-compose logs -f wordpress
Wait until the build is complete. Then press ctrl + c.
Now run
yarn start
Or if you are using npm
npm start
This will open up the development server within your network LAN Ip address.
Note that due to how
file:
dependency works withnpm
, it might throw some error. We recommend usingyarn
, until the issue is resolved. This is just for checking out this demo. In your own project, bothnpm
andyarn
will work fine. -
Now log into your WordPress dashboard with: a. Username:
root
b. Password:root
-
Activate
WPack.io Sample Plugin Development
plugin. -
Check the homepage and check your browser's console.
-
Publish a page with a shortcode
[wpackio-reactapp]
. -
Check the page content.
It is not a requirement to use docker for
@wpackio/scripts
. It is just required for this example. You can very well spin up any local server you are comfortable with.
Now go ahead and edit the contents in file src/app/modules/logger.js
. Check it
load live in your console.
If you edit any of the entrypoints like src/app/index.js
, then you will see
full page reload.
With the help of browsersync, we also watch for files inside inc/**/*.php
. So
go ahead and edit them. The page will reload.
We have created a simple shortcode [wpackio-reactapp]
. Publish it in any page
and this will create a todo app.
Edit files under src/reactapp/
and see them refresh live (without page reload).
This is done with the help of react-hot-loader.
Run
yarn build