This is fork of WordPress plugin boilerpate combined with Roots Sage webpack build script. Plugin includes modified files from original WordPress Plugin Boilerplate version but with stripped comments which should save you time of renaming all classes and filenames and othere included information that is just waste of time.
Plugin Boilerplate generator kind of saves time but you still end up having to rename bunch of things before you can get started to actually do some work you would like to. To fight against name colisions PHP namespaces are included in this plugin so be sure to rename base namespace in all files.
Folder structure is still the same as the original, only difference is that assets are moved to 'dist' directory instead of having them separated for admin/public area.
Plugin includes composer.json file with example how to copy files from vendor directory to 'lib' directory. If you would like to manage php dependencies with composer, just include them in composer.json like you usually do and add them to 'CopyWebpackPlugin' in /assets/build/webpack.config.js L:130'. This will copy all of your plugin required files into 'lib' directory and you can then include them in your plugin from there. Not really sure would autoload work out of the box within WordPress plugins that are ment to be installed from WordPress repository via plugin installer.
- Sass for stylesheets
- ES6 for JavaScript
- Webpack for compiling assets, optimizing images, and concatenating and minifying files
- Browsersync for synchronized browser testing
Make sure all dependencies have been installed before moving on:
Fork or clone repository in your local dir
yarn
— navigate to the plugin directory and run yarncomposer install
— Install composer dependenciesyarn run build
- Initial buildyarn run start
- 'Watch'
From the command line on your host machine (not on your Vagrant development box), navigate to the theme directory then run yarn
:
# @ wp-plugins/your-plugin-name/
$ yarn
You now have all the necessary dependencies to run the build process.
yarn run start
— Compile assets when file changes are made, start Browsersync sessionyarn run build
— Compile and optimize the files in your assets directoryyarn run build:production
— Compile assets for production
yarn run rmdist
— Remove yourdist/
folderyarn run lint
— Run ESLint against your assets and build scriptscomposer test
— Check your PHP for PSR-2 compliance withphpcs
To use Browsersync you need to update devUrl
at the bottom of assets/config.json
to reflect your local development hostname.
If your local development URL is https://project-name.dev
, update the file to read:
...
"devUrl": "https://project-name.dev",
...
If you are not using Bedrock, update publicPath
to reflect your folder structure:
...
"publicPath": "/wp-plugins/plugin-name/"
...
By default, Browsersync will use webpack's HMR, which won't trigger a page reload in your browser.
If you would like to force Browsersync to reload the page whenever certain file types are edited, then add them to watch
in assets/config.json
.
...
"watch": [
"assets/scripts/**/*.js",
"templates/**/*.php",
"src/**/*.php"
],
...