Skip to content
GitHubXDiscord

@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.

npm bundle

pnpm add -D @triggery/vite

Peer deps: vite ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0.

ExportPurpose
triggery(options?) (default)The Vite plugin. Returns a Plugin you drop into the plugins array.
virtual:triggery-registrySide-effect virtual module that imports every matched file.
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 bootstrap

That’s the full setup. Every file matching the glob is auto-imported, so its top-level createTrigger(...) call registers with the default runtime.

OptionDefaultDescription
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.

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';