{"_id":"@cjean-fr/vite-plugin-precompile","name":"@cjean-fr/vite-plugin-precompile","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@cjean-fr/vite-plugin-precompile","version":"0.1.0","description":"Vite plugin that precompiles JSX into tagged template literals (Deno-style precompile) for @cjean-fr/jsx-string","author":"Christophe Jean","license":"MIT","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./transformer":{"types":"./dist/transformer.d.ts","default":"./dist/transformer.js"}},"scripts":{"build":"bun run build.ts","check":"tsc --noEmit","test":"bun test"},"dependencies":{"@cjean-fr/precompile-core":"0.1.0","magic-string":"^0.30.21","oxc-parser":"^0.135.0"},"peerDependencies":{"vite":"^5 || ^6 || ^7 || ^8"},"devDependencies":{"@cjean-fr/jsx-string":"2.0.0","@jridgewell/trace-mapping":"^0.3.31","vite":"^8"},"publishConfig":{"access":"public"},"_id":"@cjean-fr/vite-plugin-precompile@0.1.0","_integrity":"sha512-gb7Myz8uNe2JvwF4iouakDDSqOdkfmB1k60J3KcTQrjWrMTPl4KxZSwahu1l81msftNTt9vuf2WoPYpjE3yqYw==","_nodeVersion":"24.3.0","_npmVersion":"10.8.3","shasum":"740a93cf4ee7eb166fcca4e4920ac812cdfe6564","dist":{"integrity":"sha512-gb7Myz8uNe2JvwF4iouakDDSqOdkfmB1k60J3KcTQrjWrMTPl4KxZSwahu1l81msftNTt9vuf2WoPYpjE3yqYw==","shasum":"740a93cf4ee7eb166fcca4e4920ac812cdfe6564","tarball":"https://registry.npmjs.org/@cjean-fr/vite-plugin-precompile/-/vite-plugin-precompile-0.1.0.tgz","fileCount":6,"unpackedSize":28860,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC3Q1iL1+CQi/4RADCoiU/BH4Nl1GLf6CG1dnSveQB65wIhAL/jEZUrt8wEENC9Wa6ZRiCnClTOORPKjk1GXb/D2UeE"}]},"_npmUser":{"name":"cjean","email":"christophe@cjean.fr"},"directories":{},"maintainers":[{"name":"cjean","email":"christophe@cjean.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/vite-plugin-precompile_0.1.0_1782075383214_0.4893665259227926"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-21T20:56:23.037Z","0.1.0":"2026-06-21T20:56:23.344Z","modified":"2026-06-21T20:56:23.571Z"},"maintainers":[{"name":"cjean","email":"christophe@cjean.fr"}],"description":"Vite plugin that precompiles JSX into tagged template literals (Deno-style precompile) for @cjean-fr/jsx-string","author":"Christophe Jean","license":"MIT","readme":"# @cjean-fr/vite-plugin-precompile\n\nVite plugin that precompiles lowercase (native HTML) JSX elements into Deno-style `jsxTemplate` tagged template literals.\n\nWraps a TypeScript transformer that precompiles lowercase (native HTML) JSX elements into Deno-style `jsxTemplate` tagged template literals. The transformer is also exposed as `@cjean-fr/vite-plugin-precompile/transformer` for programmatic use.\n\n## Install\n\n```sh\nnpm install @cjean-fr/vite-plugin-precompile -D\n# or: bun add -D, yarn add -D, pnpm add -D\n```\n\nRequires `vite` >= 5 as a peer dependency.\n\n## Usage\n\n### With jsx-string (default)\n\n```ts\n// tsconfig.json\n{\n  \"compilerOptions\": {\n    \"jsx\": \"react-jsx\",\n    \"jsxImportSource\": \"@cjean-fr/jsx-string\"\n  }\n}\n```\n\n```ts\n// vite.config.ts\nimport precompile from \"@cjean-fr/vite-plugin-precompile\";\nimport { defineConfig } from \"vite\";\n\nexport default defineConfig({\n  plugins: [precompile()],\n});\n```\n\nYou can also set `esbuild: { jsxImportSource: \"@cjean-fr/jsx-string\" }` in `vite.config.ts` instead of tsconfig. Vite reads either way and exposes it via `resolvedConfig.esbuild.jsxImportSource`.\n\n### With Preact\n\n```ts\n// vite.config.ts\nimport precompile from \"@cjean-fr/vite-plugin-precompile\";\nimport preact from \"@preact/preset-vite\";\nimport { defineConfig } from \"vite\";\n\nexport default defineConfig({\n  esbuild: { jsxImportSource: \"preact\" },\n  plugins: [\n    precompile(),  // auto-detected → \"preact/jsx-runtime\"\n    preact(),\n  ],\n});\n```\n\n```ts\n// vite.config.ts\nimport precompile from \"@cjean-fr/vite-plugin-precompile\";\nimport { defineConfig } from \"vite\";\n\nexport default defineConfig({\n  plugins: [precompile()],\n});\n```\n\nThe plugin uses `jsxImportSource` from Vite's resolved esbuild config (which Vite reads from `tsconfig.json` or `vite.config.ts`) to determine the runtime helpers path (`{source}/jsx-runtime`). If that isn't set either, it falls back to `@cjean-fr/jsx-string/jsx-runtime`.\n\n`runtimeSource` option always wins when provided.\n\n### With Preact\n\n```ts\n// vite.config.ts\nimport precompile from \"@cjean-fr/vite-plugin-precompile\";\nimport preact from \"@preact/preset-vite\";\nimport { defineConfig } from \"vite\";\n\nexport default defineConfig({\n  plugins: [\n    precompile(),  // auto-detected from tsconfig → \"preact/jsx-runtime\"\n    preact(),\n  ],\n});\n```\n\n### With any runtime (explicit)\n\n```ts\nprecompile({ runtimeSource: \"custom/jsx-runtime\" })\n// explicit — overrides both jsxImportSource and default\n```\n\n## API\n\n### `PluginConfig`\n\n```ts\ninterface PluginConfig {\n  runtimeSource?: string;  // default: auto-detected from esbuild.jsxImportSource + \"/jsx-runtime\"\n}\n```\n\n### Default export\n\n```ts\nfunction vitePrecompile(config?: PluginConfig): Plugin\n```\n\nReturns a Vite plugin with `enforce: \"pre\"` — runs before esbuild/Vite's own transforms.\n\n### `PluginConfig`\n\n```ts\ninterface PluginConfig {\n  runtimeSource?: string;  // default: \"@cjean-fr/jsx-string/jsx-runtime\"\n}\n```\n\n## Standalone transformer\n\nThe underlying TypeScript transformer is exposed for programmatic use:\n\n```ts\nimport transformer from \"@cjean-fr/vite-plugin-precompile/transformer\";\nimport ts from \"typescript\";\n\nconst result = ts.transform(sourceFile, [\n  transformer(program, { runtimeSource: \"preact/jsx-runtime\" }),\n]);\n```\n\nThis is the same transformer used internally by the Vite plugin.\n\n## How it works\n\n- `enforce: \"pre\"` — runs before esbuild/Vite's own transforms\n- Reads `jsxImportSource` from Vite's resolved esbuild config during `configResolved`\n- Only transforms `.tsx`/`.jsx` files (skips `node_modules`)\n- Skips files that don't contain `<` (no JSX)\n- The underlying TS transformer handles element-level decisions (lowercase only, skip spread/innerHTML)\n- Emits `jsxTemplate\\`<div>\\${jsxEscape(expr)}\\</div>\\`` with auto-imported runtime helpers\n\n## Test\n\n```sh\nbun test   # 9 tests (integration with Vite build pipeline)\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-de95d188e84ac0ea366b50100acc3cca"}