There are few steps necessary to prepare a plugin for release on the WordPress.org plugin directory. We use Gulp 5 to automate this.
- Download and install Node.js and npm (Node.js 18+ required for Gulp 5).
- Install Gulp CLI using
npm install -g gulp-cli. - In the plugin folder, ensure the plugin-build repository has been added as a submodule in a folder called 'build' and is up to date. This can be done using
git submodule add [email protected]:siteorigin/plugin-build.git build. - In a terminal, navigate to the build directory in the plugin and run
npm install. When using plugin-build in the SiteOrigin CSS plugin,npm installshould be run in both the SiteOrigin CSS plugin folder and the build folder. - Get some coffee while npm installs the required packages.
Each plugin has it's own slug and different files needed for a build. So any plugin that uses this build is required to have a configuration file called build-config.js in the root of the plugin directory. This file is in the form of an npm module which simply returns a configuration object used by the gulpfile to determine the files and folders needed for the build. Below is an excerpt from the SiteOrigin CSS Editor plugin build-config.js file:
module.exports = {
slug: 'so-css',
jsMinSuffix: '.min',
version: {
src: [
'so-css.php',
'readme.txt'
]
},
less: {
src:['css/**/*.less'],
include:[]
},
};
There are two main build tasks, build:release and build:dev.
The release task performs the following subtasks:
- Updates the version number in the required files.
- Compiles required SASS and LESS files to CSS.
- Processes JavaScript files with Babel and Browserify.
- Minifies CSS and JavaScript files.
- Copies all files to a
dist/folder. - Generates translation (POT) files.
- Creates a
.ziparchive with the appropriate filename ready for uploading to wordpress.org.
Release task usage:
npm run build:release --release=1.2.3
The development build task includes:
- Initial compilation of LESS/SASS files to CSS.
- Initial processing of JavaScript files.
- Watch LESS, SASS, and JavaScript files for changes and recompile automatically.
Development task usage:
npm run build:dev
You can also run individual build tasks:
npm run css # Compile LESS/SASS files npm run js # Process JavaScript files npm run minify # Minify CSS and JS files npm run copy # Copy files to tmp directory npm run i18n # Generate translation files
npm run update:font-awesome
npx cross-env gulp updateGoogleFontsTask --apiKey=YOUR_API_KEY
The Google Fonts task will require an update to the build-config file in each plugin to specify the name and location of the fonts file.
This build system has been migrated from Gulp 3 to Gulp 5 with the following key changes:
- ES Modules: All tasks now use ES module syntax instead of CommonJS.
- Task Binding: Individual tasks require explicit binding for proper configuration passing.
- Copy Patterns: Updated glob patterns for better file selection and exclusion handling.
- Dependencies: Updated to use
gulp-terserinstead ofgulp-uglify-esand modern package versions.
If you encounter issues:
- Ensure Node.js 18+ is installed.
- Clear
node_modulesand runnpm installagain. - Check that all required files exist in the plugin's
build-config.js. - Verify that the build directory has proper read/write permissions.