homepage-header-3
v0.0.1
Published
This project contains the PixiJS-powered hero header that we mount onto the Big Mugs WordPress site. The codebase is a standard Vite + Solid project that outputs an embeddable bundle under `dist/`. The intent is to ship this bundle as an npm package and l
Readme
Big Mugs Hero Header
This project contains the PixiJS-powered hero header that we mount onto the Big Mugs WordPress site. The codebase is a standard Vite + Solid project that outputs an embeddable bundle under dist/. The intent is to ship this bundle as an npm package and load it on the WordPress site via a public CDN.
Local development
npm install
npm run devOpen http://localhost:5173 to iterate on the header in isolation. Update the assets under src/ as needed, and keep the public API of your entry file stable so that the bundle can be mounted in WordPress without code changes.
Preparing the package for npm
- Update package metadata
- Choose an npm-safe name (for example,
@big-mugs/hero-header). - Remove the
"private": trueflag inpackage.json. - Set an appropriate
version,description,author,license, andrepositoryfield. - Point
main,module, andtypes(if you ship definitions) to the built files underdist/. - Add an
exportsmap if you want to control what consumers can import.
- Choose an npm-safe name (for example,
- Verify the entry point
- The
dist/output should expose a function that mounts the header into a DOM element. - Confirm any CSS or assets referenced in the bundle are included.
- The
- Build the package
- Run
npm run buildto produce the production bundle indist/. - Optionally, inspect the output and test it locally by loading
index.htmland manually invoking the exported function.
- Run
- Authenticate with npm
- Run
npm login(ornpm login --registry https://registry.npmjs.orgif you use a different default registry). - Ensure you have publish rights to the chosen scope.
- Run
- Publish
- Bump the version number following semantic versioning (
npm version patch|minor|major). - Run
npm publish --access publicto push the build to npm. - Tag the release in git once the publish succeeds.
- Bump the version number following semantic versioning (
Consuming the package from a CDN
After publishing, the bundle can be served from an npm CDN such as jsDelivr or unpkg. Below is an example using jsDelivr:
<script type="module">
import mountHeroHeader from "https://cdn.jsdelivr.net/npm/@big-mugs/[email protected]/dist/index.js";
document.addEventListener("DOMContentLoaded", () => {
const target = document.getElementById("big-mugs-hero-root");
mountHeroHeader(target, { /* custom options */ });
});
</script>Update the URL with the published package name and version. You can omit the version (@latest) while testing, but pinning a version is recommended for production stability.
Loading the header in WordPress
Register a container element in your theme or block markup, e.g.
<div id="big-mugs-hero-root"></div>.Enqueue the CDN script in WordPress:
function big_mugs_enqueue_hero_header() { wp_enqueue_script( 'big-mugs-hero-header', 'https://cdn.jsdelivr.net/npm/@big-mugs/[email protected]/dist/index.js', [], null, true ); } add_action( 'wp_enqueue_scripts', 'big_mugs_enqueue_hero_header' );Use
wp_add_inline_scriptif you need to pass configuration before mounting.Invoke the mount function either inline (via
wp_add_inline_script) or inside your theme JavaScript bundle after the CDN module loads.
Ensure cache busting by updating the version in the CDN URL whenever you publish a new release. Consider setting up automated integration tests to confirm the WordPress page loads the header correctly after each publish.
