Add a @wordpress/scripts asset build pipeline#41
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/scriptsbuildssrc/js/admin-settings.js(a small character counter on the example settings field) intobuild/. Importing@wordpress/dom-readyand@wordpress/i18nshows how those becomewp-dom-readyandwp-i18nentries in the generatedadmin-settings.asset.php, and the imported stylesheet is extracted alongside it with an automatic RTL variant. The webpack config extends the@wordpress/scriptsdefault 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, withwp_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;
.gitignorecoversbuild/while.gitattributesand.distignoreship the compiled output but exclude its source, and the deploy workflow runs the build so releases stay ready to install. Unlikecomposer.lock,package-lock.jsonis 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%.