[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-11392":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":13,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":14,"stars7d":14,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":17,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":13,"lastSyncTime":26,"discoverSource":27},11392,"comptime","lukeed\u002Fcomptime","lukeed","A Zig-inspired build-time evaluation primitive, exposed as Vite and Rolldown plugins","",null,"TypeScript",168,2,1,0,11,3,1.43,"MIT License",false,"main",[],"2026-06-12 02:02:31","# comptime\n\n> A Zig-inspired build-time evaluation primitive, exposed as Vite and Rolldown plugins.\n\n```ts\nimport { comptime } from \"comptime\";\nimport { fibonacci } from \".\u002Fmath\";\n\nexport const value = comptime(() => fibonacci(10));\n```\n\nWith the plugin enabled, the call is evaluated during the build and replaced with a serialized expression:\n\n```ts\nexport const value = 55;\n```\n\nIf the plugin is not enabled, the runtime helper throws so missed transforms fail loudly.\n\n> View [more complex examples](\u002Fexamples\u002F)\n\n## Install\n\n```sh\n# via rolldown\nbun add --dev comptime rolldown\n\n# via vite\nbun add --dev comptime vite\n```\n\n## Vite\n\n```ts\nimport { defineConfig } from \"vite\";\nimport { comptime } from \"comptime\u002Fvite\";\n\nexport default defineConfig({\n  plugins: [comptime()],\n});\n```\n\n## Rolldown\n\n```ts\nimport { defineConfig } from \"rolldown\";\nimport { comptime } from \"comptime\u002Frolldown\";\n\nexport default defineConfig({\n  input: \"src\u002Fapp.ts\",\n  plugins: [comptime()],\n});\n```\n\n## API\n\n```ts\nimport { comptime } from \"comptime\";\n\nlet value = comptime(() => expensivePureWork());\n```\n\n`comptime\u003CT>(fn: () => T | Promise\u003CT>): T` is typed as an identity helper. The plugin requires a single zero-argument arrow function or function expression.\n\nSupported behavior:\n\n- Imported `comptime` bindings from `\"comptime\"`, including aliases.\n- Shadowed local bindings are ignored.\n- Referenced value imports are captured into virtual modules with absolute import paths.\n- Referenced top-level declarations from the origin module are copied into the virtual module.\n- Promise-returning bodies are awaited.\n- Values are serialized with `devalue`.\n- Build errors include the original call-site location.\n- Vite dev uses `server.ssrLoadModule`; Vite build and Rolldown build use an internal Rolldown evaluator.\n\n## Options\n\n```ts\ntype ComptimeOptions = {\n  include?: string | string[];\n  exclude?: string | string[];\n  timeout?: number;\n  env?: string[] | \"all\" | \"declared\";\n  serializers?: Array\u003C{\n    test: (value: unknown) => boolean;\n    serialize: (value: unknown) => string;\n  }>;\n};\n```\n\nDefaults:\n\n- `timeout`: `10_000`\n- `env`: `\"all\"`\n\nWhen `env` is a string list, static `process.env.KEY` reads must be listed. Dynamic env reads are rejected unless `env` is `\"all\"`.\n\n## Common Errors\n\nThese fail during transform:\n\n```ts\ncomptime(1);\n\u002F\u002F comptime() requires a single arrow function with no parameters\n```\n\n```ts\ncomptime((value) => value);\n\u002F\u002F comptime() requires a single arrow function with no parameters\n```\n\n```ts\ncomptime(() => () => 1);\n\u002F\u002F comptime returned a value that cannot be serialized\n```\n\n```ts\ncomptime(() => {\n  throw new Error(\"something happened\");\n});\n\u002F\u002F build fails\n```\n\n## Limits\n\nThis package does not add browser-side evaluation, disk caching, Webpack support, or esbuild standalone support.\n\n## License\n\nMIT © [Luke Edwards](https:\u002F\u002Flukeed.com)\n","comptime 是一个受 Zig 启发的构建时求值工具，以 Vite 和 Rolldown 插件的形式提供。其核心功能在于能够在构建阶段对函数进行评估，并将结果替换为序列化后的表达式，从而减少运行时计算开销。项目使用 TypeScript 编写，支持异步函数和环境变量读取，同时具备错误处理机制确保未启用插件时不会静默失败。适用于需要在编译期间执行纯函数并将其结果直接嵌入到最终代码中的场景，如前端项目的优化构建流程。","2026-06-11 03:31:46","CREATED_QUERY"]