🐗 Building WordPress plugins with an increasingly verbose Gruntfile

When building WordPress plugins, I’m using gruntjs for all my project tooling needs. I am always aiming for a hierarchical Gruntfile.js structure that reminds me of increasingly verbose memes. And you should, too.

No matter which tool you’re using, building, testing, packaging and deploying a WordPress plugin should be one command. That way when you’re dev testing, you are actually testing the whole process, including installation, activation and deactivation of the plugin’s zip file. grunt-shell and wp-cli are your friends. Use wp option liberally in your dev deployment code.

My Gruntfile.js describes all the steps needed between my code sitting in my working directory and the same code running in my WordPress dev environment.

Grunt alias tasks let you define this process hierarchically. Use them! I aim to model the process so that at some level it has some resemblance to steps from the waterfall model: build, package, test, and deploy are verbs that I always aim to define in my script. Then, at a lower level I can define which grunt plugins actually accomplish each step.

When you have defined the steps in this way, then you can begin to create builds of varying quality or for various purposes. Testing takes too long to run every time in your development cycle? Create a quick build that excludes it. Want to have separate builds with and without documentation included? Define another package verb. Want to create a deliverable package but not deploy it? Create a task that omits the deploy verb.

The following is from an actual project I’m working on. Don’t worry about the details. You have your own workflow. All I’m saying is that you will benefit from structuring your script hierarchically.

Here’s my increasingly verbose meme. Make it viral!

Increasingly verbose Gruntfile

1 thought on “🐗 Building WordPress plugins with an increasingly verbose Gruntfile

Leave a Reply

Your email address will not be published. Required fields are marked *