AlpineJS components
Frontend
brush/src/components/hello-world.ts
brush/src/components/index.ts
brush/src/components/index.ts
Creating and using AlpineJS components requires 3 steps: create the component, declare it, use it in Liquid.
Create a component
Section titled “Create a component”- Create a new
.tsfile in your theme’s Brush directory. Example:brush/src/components/hello-world.ts - Build it like a standard AlpineJS component:
export default function () { Alpine.data("HelloWorld", () => ({ message: "Hello world!", }));}Declare the component
Section titled “Declare the component”- Update the
brush/src/components/index.tsfile to declare your component.
import HelloWorld from "./hello-world";
export function registerAlpineComponents() { HelloWorld(); // Add components here}Use the component in a Liquid file
Section titled “Use the component in a Liquid file”<div x-data="HelloWorld()"><span x-text="message"></span></div>