Webflow module creation

From vallafederico/webflow-dev-setup · View interactive version

Webflow module creation is an AI agent skill from the GitHub repository vallafederico/webflow-dev-setup. Create and register custom JavaScript modules for Webflow projects. Use when creating new functionality, adding data-module attributes, or structuring component logic.

How to use this skill

Skill file

Webflow Module Creation

This skill guides you through creating and registering custom modules that are automatically mounted based on DOM attributes.

Core Principles

Module Template

pnpm new:module <name> writes a module like this one, which already passes every rule:

import { onMount, onDestroy } from "@/modules/_";

/**
 * @param element The DOM element with the data-module attribute
 * @param dataset The data attributes of the element
 */
export default function (element: HTMLElement, dataset: DOMStringMap) {
  // Setup logic here

  onMount(() => {
    // Initialization code
  });

  onDestroy(() => {
    // Cleanup code
  });
}

Step-by-Step Creation

  1. Create the File: Run pnpm new:module my-component, or add a new .ts file in src/modules/ (e.g., src/modules/my-component.ts).
  2. Implement the Function: Export a default function with the signature (element: HTMLElement, dataset: DOMStringMap) => void. Fewer parameters are fine.
  3. Register in HTML: Add the data-module="my-component" attribute to the target element in Webflow/HTML.
  4. Access Data: Use the dataset parameter to access data- attributes passed from the DOM.
  5. Check: Run pnpm check. A module that uses Raf.add, onView or GSAP must also call onEditor (see the editor skill), and everything it subscribes to must be undone in onDestroy.

Best Practices

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.