🧩 html-scoped-component-importer

Bind TypeScript classes to HTML with a data-component attribute. Components load on demand, talk through an event bus, share state, and tell you what they are doing in a friendly log.

npm install html-scoped-component-importer ⭐ GitHub npm

The whole idea in 30 seconds

Mark an element, write a class that receives it, start a dispatcher. This greeting is a real component loaded right now:

<div data-component="Greeting"></div>
// components/Greeting.ts
export default class Greeting {
  constructor(element: HTMLElement, dispatcher: ComponentDispatcher) {
    element.textContent = 'Hello!';
  }
}

// main.ts
import { ComponentDispatcher } from 'html-scoped-component-importer';

const dispatcher = new ComponentDispatcher();
await dispatcher.importAsyncComponents();
dispatcher.observeDomChanges();

Explore

Each page focuses on one feature, with live examples and the code behind them.