@zntc/vite-plugin 0.1.0
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/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +34 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ohah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @zntc/vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite 의 esbuild transform 을 ZNTC 로 교체하는 플러그인. TypeScript / JSX / Flow / decorators 변환을 ZNTC (Zig 기반) 가 담당하면서 Vite 의 dev server / HMR / plugin 생태계는 그대로 유지.
|
|
4
|
+
|
|
5
|
+
## 설치
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add -D @zntc/vite-plugin @zntc/core
|
|
9
|
+
# 또는
|
|
10
|
+
npm i -D @zntc/vite-plugin @zntc/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@zntc/core` 가 dependency 로 함께 따라옴 (NAPI binary 포함).
|
|
14
|
+
|
|
15
|
+
## 사용
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// vite.config.ts
|
|
19
|
+
import { defineConfig } from 'vite';
|
|
20
|
+
import { zntc } from '@zntc/vite-plugin';
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
plugins: [zntc()],
|
|
24
|
+
// esbuild 자동 비활성화 (zntc 가 .ts/.tsx/.jsx 변환 담당)
|
|
25
|
+
esbuild: false,
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 옵션
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
zntc({
|
|
33
|
+
include: /\.(tsx?|jsx)$/, // 변환할 파일 패턴 (default)
|
|
34
|
+
exclude: /node_modules/, // 제외 패턴 (default)
|
|
35
|
+
tsconfigCache: true, // tsconfig autodiscover 결과 캐시 (default: true)
|
|
36
|
+
transpileOptions: {
|
|
37
|
+
// ZNTC transpile 옵션 (target / jsx / decorators 등)
|
|
38
|
+
target: 'es2020',
|
|
39
|
+
jsx: 'automatic',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Framework plugin 과 함께 쓰기
|
|
45
|
+
|
|
46
|
+
대부분의 framework plugin (`@vitejs/plugin-react`, `@vitejs/plugin-vue`,
|
|
47
|
+
`@sveltejs/vite-plugin-svelte`, `vite-plugin-solid`) 은 ZNTC 와 충돌 없이 같이
|
|
48
|
+
쓸 수 있습니다. 다만 **babel 기반으로 `.tsx` 를 자체적으로 다시 변환하는 plugin**
|
|
49
|
+
— 대표적으로 `@preact/preset-vite` — 와 함께 쓰면 `.tsx` 가 둘 다 처리되면서
|
|
50
|
+
결과가 깨질 수 있습니다 (component body 의 JSX return 이 비어버림).
|
|
51
|
+
|
|
52
|
+
이 경우 `jsx: 'preserve'` 옵션을 사용합니다 — ZNTC 는 `.tsx`/`.jsx` 처리를
|
|
53
|
+
건너뛰고 framework plugin 이 JSX + TS 까지 모두 담당합니다. `.ts` 는 그대로
|
|
54
|
+
ZNTC 가 처리.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// preact + vite
|
|
58
|
+
import { defineConfig } from 'vite';
|
|
59
|
+
import preact from '@preact/preset-vite';
|
|
60
|
+
import { zntc } from '@zntc/vite-plugin';
|
|
61
|
+
|
|
62
|
+
export default defineConfig({
|
|
63
|
+
plugins: [zntc({ transpileOptions: { jsx: 'preserve' } }), preact()],
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`jsx: 'preserve'` 는 tsc `"jsx": "preserve"` 와 동등한 의미 — JSX 변환을
|
|
68
|
+
downstream tool 에 위임합니다.
|
|
69
|
+
|
|
70
|
+
## peer
|
|
71
|
+
|
|
72
|
+
- `vite >= 5.0.0` (8.x 권장)
|
|
73
|
+
|
|
74
|
+
## 라이센스
|
|
75
|
+
|
|
76
|
+
MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zntc/vite-plugin — Vite plugin that replaces Vite's esbuild transform with ZNTC.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* // vite.config.ts
|
|
7
|
+
* import { defineConfig } from "vite";
|
|
8
|
+
* import { zntc } from "@zntc/vite-plugin";
|
|
9
|
+
*
|
|
10
|
+
* export default defineConfig({
|
|
11
|
+
* plugins: [zntc()],
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import type { Plugin } from 'vite';
|
|
16
|
+
import type { TranspileOptions } from '@zntc/core';
|
|
17
|
+
export interface ZntcPluginOptions {
|
|
18
|
+
/**
|
|
19
|
+
* File extension pattern to transform (default: /\.(tsx?|jsx)$/).
|
|
20
|
+
*/
|
|
21
|
+
include?: RegExp;
|
|
22
|
+
/**
|
|
23
|
+
* File pattern to exclude (default: /node_modules/).
|
|
24
|
+
*/
|
|
25
|
+
exclude?: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* ZNTC transpile options (target, jsx, etc.).
|
|
28
|
+
*/
|
|
29
|
+
transpileOptions?: Omit<TranspileOptions, 'filename'>;
|
|
30
|
+
/**
|
|
31
|
+
* Enable caching of tsconfig autodiscovery results (default: true). For the
|
|
32
|
+
* lifetime of the plugin instance, files in the same workspace are walked only
|
|
33
|
+
* once → saves 5–10 fs syscalls per file (#2367).
|
|
34
|
+
* The cache is automatically bypassed when `transpileOptions.tsconfigPath` /
|
|
35
|
+
* `tsconfigRaw` is set explicitly.
|
|
36
|
+
* Set to false to disable if a very long Vite dev session raises memory concerns.
|
|
37
|
+
*/
|
|
38
|
+
tsconfigCache?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function zntc(options?: ZntcPluginOptions): Plugin;
|
|
41
|
+
export default zntc;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TsconfigCache, init, transpile } from "@zntc/core";
|
|
2
|
+
//#region index.ts
|
|
3
|
+
const DEFAULT_INCLUDE = /\.(tsx?|jsx)$/,DEFAULT_EXCLUDE = /node_modules/,JSX_EXT_PATTERN = /\.[jt]sx$/;
|
|
4
|
+
function zntc(options={}) {
|
|
5
|
+
const include = options.include ?? DEFAULT_INCLUDE,exclude = options.exclude ?? DEFAULT_EXCLUDE,transpileOpts = options.transpileOptions ?? {},useTsconfigCache = options.tsconfigCache ?? true;
|
|
6
|
+
let initialized = false,cache;
|
|
7
|
+
return { name: "@zntc/vite-plugin", config(_,_env) {
|
|
8
|
+
try {
|
|
9
|
+
const viteVersion = parseInt(require("vite/package.json").version);
|
|
10
|
+
if (viteVersion < 6)return { esbuild: false };
|
|
11
|
+
} catch {
|
|
12
|
+
}
|
|
13
|
+
return {};
|
|
14
|
+
}, buildStart() {
|
|
15
|
+
if (!initialized) {
|
|
16
|
+
init();
|
|
17
|
+
initialized = true;
|
|
18
|
+
}
|
|
19
|
+
if (useTsconfigCache && !cache) {
|
|
20
|
+
cache = new TsconfigCache();
|
|
21
|
+
}
|
|
22
|
+
}, transform(code,id) {
|
|
23
|
+
if (!include.test(id))return null;
|
|
24
|
+
if (exclude.test(id))return null;
|
|
25
|
+
if (transpileOpts.jsx === "preserve" && JSX_EXT_PATTERN.test(id)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const result = transpile(code, { ...transpileOpts, filename: id, cache });
|
|
29
|
+
return { code: result.code, map: result.map ? JSON.parse(result.map) : null };
|
|
30
|
+
} };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { zntc, zntc as default };
|
|
34
|
+
//#endregion
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zntc/vite-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Use ZNTC as the TypeScript/JSX transformer in Vite (replaces esbuild)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"esbuild",
|
|
7
|
+
"jsx",
|
|
8
|
+
"swc",
|
|
9
|
+
"transpiler",
|
|
10
|
+
"typescript",
|
|
11
|
+
"vite",
|
|
12
|
+
"vite-plugin",
|
|
13
|
+
"zntc"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://ohah.github.io/zntc",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/ohah/zntc/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "ohah",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ohah/zntc.git",
|
|
24
|
+
"directory": "packages/vite-plugin"
|
|
25
|
+
},
|
|
26
|
+
"source": "./src/index.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist/",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"source": "./src/index.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build:bundle": "node ../core/bin/zntc.mjs --bundle src/index.ts --outfile dist/index.js --format=esm --target=node --conditions=source --external @zntc/core --external vite",
|
|
43
|
+
"build:dts": "bun x tsc -b",
|
|
44
|
+
"build": "bun run build:bundle && bun run build:dts",
|
|
45
|
+
"prepublishOnly": "bun run build && bunx publint --strict --level error ."
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@zntc/core": "workspace:*"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^25.5.2",
|
|
52
|
+
"vite": "^8.0.8"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"vite": ">=5.0.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=24.0.0"
|
|
59
|
+
}
|
|
60
|
+
}
|