Plugin Template
@ailura/alpinejs-plugin-template
Copy-paste scaffold for new toolkit packages. It is a demo package — never published —
and it ships a single-file example (src/index.ts plus the alpine.d.ts store
augmentation). Every real package then grows out of it into this canon:
src/ index.ts # barrel only — re-exports, no logic types.ts # public contracts + DEFAULT_*_KEY constants controller.ts # extends BaseController, owns state, emits 'change' plugin.ts # factory xxxPlugin(options) => (alpine) => void + guards events.ts # typed Events map + ChangeDetail store.ts # store creation + reactive sync (packages that ship a store)Scaffold a plugin
Section titled “Scaffold a plugin”pnpm run new:plugin -- my-plugin# creates packages/my-plugin from packages/plugin-template,# renames plugin-template → my-plugin and pluginTemplate → myPlugin,# and prints the tsconfig reference you still have to add by hand.The canon
Section titled “The canon”index.tsis a pure barrel. It re-exports; it defines nothing. Logic here means something is leaking to the public surface.types.tsis the boundary. Everything a consumer can touch, plus theDEFAULT_*_KEYconstants.controller.tsowns the state. It does not import Alpine and it does not touch the DOM. The framework only gets connected inplugin.ts.plugin.tsdoes three things, in order. Claim the name with the guard, sync the state, return the callback. Nothing else.events.tsis the event map. Every event with its typed payload, in one file.store.tsowns the store projection. A package that registers a store creates it there;plugin.tsonly registers the result and wires the sync.
Pre-merge checklist
Section titled “Pre-merge checklist”-
package.json:type:module,sideEffects:false,exportswithtypes+import, a single entry,files:["dist"], and thebuild/test/typecheck/sizescripts. -
vite.config.ts:deps.neverBundleforalpinejsand the core peer, so they stay out of the bundle. -
controller.ts: noalpinejsimports, nowindow/documentaccess. -
plugin.ts:guardStore/guardMagicwith a literalpackageName. -
index.ts: a pure barrel. - Tests: the
@ailura/alpinejs-testingpattern, withstartonce per file andresumein eachbeforeEach. - Size within the
.size-limit.jsonbudget. - README and
ARCHITECTURE.mdupdated.
Reference canon
Section titled “Reference canon”The accordion package is the reference feature implementation:
packages/accordion/src/ controller.ts # accessible AccordionController plugin.ts # factory + guards + reactive sync types.ts # options + DEFAULT keys store.ts # store creation + registry sync events.ts # typed events