{"id":22614,"library":"vite-plugin-compile-time","title":"vite-plugin-compile-time","description":"A Vite plugin that evaluates JavaScript/TypeScript code at build time and inlines the result into the bundle. Version 0.4.6, actively maintained, with frequent releases. Supports both inline `compileTime()` calls and standalone `.compile.ts` files. Handles JSON-serializable data, RegExp, Date, Map, Set, BigInt, ArrayBuffer, TypedArray, Response, and Buffer. ESM-only, requires Node.js, compatible with Vite >=2.","status":"active","version":"0.4.6","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-plugin-compile-time","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-compile-time","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-compile-time","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency, plugin extends Vite's build pipeline","package":"vite","optional":false}],"imports":[{"note":"Default export is a function that returns the Vite plugin object.","wrong":"import { compileTime } from 'vite-plugin-compile-time'","symbol":"default","correct":"import compileTime from 'vite-plugin-compile-time'"},{"note":"Only works at top-level of a module; cannot be nested in closures or called dynamically.","wrong":"compileTime.call(null, expr)","symbol":"compileTime (runtime helper)","correct":"const data = compileTime(expression)"},{"note":"Add to tsconfig.json 'types' array, not as an import statement.","wrong":"import 'vite-plugin-compile-time/client'","symbol":"client types","correct":"/// <reference types=\"vite-plugin-compile-time/client\" />"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport compileTime from 'vite-plugin-compile-time'\n\nexport default defineConfig({\n  plugins: [compileTime()]\n})\n\n// source.ts\nimport fs from 'fs'\n\nconst content = compileTime(fs.readFileSync('./README.md', 'utf8'))\n\nexport { content }","lang":"typescript","description":"Shows how to add the plugin to Vite config and use compileTime to inline file content at build time."},"warnings":[{"fix":"Move any `compileTime()` call to the module's top-level scope.","message":"`compileTime()` must be called at the top level of a module, not inside a function or closure.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Only use Node.js APIs inside compile-time code. Use separate files for browser-related logic.","message":"File executed by `compileTime` runs in Node.js. Browser APIs like `document` or `window` are unavailable.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Export values directly without `compileTime` wrapper; the plugin handles evaluation automatically.","message":"`.compile.ts` files are evaluated as modules; importing them in runtime code triggers bundle splitting, not compile-time inlining.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure vite-plugin-compile-time is added to vite.config.ts and compileTime is imported correctly (default import).","cause":"Missing plugin registration or incorrect import","error":"Error: 'compileTime' is not defined"},{"fix":"Move compile-time code to a separate file or ensure it only uses Node.js APIs that work at build time.","cause":"Running code in browser environment where 'fs' is not available","error":"TypeError: fs.readFileSync is not a function"},{"fix":"Wrap async code in an async function and use `compileTime()` to inline the result, or use top-level await only if supported (Node >=14.8).","cause":"Using top-level await inside a `.compile.ts` file without proper async handling","error":"SyntaxError: await is only valid in async functions"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}