LogoPixi’VN
viteFunctions

Function: vitePluginNqtr()

> vitePluginNqtr(options?): Plugin

Defined in: src/vite/index.ts:222

Creates a Vite plugin that generates TypeScript declaration files with compile-time–safe ID types for all six NQTR entity registries: activities, commitments, locations, maps, quests, and rooms.


How it works

At startup (and after every hot-module reload), the plugin executes the content modules listed in the options server-side via Vite SSR. Those modules register entities by calling RegisteredActivities.add(...), RegisteredRooms.add(...), etc. The plugin then reads back the IDs from all six registries and writes a .d.ts declaration file that augments the Nqtr*Ids interfaces in @drincs/nqtr/registries.


Pixi-VN integration

If vitePluginPixivn (from @drincs/pixi-vn/vite) is present in the same Vite config, this plugin automatically waits for its contentLoaded signal before reading registry state. This means you can pass a single content barrel file to vitePluginPixivn and have both plugins read from it without duplicating the option:

// vite.config.ts
import { vitePluginPixivn } from "@drincs/pixi-vn/vite";
import { vitePluginNqtr } from "@drincs/nqtr/vite";

export default defineConfig({
  plugins: [
    vitePluginPixivn({ content: "./src/content/index.ts" }),
    vitePluginNqtr({ typeFilePath: "./src/nqtr.keys.gen.ts" }),
  ],
});

The nqtr plugin will piggy-back on pixi-vn's content loading and re-run type generation on every hot-reload triggered by the pixi-vn plugin.


Standalone usage (without pixi-vn)

Target specific entity files directly:

vitePluginNqtr({
  activities:   "./src/activities/*.ts",
  rooms:        "./src/rooms.ts",
  locations:    "./src/locations.ts",
  maps:         "./src/maps.ts",
  typeFilePath: "./src/nqtr.keys.gen.ts",
})

Generated file

The file written to VitePluginNqtrOptions.typeFilePath looks like:

// nqtr.keys.gen.ts  — auto-generated, do not edit manually
export const nqtrActivityIds = ["study", "cook"] as const;
export const nqtrRoomIds = ["bedroom", "kitchen"] as const;
// …

declare module "@drincs/nqtr/registries" {
    interface NqtrActivityIds { "study": never; "cook": never; }
    interface NqtrRoomIds     { "bedroom": never; "kitchen": never; }
    // …
}

The as const arrays can be passed to createNqtrHandler for runtime validation of Ink hashtag commands. The declare module augmentation narrows the *IdType helpers (ActivityIdType, RoomIdType, …) from string to the union of known literal IDs at compile time.

Parameters

options?

VitePluginNqtrOptions

Optional plugin configuration.

Returns

Plugin

A Vite plugin.

On this page