@triggery/vite
Vite plugin that auto-discovers every *.trigger.ts file in your project and registers it at app startup. One import of virtual:triggery-registry at the entry point and every trigger is live — no manual import wiring. HMR-aware: editing a trigger re-runs createTrigger(...), adding or renaming files invalidates the virtual module.
Install
Section titled “Install”pnpm add -D @triggery/vite npm install --save-dev @triggery/vite yarn add --save-dev @triggery/vite bun add -D @triggery/vite Peer deps: vite ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0.
What’s inside
Section titled “What’s inside”| Export | Purpose |
|---|---|
triggery(options?) (default) | The Vite plugin. Returns a Plugin you drop into the plugins array. |
virtual:triggery-registry | Side-effect virtual module that imports every matched file. |
Quick example
Section titled “Quick example”vite.config.ts
import { defineConfig } from 'vite';
import triggery from '@triggery/vite';
export default defineConfig({
plugins: [triggery({ glob: 'src/**/*.trigger.ts' })],
});src/main.tsx
import 'virtual:triggery-registry';
// ...rest of your bootstrapThat’s the full setup. Every file matching the glob is auto-imported, so its top-level createTrigger(...) call registers with the default runtime.
Options
Section titled “Options”| Option | Default | Description |
|---|---|---|
glob | 'src/**/*.trigger.{ts,tsx,js,jsx}' | One pattern or an array. Anything tinyglobby accepts. |
- Editing an existing trigger file just re-runs its
createTrigger(...)— the runtime’s last-mount-wins replaces the old registration. No special handling needed in your app code. - Adding / removing / renaming a trigger file invalidates the virtual module so its import list is rebuilt on the next request.
Type declaration
Section titled “Type declaration”Add a single ambient declaration so TypeScript knows about the virtual module:
src/vite-env.d.ts
/// <reference types="vite/client" />
declare module 'virtual:triggery-registry';Related packages
Section titled “Related packages” @triggery/core The runtime that registered triggers attach to.
@triggery/react Most common pairing for Vite + React apps.
@triggery/solid Pairs with vite-plugin-solid.
@triggery/vue Pairs with @vitejs/plugin-vue.
@triggery/cli triggery graph reads the same *.trigger.ts files.