vite-plugin-vanjs 0.0.1 → 0.0.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 CHANGED
@@ -5,15 +5,14 @@
5
5
  [![typescript version](https://img.shields.io/badge/typescript-5.6.2-brightgreen)](https://www.typescriptlang.org/)
6
6
  [![vanjs-core version](https://img.shields.io/badge/vanjs--core-1.5.2-brightgreen)](https://github.com/vanjs-org/van)
7
7
  [![mini-van-plate version](https://img.shields.io/badge/mini--van--plate-0.6.1-brightgreen)](https://github.com/vanjs-org/mini-van-plate)
8
- [![vite version](https://img.shields.io/badge/vite-6.0.5-brightgreen)](https://github.com/vitejs)
8
+ [![vite version](https://img.shields.io/badge/vite-6.0.6-brightgreen)](https://github.com/vitejs)
9
9
 
10
- A Vite plugin for VanJS to enable JSX transformation and simplify application development.
10
+ A Vite plugin for VanJS to enable JSX transformation and simplify application development and enables you to create SSR applications or SSG (static) pages. It will automatically load the appropriate Van or VanX objects depending on the client/server environment with zero configuration needed. It uses the `mini-van-plate/shared` module to register the required objects in an isomorphic enviroment.
11
11
 
12
- This plugin uses and requires the `mini-van-plate` package in order to register the Van and VanX objects in an isomorphic server/client enviroment. If you're planning to do SSR apps, the `van-ext` is also required.
12
+ The plugin uses `van-ext` along with `mini-van-plate` so you can have everything ready from start. It also enables JSX transformation with minimal setup so you can write your code faster.
13
13
 
14
- The recommended templates for you to use are the [vite-starter-vanjs-ssr](https://github.com/thednp/vite-starter-vanjs-ssr) and [vite-starter-vanjs-ssr-jsx](https://github.com/thednp/vite-starter-vanjs-ssr-jsx) which already feature this plugin.
14
+ The recommended starter templates for you are the [vite-starter-vanjs-ssr](https://github.com/thednp/vite-starter-vanjs-ssr) and [vite-starter-vanjs-ssr-jsx](https://github.com/thednp/vite-starter-vanjs-ssr-jsx) which already include this plugin.
15
15
 
16
- If you don't need an SSR/SSG application, you simply make use of the JSX transformation capability.
17
16
 
18
17
  ### Install
19
18
 
@@ -55,7 +54,7 @@ export default defineConfig({
55
54
 
56
55
  **Example**:
57
56
 
58
- For your convenience and for your SSR applications/extensions expecially, you need to import from `@vanjs/van` virtual module, so **vite-plugin-vanjs** makes sure to load the right modules where needed.
57
+ While the plugin will resolve the appropriate modules depending on the environment, for your convenience, you can also import the `@vanjs/van` and `@vanjs/vanX` virtual modules, so the plugin makes sure to load the right modules where needed.
59
58
 
60
59
  ```ts
61
60
  // my-component.ts
@@ -84,7 +83,7 @@ const MyList = () => {
84
83
  inputDom,
85
84
  button({onclick: () => items.push({text: inputDom.value, done: false})}, "Add"),
86
85
  vanX.list(div, items, ({val: v}, deleter) => div(
87
- input({type: "checkbox", checked: () => v.done, onclick: (e: TodoClickEvent) => v.done = e.target.checked}),
86
+ input({type: "checkbox", checked: () => v.done, onclick: (e) => v.done = e.target.checked}),
88
87
  () => (v.done ? del : span)(v.text),
89
88
  button({ onclick: deleter }, "Remove"),
90
89
  )),
@@ -100,7 +99,6 @@ To enable JSX transformation, you have to edit your `tsconfig.json` as follows:
100
99
  ```json
101
100
  {
102
101
  "compilerOptions": {
103
- /* {... your other compiler options } */
104
102
  "jsx": "preserve",
105
103
  "jsxImportSource": "@vanjs/jsx"
106
104
  }
@@ -129,8 +127,8 @@ van.add(document.getElementById("app")!, <App /> as ChildDom);
129
127
  * in some cases like this one, enforcing a certain typescript type via `as` might be in good order depending on who renders your component;
130
128
  * you can use `ref` as a `van.state`, `class` instead of `className`, `for` instead of `htmlFor`;
131
129
  * you can use style as both an object and a string;
132
- * for a JSX started template, check out the [vite-starter-vanjs-ssr-jsx](https://github.com/thednp/vite-starter-vanjs-ssr-jsx).
133
- * for a pure started template, check out the [vite-starter-vanjs-ssr](https://github.com/thednp/vite-starter-vanjs-ssr).
130
+ * for a JSX starter template, check out the [vite-starter-vanjs-ssr-jsx](https://github.com/thednp/vite-starter-vanjs-ssr-jsx).
131
+ * for a pure vanilla starter template, check out the [vite-starter-vanjs-ssr](https://github.com/thednp/vite-starter-vanjs-ssr).
134
132
 
135
133
 
136
134
 
@@ -142,4 +140,4 @@ van.add(document.getElementById("app")!, <App /> as ChildDom);
142
140
 
143
141
 
144
142
  ### License
145
- Released under [MIT](LICENSE).
143
+ Released under [MIT](LICENSE).
package/jsx/fragment.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { ChildDom } from "vanjs-core";
2
1
  import type { JSX } from "./jsx";
3
2
 
4
3
  export type FragmentProps = {
package/jsx/jsx.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import van from "@vanjs/van";
2
- import setup from "@vanjs/van";
2
+ import setup from "@vanjs/setup";
3
3
  import { setAttribute, styleToString } from "./utils.mjs";
4
4
 
5
5
  export const jsx = (jsxTag, { children, ref, style, ...props }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vanjs",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "author": "thednp",
5
5
  "license": "MIT",
6
6
  "description": "A Vite plugin for VanJS to enable JSX transformation and simplify aplication development.",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "typescript": "5.6.2",
70
- "vite": "^6.0.5"
70
+ "vite": "^6.0.6"
71
71
  },
72
72
  "scripts": {
73
73
  "badges": "npx -p dependency-version-badge update-badge vanjs-core mini-van-plate typescript vite",
package/setup/global.d.ts CHANGED
@@ -5,19 +5,48 @@ declare module "@vanjs/van" {
5
5
  }
6
6
 
7
7
  declare module "@vanjs/vanX" {
8
- import * as VanX from "vanjs-ext";
9
- const vanX: typeof VanX;
8
+ import {
9
+ calc,
10
+ compact,
11
+ list,
12
+ noreactive,
13
+ raw,
14
+ reactive,
15
+ replace,
16
+ stateFields,
17
+ } from "vanjs-ext";
18
+ const vanX: {
19
+ calc: typeof calc;
20
+ reactive: typeof reactive;
21
+ noreactive: typeof noreactive;
22
+ stateFields: typeof stateFields;
23
+ raw: typeof raw;
24
+ list: typeof list;
25
+ replace: typeof replace;
26
+ compact: typeof compact;
27
+ };
10
28
  export default vanX;
29
+ export {
30
+ calc,
31
+ compact,
32
+ list,
33
+ noreactive,
34
+ raw,
35
+ reactive,
36
+ replace,
37
+ stateFields,
38
+ };
11
39
  }
12
40
 
13
41
  declare module "@vanjs/setup" {
14
42
  import type { Van } from "vanjs-core";
15
- import * as VanX from "vanjs-ext";
43
+ import type * as vanX from "vanjs-ext";
44
+ import type { dummyVanX } from "mini-van-plate/shared";
16
45
 
17
46
  interface Setup {
18
47
  isServer: boolean;
19
48
  van: Van;
20
- vanX: typeof VanX;
49
+ vanX: typeof vanX | typeof dummyVanX;
21
50
  }
22
51
  const setup: Setup;
23
52
  export default setup;
package/setup/index.mjs CHANGED
@@ -3,13 +3,16 @@ import vanPlate from "mini-van-plate/van-plate";
3
3
  import vanCore from "vanjs-core";
4
4
  import * as vanX from "vanjs-ext";
5
5
 
6
+ const vanXObject = { ...vanX, default: vanX };
7
+ const dummyObject = { ...dummyVanX, default: dummyVanX };
8
+
6
9
  const setup = {
7
10
  isServer: typeof window === "undefined",
8
11
  get van() {
9
12
  return this.isServer ? vanPlate : vanCore;
10
13
  },
11
14
  get vanX() {
12
- return this.isServer ? dummyVanX : vanX;
15
+ return this.isServer ? dummyObject : vanXObject;
13
16
  },
14
17
  };
15
18
 
package/setup/vanX.mjs CHANGED
@@ -1,2 +1,14 @@
1
1
  import setup from "./index.mjs";
2
- export default setup.vanX;
2
+ const vanX = setup.vanX;
3
+
4
+ export const {
5
+ calc,
6
+ reactive,
7
+ noreactive,
8
+ stateFields,
9
+ raw,
10
+ list,
11
+ replace,
12
+ compact,
13
+ } = "default" in vanX ? vanX.default : vanX;
14
+ export default vanX;
package/src/index.mjs CHANGED
@@ -10,6 +10,12 @@ export default function VitePluginVanJS() {
10
10
  enforce: "pre",
11
11
  config() {
12
12
  return {
13
+ build: {
14
+ optimizeDeps: {
15
+ include: ["vanjs-core", "vanjs-ext", "mini-van-plate"],
16
+ },
17
+ dedupe: ["vanjs-core", "vanjs-ext", "mini-van-plate"],
18
+ },
13
19
  resolve: {
14
20
  alias: {
15
21
  "@vanjs/jsx": resolve(__dirname, "../jsx"),
@@ -18,9 +24,6 @@ export default function VitePluginVanJS() {
18
24
  "@vanjs/vanX": resolve(__dirname, "../setup/vanX"),
19
25
  },
20
26
  },
21
- optimizeDeps: {
22
- include: ["vanjs-core", "mini-van-plate", "vanjs-ext"],
23
- },
24
27
  esbuild: {
25
28
  jsx: "automatic",
26
29
  jsxFactory: "jsx",
@@ -28,5 +31,33 @@ export default function VitePluginVanJS() {
28
31
  },
29
32
  };
30
33
  },
34
+ transform(code, id) {
35
+ let newCode = code;
36
+
37
+ const vanCoreReg = /import\s*.*\s*from\s*['"]vanjs-core['"]/g;
38
+ const vanExtReg = /import\s*.*\s*from\s*['"]vanjs-ext['"]/g;
39
+ const isSetupFile = /vite-plugin-vanjs[\\/]setup/.test(id);
40
+ const isVanXFile = /vanjs-ext[\\/]src[\\/]van-x/.test(id);
41
+
42
+ if (!isSetupFile && !isVanXFile) {
43
+ if (vanCoreReg.test(newCode)) {
44
+ newCode = newCode.replace(
45
+ vanCoreReg,
46
+ (match) => match.replace("vanjs-core", "@vanjs/van"),
47
+ );
48
+ }
49
+ if (vanExtReg.test(newCode)) {
50
+ newCode = newCode.replace(
51
+ vanExtReg,
52
+ (match) => match.replace("vanjs-ext", "@vanjs/vanX"),
53
+ );
54
+ }
55
+ }
56
+
57
+ return {
58
+ code: newCode,
59
+ map: null,
60
+ };
61
+ },
31
62
  };
32
63
  }
package/tsconfig.json CHANGED
@@ -28,6 +28,6 @@
28
28
  "jsx": "preserve",
29
29
  "jsxImportSource": "vite-plugin-vanjs",
30
30
  },
31
- "include": ["./src/**/*", "./jsx/**/*.d.ts", "setup/**/*"],
31
+ "include": ["./src/**/*.ts", "./jsx/*.d.ts", "setup/**/*"],
32
32
  "exclude": ["node_modules", "experiments", "coverage"],
33
33
  }