vite-plugin-vanjs 0.1.2 → 0.1.4
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 +1 -1
- package/package.json +3 -3
- package/plugin/index.mjs +76 -56
- package/server/index.mjs +6 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/vite-plugin-vanjs)
|
|
6
6
|
[](http://npm-stat.com/charts.html?package=vite-plugin-vanjs)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
|
-
[](https://github.com/vanjs-org/van)
|
|
9
9
|
[](https://github.com/vanjs-org/mini-van-plate)
|
|
10
10
|
[](https://www.vitest.dev/)
|
|
11
11
|
[](https://vite.dev)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vanjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"author": "thednp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A mini meta-framework for VanJS powered by Vite",
|
|
@@ -83,11 +83,11 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"csstype": "^3.1.3",
|
|
85
85
|
"mini-van-plate": "^0.6.3",
|
|
86
|
-
"vanjs-core": "^1.5.
|
|
86
|
+
"vanjs-core": "^1.5.5",
|
|
87
87
|
"vanjs-ext": "^0.6.2"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@types/node": "^22.15.
|
|
90
|
+
"@types/node": "^22.15.3",
|
|
91
91
|
"@vitest/browser": "^3.1.2",
|
|
92
92
|
"@vitest/coverage-istanbul": "^3.1.2",
|
|
93
93
|
"@vitest/ui": "^3.1.2",
|
package/plugin/index.mjs
CHANGED
|
@@ -19,6 +19,36 @@ const pluginDefaults = {
|
|
|
19
19
|
extensions: [".tsx", ".jsx", ".ts", ".js"],
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
// Define module mapping configuration
|
|
23
|
+
const moduleAliases = {
|
|
24
|
+
// Core modules
|
|
25
|
+
"@vanjs/van": "../setup/van",
|
|
26
|
+
"@vanjs/vanX": "../setup/vanX",
|
|
27
|
+
|
|
28
|
+
// Setup modules
|
|
29
|
+
"@vanjs/setup": "../setup/index",
|
|
30
|
+
|
|
31
|
+
// Other modules
|
|
32
|
+
"@vanjs/client": "../client",
|
|
33
|
+
"@vanjs/server": "../server",
|
|
34
|
+
"@vanjs/meta": "../meta",
|
|
35
|
+
"@vanjs/router": "../router",
|
|
36
|
+
"@vanjs/jsx": "../jsx",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// SSR specific module mappings
|
|
40
|
+
const ssrModuleAliases = {
|
|
41
|
+
"@vanjs/van": "../setup/van-ssr",
|
|
42
|
+
"@vanjs/vanX": "../setup/vanX-ssr",
|
|
43
|
+
"@vanjs/setup": "../setup/index-ssr",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Debug specific module mappings (development only)
|
|
47
|
+
const debugModuleAliases = {
|
|
48
|
+
"@vanjs/van": "../setup/van-debug",
|
|
49
|
+
"@vanjs/setup": "../setup/index-debug",
|
|
50
|
+
};
|
|
51
|
+
|
|
22
52
|
export default function VitePluginVanJS(options = {}) {
|
|
23
53
|
const pluginConfig = { ...pluginDefaults, ...options };
|
|
24
54
|
const { routesDir } = pluginConfig;
|
|
@@ -101,71 +131,61 @@ export default function VitePluginVanJS(options = {}) {
|
|
|
101
131
|
server.watcher.on("change", changeHandler);
|
|
102
132
|
},
|
|
103
133
|
/** @type {(source: string, importer: string | undefined, ops: { ssr: boolean }) => string | null} */
|
|
104
|
-
resolveId(source, importer,
|
|
105
|
-
//
|
|
134
|
+
resolveId(source, importer, { ssr }) {
|
|
135
|
+
// Handle virtual module
|
|
106
136
|
if (source === virtualModuleId) {
|
|
107
137
|
return resolvedVirtualModuleId;
|
|
108
138
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const isSetupFile = importer &&
|
|
112
|
-
/vite-plugin-vanjs[\/\\]setup/.test(importer);
|
|
139
|
+
|
|
140
|
+
// Get the appropriate module aliases based on environment
|
|
113
141
|
const isProduction = process.env.NODE_ENV === "production";
|
|
114
142
|
const isTest = process.env.NODE_ENV === "test";
|
|
115
|
-
const
|
|
116
|
-
importer
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
? "../setup/van.mjs"
|
|
122
|
-
: "../setup/van-debug.mjs",
|
|
123
|
-
);
|
|
124
|
-
const resolvedVanX = toAbsolute(
|
|
125
|
-
ops.ssr ? "../setup/vanX-ssr.mjs" : "../setup/vanX.mjs",
|
|
143
|
+
const isSetupFile = typeof importer === "string" &&
|
|
144
|
+
importer.includes("vite-plugin-vanjs/setup");
|
|
145
|
+
const isImportedVanXFile = typeof importer === "string" &&
|
|
146
|
+
importer.includes("vite-plugin-vanjs/setup/vanX");
|
|
147
|
+
const isResolvedVanXFile = source.includes(
|
|
148
|
+
"vite-plugin-vanjs/setup/vanX",
|
|
126
149
|
);
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
? "../setup/index.mjs"
|
|
132
|
-
: "../setup/index-debug.mjs",
|
|
150
|
+
const isResolvedVanFile = !isResolvedVanXFile &&
|
|
151
|
+
source.includes("vite-plugin-vanjs/setup/van");
|
|
152
|
+
const isResolvedSetupFile = source.includes(
|
|
153
|
+
"vite-plugin-vanjs/setup/index",
|
|
133
154
|
);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
(
|
|
145
|
-
) {
|
|
146
|
-
return resolvedVan;
|
|
147
|
-
}
|
|
148
|
-
if (
|
|
149
|
-
(ops.ssr || isTest) &&
|
|
150
|
-
(source === resolvedVanX || resolvedVanX.includes(source))
|
|
151
|
-
) {
|
|
152
|
-
return resolvedVanX;
|
|
155
|
+
const isJSXImport = source.includes("/vite-plugin-vanjs/jsx/jsx") ||
|
|
156
|
+
(typeof importer === "string" &&
|
|
157
|
+
importer.includes("/vite-plugin-vanjs/jsx/jsx.mjs"));
|
|
158
|
+
const isDebugImport = !ssr && typeof importer === "string" &&
|
|
159
|
+
importer.includes("/src/van.debug.js") &&
|
|
160
|
+
source.includes("/van.js");
|
|
161
|
+
let aliases = moduleAliases;
|
|
162
|
+
|
|
163
|
+
// Handle special case for debug
|
|
164
|
+
if (isDebugImport) {
|
|
165
|
+
return toAbsolute("../setup/van.mjs");
|
|
153
166
|
}
|
|
154
167
|
|
|
155
|
-
//
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
// Select appropriate aliases based on environment
|
|
169
|
+
if (ssr) {
|
|
170
|
+
aliases = { ...aliases, ...ssrModuleAliases };
|
|
171
|
+
} else if (!isProduction && !isTest && !isJSXImport) {
|
|
172
|
+
aliases = { ...aliases, ...debugModuleAliases };
|
|
173
|
+
}
|
|
174
|
+
// Check if the source is a known module
|
|
175
|
+
const matchedSource =
|
|
176
|
+
isResolvedVanFile || (source === "vanjs-core" && !isSetupFile)
|
|
177
|
+
? "@vanjs/van"
|
|
178
|
+
: isResolvedVanXFile ||
|
|
179
|
+
(source === "vanjs-ext" && /* istanbul ignore next */
|
|
180
|
+
!isImportedVanXFile)
|
|
181
|
+
? "@vanjs/vanX"
|
|
182
|
+
: isResolvedSetupFile && (!ssr && isSetupFile || ssr && !isSetupFile)
|
|
183
|
+
? "@vanjs/setup"
|
|
184
|
+
: null;
|
|
185
|
+
const resolvedPath = matchedSource ? aliases[matchedSource] : null;
|
|
186
|
+
|
|
187
|
+
if (resolvedPath) {
|
|
188
|
+
return toAbsolute(resolvedPath + ".mjs");
|
|
169
189
|
}
|
|
170
190
|
|
|
171
191
|
return null;
|
package/server/index.mjs
CHANGED
|
@@ -80,8 +80,12 @@ export function renderPreloadLinks(modules, manifest) {
|
|
|
80
80
|
|
|
81
81
|
// First pass: collect all assets from ignored paths
|
|
82
82
|
Object.entries(manifest).forEach(([id, files]) => {
|
|
83
|
-
// istanbul ignore else
|
|
84
|
-
if (
|
|
83
|
+
// istanbul ignore else - don't pre-render routes, layouts and JSX stuff
|
|
84
|
+
if (
|
|
85
|
+
["src/pages", "src/routes", "vite-plugin-vanjs/jsx"].some((l) =>
|
|
86
|
+
id.includes(l)
|
|
87
|
+
)
|
|
88
|
+
) {
|
|
85
89
|
files.forEach((asset) => ignoredAssets.add(asset));
|
|
86
90
|
}
|
|
87
91
|
});
|