Registry / devops / vite-plugin-codegen

vite-plugin-codegen

JSON →
library2.1.0jsnpmunverified

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-codegen
INSTALL
IMPORT
SIG · VITE-PLUGIN-CODEGE
V
vite-plugin-codegen
devopsjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

codegen
import { codegen } from 'vite-plugin-codegen'
import codegen from 'vite-plugin-codegen'
Named export only; default export is not available.
CodegenOptions
import type { CodegenOptions } from 'vite-plugin-codegen'
Type import for TypeScript users.
CodegenModule
import type { CodegenModule } from 'vite-plugin-codegen'
Type import for defining virtual modules.

Shows how to configure the plugin in vite.config.ts and use a generated virtual module in app code.

import { codegen } from 'vite-plugin-codegen'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ codegen({ modules: [ { id: 'my-module', generate: () => `export const message = 'Hello, World!';` } ] }) ] }); // In your application code, import the virtual module: // import { message } from 'virtual:my-module';
Debug
Known issues
breakingv2.0.0 moved core logic to 'codegen-lib' and restructured exports; default import removed.
fix
Use named import: import { codegen } from 'vite-plugin-codegen'.
affects: >=2.0.0
gotchaVirtual module IDs must be prefixed with 'virtual:' or the plugin will not resolve them.
fix
Use 'virtual:' prefix for all generated module ids.
affects: >=1.0.0
gotchaOnly ESM output is supported; CJS require() will fail.
fix
Use ESM imports or ensure your project is configured for ESM.
affects: >=2.0.0
deprecatedThe old 'generate' function signature from v1 is removed; use the new object format with 'id' and 'generate'.
fix
Update plugin configuration to new object format.
affects: >=2.0.0
Errors
Common errors & fixes
Error: [vite-plugin-codegen] Virtual module id must start with 'virtual:'
Module ID missing the required prefix.
fix
Add 'virtual:' prefix to the module id.
TypeError: codegen is not a function
Using default import (common mistake after v2 breaking change).
fix
Change to named import: import { codegen } from 'vite-plugin-codegen'.
Error: require() of ES Module not supported
CJS require() used for ESM-only package.
fix
Switch to ESM imports or set project type to module in package.json.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
viterequiredpeer dependency – plugin designed for Vite 4+
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vite-plugin-codegen — npm install vite-plugin-codegen · libregistry