A Vite plugin (v4+) that generates virtual modules at bundle time, useful for injecting configuration, metadata, or generated code without a separate build step. Current stable version is 2.1.0, with monthly releases. Ships TypeScript types. Supports ESM-only; designed specifically for Vite 4+. Key differentiator: generates virtual modules on-the-fly, eliminating the need for pre-build scripts or file I/O.
npm install vite-plugin-codegenVerified import paths — ran on the pinned version, not inferred.
Shows how to configure the plugin in vite.config.ts and use a generated virtual module in app code.
Use named import: import { codegen } from 'vite-plugin-codegen'.Use 'virtual:' prefix for all generated module ids.
Use ESM imports or ensure your project is configured for ESM.
Update plugin configuration to new object format.
Add 'virtual:' prefix to the module id.
Change to named import: import { codegen } from 'vite-plugin-codegen'.Switch to ESM imports or set project type to module in package.json.