@zntc/vite-plugin 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -26
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
# @zntc/vite-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English · **[한국어](./README_KO.md)**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Replace Vite's esbuild transform with ZNTC — TypeScript / JSX / Flow / decorators handled by ZNTC (Zig-based), while Vite's dev server / HMR / plugin ecosystem stays intact.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@zntc/vite-plugin)
|
|
8
|
+
[](https://github.com/ohah/zntc/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
This plugin swaps Vite's built-in esbuild transform step for [ZNTC](https://github.com/ohah/zntc), a single-pass transpiler written in Zig. TypeScript, JSX, Flow, and decorator transforms all flow through ZNTC, and you keep the rest of the Vite pipeline (dev server, HMR, plugins) untouched.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
6
13
|
|
|
7
14
|
```bash
|
|
8
15
|
bun add -D @zntc/vite-plugin @zntc/core
|
|
9
|
-
#
|
|
16
|
+
# or
|
|
10
17
|
npm i -D @zntc/vite-plugin @zntc/core
|
|
11
18
|
```
|
|
12
19
|
|
|
13
|
-
`@zntc/core`
|
|
20
|
+
`@zntc/core` (which ships the native NAPI binary) is required alongside the plugin.
|
|
14
21
|
|
|
15
|
-
##
|
|
22
|
+
## Usage
|
|
16
23
|
|
|
17
24
|
```ts
|
|
18
25
|
// vite.config.ts
|
|
@@ -21,37 +28,31 @@ import { zntc } from '@zntc/vite-plugin';
|
|
|
21
28
|
|
|
22
29
|
export default defineConfig({
|
|
23
30
|
plugins: [zntc()],
|
|
24
|
-
// esbuild
|
|
31
|
+
// Disable esbuild — ZNTC handles .ts / .tsx / .jsx transforms.
|
|
25
32
|
esbuild: false,
|
|
26
33
|
});
|
|
27
34
|
```
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
### Options
|
|
30
37
|
|
|
31
38
|
```ts
|
|
32
39
|
zntc({
|
|
33
|
-
include: /\.(tsx?|jsx)$/, //
|
|
34
|
-
exclude: /node_modules/, //
|
|
35
|
-
tsconfigCache: true, // tsconfig
|
|
40
|
+
include: /\.(tsx?|jsx)$/, // files to transform (default)
|
|
41
|
+
exclude: /node_modules/, // files to skip (default)
|
|
42
|
+
tsconfigCache: true, // cache tsconfig autodiscovery results (default: true)
|
|
36
43
|
transpileOptions: {
|
|
37
|
-
// ZNTC transpile
|
|
44
|
+
// ZNTC transpile options (target / jsx / decorators, etc.)
|
|
38
45
|
target: 'es2020',
|
|
39
46
|
jsx: 'automatic',
|
|
40
47
|
},
|
|
41
48
|
});
|
|
42
49
|
```
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
### Using with framework plugins
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
`@sveltejs/vite-plugin-svelte`, `vite-plugin-solid`) 은 ZNTC 와 충돌 없이 같이
|
|
48
|
-
쓸 수 있습니다. 다만 **babel 기반으로 `.tsx` 를 자체적으로 다시 변환하는 plugin**
|
|
49
|
-
— 대표적으로 `@preact/preset-vite` — 와 함께 쓰면 `.tsx` 가 둘 다 처리되면서
|
|
50
|
-
결과가 깨질 수 있습니다 (component body 의 JSX return 이 비어버림).
|
|
53
|
+
Most framework plugins (`@vitejs/plugin-react`, `@vitejs/plugin-vue`, `@sveltejs/vite-plugin-svelte`, `vite-plugin-solid`) work alongside ZNTC without conflict. The exception is a **Babel-based plugin that re-transforms `.tsx` on its own** — most notably `@preact/preset-vite` — where `.tsx` gets processed twice and the output can break (the JSX return inside a component body ends up empty).
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
건너뛰고 framework plugin 이 JSX + TS 까지 모두 담당합니다. `.ts` 는 그대로
|
|
54
|
-
ZNTC 가 처리.
|
|
55
|
+
In that case set `jsx: 'preserve'`. ZNTC then skips `.tsx` / `.jsx` and lets the framework plugin handle both JSX and TS, while `.ts` is still processed by ZNTC.
|
|
55
56
|
|
|
56
57
|
```ts
|
|
57
58
|
// preact + vite
|
|
@@ -64,13 +65,17 @@ export default defineConfig({
|
|
|
64
65
|
});
|
|
65
66
|
```
|
|
66
67
|
|
|
67
|
-
`jsx: 'preserve'`
|
|
68
|
-
|
|
68
|
+
`jsx: 'preserve'` is equivalent to tsc's `"jsx": "preserve"` — it delegates JSX transformation to a downstream tool.
|
|
69
|
+
|
|
70
|
+
### Peer requirements
|
|
71
|
+
|
|
72
|
+
- `vite >= 5.0.0` (8.x recommended)
|
|
69
73
|
|
|
70
|
-
##
|
|
74
|
+
## Documentation
|
|
71
75
|
|
|
72
|
-
-
|
|
76
|
+
- Monorepo: <https://github.com/ohah/zntc>
|
|
77
|
+
- Docs: <https://ohah.github.io/zntc>
|
|
73
78
|
|
|
74
|
-
##
|
|
79
|
+
## License
|
|
75
80
|
|
|
76
|
-
MIT
|
|
81
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -37,5 +37,11 @@ export interface ZntcPluginOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
tsconfigCache?: boolean;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Vite 5 이하에서만 esbuild 변환을 비활성화해야 하는지 판단(Vite 6+ 는 Rolldown 기반이라 불필요).
|
|
42
|
+
* version 문자열의 major 세그먼트만 robust 파싱 — `parseInt('6.0.0-beta')` 류 취약성 회피, 파싱
|
|
43
|
+
* 불가 시 보수적으로 false(비활성화 안 함). 순수 함수로 분리해 단위 테스트 가능.
|
|
44
|
+
*/
|
|
45
|
+
export declare function shouldDisableEsbuildForVite(version: string): boolean;
|
|
40
46
|
export declare function zntc(options?: ZntcPluginOptions): Plugin;
|
|
41
47
|
export default zntc;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { TsconfigCache, init, transpile } from "@zntc/core";
|
|
2
2
|
//#region index.ts
|
|
3
3
|
const DEFAULT_INCLUDE = /\.(tsx?|jsx)$/,DEFAULT_EXCLUDE = /node_modules/,JSX_EXT_PATTERN = /\.[jt]sx$/;
|
|
4
|
+
function shouldDisableEsbuildForVite(version) {
|
|
5
|
+
const major = Number.parseInt(version.split(".", 1)[0] ?? "", 10);
|
|
6
|
+
return Number.isFinite(major) && major < 6;
|
|
7
|
+
}
|
|
4
8
|
function zntc(options={}) {
|
|
5
9
|
const include = options.include ?? DEFAULT_INCLUDE,exclude = options.exclude ?? DEFAULT_EXCLUDE,transpileOpts = options.transpileOptions ?? {},useTsconfigCache = options.tsconfigCache ?? true;
|
|
6
10
|
let initialized = false,cache;
|
|
7
|
-
return { name: "@zntc/vite-plugin", config(_,_env) {
|
|
11
|
+
return { name: "@zntc/vite-plugin", async config(_,_env) {
|
|
8
12
|
try {
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
13
|
+
const { version:version } = await import("vite");
|
|
14
|
+
if (shouldDisableEsbuildForVite(version))return { esbuild: false };
|
|
11
15
|
} catch {
|
|
12
16
|
}
|
|
13
17
|
return {};
|
|
@@ -30,5 +34,5 @@ function zntc(options={}) {
|
|
|
30
34
|
} };
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
export { zntc, zntc as default };
|
|
37
|
+
export { shouldDisableEsbuildForVite, zntc, zntc as default };
|
|
34
38
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zntc/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Use ZNTC as the TypeScript/JSX transformer in Vite (replaces esbuild)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esbuild",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"prepublishOnly": "bun run build && bunx publint --strict --level error ."
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@zntc/core": "0.1.
|
|
48
|
+
"@zntc/core": "0.1.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^25.5.2",
|