Skip to content

@hamur/alpine

Alpine.js in html apps. Add it to modules and set its option under the alpine config key; alpinejs (^3) is a peer dependency you install.

ts
import { defineConfig } from "hamur"
import alpine from "@hamur/alpine"

export default defineConfig({
  framework: "html",
  modules: [alpine],
  alpine: { entrypoint: "./app/alpine.ts" },
})

default

The module, as defineModule({ meta: { name: "@hamur/alpine", configKey: "alpine", compatibility: { frameworks: ["html"] } } }). An app on another adapter fails the build with Module "@hamur/alpine" supports html; this app uses react; the module throws nothing of its own. Its setup checks alpine, writes the template alpine/entrypoint and adds @hamur/alpine/client as a client app plugin, so a script-free page, which loads no client code, gets no Alpine.

@hamur/alpine/client

The client app plugin the module adds; an app never imports it. On app:mounted it imports alpinejs, runs the entrypoint with Alpine and awaits it, sets window.Alpine and calls Alpine.start() once. It calls neither Alpine.initTree nor Alpine.destroyTree: Alpine's own observer handles the page swaps of client navigations.

AlpineOptions

KeyTypeDefault
entrypointstringnone: a file from the app root whose default export is (Alpine) => void | Promise<void>, run before Alpine.start()

Load errors: alpine.entrypoint must be a string (got 3) and alpine.entrypoint "./app/alpine.ts" does not exist.