Skip to content

Add a @wordpress/scripts asset build pipeline#41

Merged
GaryJones merged 4 commits into
mainfrom
GaryJones/asset-pipeline
Jun 11, 2026
Merged

Add a @wordpress/scripts asset build pipeline#41
GaryJones merged 4 commits into
mainfrom
GaryJones/asset-pipeline

Conversation

@GaryJones

Copy link
Copy Markdown
Owner

Removing the dead BrightNucleus Dependencies wiring left the boilerplate with no story for shipping JavaScript or CSS, which is one of the things people most often come to a reference plugin to copy. This restores that story using the modern WordPress toolchain.

@wordpress/scripts builds src/js/admin-settings.js (a small character counter on the example settings field) into build/. Importing @wordpress/dom-ready and @wordpress/i18n shows how those become wp-dom-ready and wp-i18n entries in the generated admin-settings.asset.php, and the imported stylesheet is extracted alongside it with an automatic RTL variant. The webpack config extends the @wordpress/scripts default rather than replacing it, so only the entry point is overridden.

On the PHP side, Plugin::enqueue_admin_assets() loads the bundle only on the plugin's own settings screen and reads the generated asset file for the dependency list and version, so neither is hand-maintained, with wp_set_script_translations() wiring up JavaScript translations. The asset paths live in the config beside the view paths, which keeps the runtime constants out of the analysed class and lets it degrade gracefully before the first build.

Built files are not committed; .gitignore covers build/ while .gitattributes and .distignore ship the compiled output but exclude its source, and the deploy workflow runs the build so releases stay ready to install. Unlike composer.lock, package-lock.json is committed so the build is reproducible, which the npm Dependabot ecosystem in the CI refresh already maintains.

Stacked on #39, since it builds on that branch's Plugin class and settings page; it retargets to main automatically once #39 merges. The new enqueue method is covered so the mutation score gate from #40 stays at 100%.

Restores a JavaScript/CSS build so the boilerplate demonstrates the
modern WordPress asset workflow. Source lives in src/js and the webpack
config extends the @wordpress/scripts default rather than replacing it.
Built output and package-lock.json are handled so releases stay ready to
install and reproducible while built files themselves are not committed.
Plugin::enqueue_admin_assets() loads the script and style only on the
plugin's own settings screen, reading build/admin-settings.asset.php for
the dependency list and version so neither is maintained by hand. It
degrades gracefully before the first build and registers the generated
RTL stylesheet.
Exercises both the on-screen guard and the exact script, style,
translation and RTL registration calls, keeping the mutation score gate
green now that Plugin gained the enqueue method.
Without a build step the release would ship the JavaScript source but no
compiled bundle. Documents the npm workflow in the README alongside it.
Base automatically changed from GaryJones/plugin-correctness to main June 11, 2026 18:00
@GaryJones GaryJones merged commit 87463ed into main Jun 11, 2026
3 checks passed
@GaryJones GaryJones deleted the GaryJones/asset-pipeline branch June 11, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant