@ktjs/vite-plugin-ktjsx 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/README.md +31 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +63 -0
- package/dist/index.mjs +43729 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# vite-plugin-ktjsx
|
|
2
|
+
|
|
3
|
+
light, manual‑control web framework that creates real DOM elements with built‑in reactive state management.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/vite-plugin-ktjsx)
|
|
6
|
+
[](https://www.npmjs.com/package/vite-plugin-ktjsx)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
`@ktjs/vite-plugin-ktjsx` applies KT.js JSX transforms in Vite.
|
|
10
|
+
|
|
11
|
+
It reuses `@ktjs/babel-plugin-ktjsx` internally, so behavior is the same:
|
|
12
|
+
|
|
13
|
+
- mark SVG / MathML subtrees with KT.js namespace flags
|
|
14
|
+
- (TODO) transform `k-if` / `k-else-if` / `k-else` chains
|
|
15
|
+
|
|
16
|
+
Basic usage:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { defineConfig } from 'vite';
|
|
20
|
+
import ktjsx from '@ktjs/vite-plugin-ktjsx';
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
plugins: [ktjsx()],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
|
|
29
|
+
- `include` - custom file matcher (`RegExp` or predicate function)
|
|
30
|
+
- `exclude` - files to skip (`RegExp` or predicate function)
|
|
31
|
+
- `babelConfig` - additional Babel transform options
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin as Plugin_2 } from 'vite';
|
|
2
|
+
import { TransformOptions } from '@babel/core';
|
|
3
|
+
|
|
4
|
+
declare type Filter = RegExp | ((id: string) => boolean);
|
|
5
|
+
|
|
6
|
+
declare function viteKTjsx(options?: ViteKTjsxOptions): Plugin_2;
|
|
7
|
+
export default viteKTjsx;
|
|
8
|
+
export { viteKTjsx }
|
|
9
|
+
|
|
10
|
+
export declare interface ViteKTjsxOptions {
|
|
11
|
+
include?: Filter;
|
|
12
|
+
exclude?: Filter;
|
|
13
|
+
babelConfig?: Omit<TransformOptions, 'ast' | 'babelrc' | 'configFile' | 'filename' | 'parserOpts' | 'plugins' | 'sourceFileName' | 'sourceMaps'>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { transformAsync } from '@babel/core';
|
|
2
|
+
import babelKTjsx from '@ktjs/babel-plugin-ktjsx';
|
|
3
|
+
const DEFAULT_INCLUDE_RE = /\.[cm]?[jt]sx$/;
|
|
4
|
+
const NODE_MODULES_RE = /\/node_modules\//;
|
|
5
|
+
const QUERY_RE = /\?.*$/;
|
|
6
|
+
const DEFAULT_PARSER_PLUGINS = ['jsx', 'typescript'];
|
|
7
|
+
const stripQuery = (id) => id.replace(QUERY_RE, '');
|
|
8
|
+
const matchFilter = (filter, id) => {
|
|
9
|
+
if (!filter) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (typeof filter === 'function') {
|
|
13
|
+
return filter(id);
|
|
14
|
+
}
|
|
15
|
+
filter.lastIndex = 0;
|
|
16
|
+
return filter.test(id);
|
|
17
|
+
};
|
|
18
|
+
const shouldTransform = (id, include, exclude) => {
|
|
19
|
+
if (id.startsWith('\0') || NODE_MODULES_RE.test(id)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (exclude && matchFilter(exclude, id)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (include) {
|
|
26
|
+
return matchFilter(include, id);
|
|
27
|
+
}
|
|
28
|
+
return DEFAULT_INCLUDE_RE.test(id);
|
|
29
|
+
};
|
|
30
|
+
export function viteKTjsx(options = {}) {
|
|
31
|
+
return {
|
|
32
|
+
name: 'ktjs:vite-plugin-ktjsx',
|
|
33
|
+
enforce: 'pre',
|
|
34
|
+
async transform(code, id) {
|
|
35
|
+
const cleanId = stripQuery(id);
|
|
36
|
+
if (!shouldTransform(cleanId, options.include, options.exclude)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const result = await transformAsync(code, {
|
|
40
|
+
filename: cleanId,
|
|
41
|
+
sourceFileName: cleanId,
|
|
42
|
+
ast: false,
|
|
43
|
+
babelrc: false,
|
|
44
|
+
configFile: false,
|
|
45
|
+
sourceMaps: true,
|
|
46
|
+
parserOpts: {
|
|
47
|
+
sourceType: 'module',
|
|
48
|
+
plugins: DEFAULT_PARSER_PLUGINS,
|
|
49
|
+
},
|
|
50
|
+
plugins: [babelKTjsx()],
|
|
51
|
+
...options.babelConfig,
|
|
52
|
+
});
|
|
53
|
+
if (!result?.code) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
code: result.code,
|
|
58
|
+
map: result.map ?? null,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export default viteKTjsx;
|