vite-plugin-vanjs 0.1.19 → 0.1.20
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 +2 -2
- package/plugin/helpers.mjs +14 -2
- package/plugin/index.mjs +2 -0
- package/plugin/types.d.ts +2 -0
- package/server/index.mjs +6 -14
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
|
|
|
8
|
-
|
|
8
|
+
An async first mini meta-framework for [VanJS](https://vanjs.org/) developed around the awesome [vite](https://vite.dev) and tested with [vitest](https://vitest.dev). The plugin comes with a set of modules to streamline your workflow:
|
|
9
9
|
* ***@vanjs/router*** - one of the most important part of an application which allows you to split code and lazy load page like components with ease, handles both Client Side Rendering (SSR) and Server Side Rendering (CSR) and makes it really easy to work with;
|
|
10
10
|
* ***@vanjs/meta*** - allows you to create metadata for your pages as well as load additional assets with ease;
|
|
11
11
|
* ***@vanjs/jsx*** - enables JSX transformation with automatic namespace resolution;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vanjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"author": "thednp",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "An async first mini meta-framework for VanJS powered by Vite",
|
|
7
7
|
"repository": "https://github.com/thednp/vite-plugin-vanjs",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"sideEffects": false,
|
package/plugin/helpers.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { dirname, join, posix, win32 } from "node:path";
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
import { readdir } from "node:fs/promises";
|
|
10
|
+
import process from "node:process";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Get the file most probable route path for a given potential route.
|
|
@@ -194,10 +195,21 @@ export const processLayoutRoutes = (routes, config, pluginConfig) => {
|
|
|
194
195
|
* Scan and process routes and return them
|
|
195
196
|
* @type {typeof import("./types").getRoutes}
|
|
196
197
|
*/
|
|
197
|
-
// export const scanRoutes = async (config, pluginConfig) => {}
|
|
198
198
|
export const getRoutes = async (config, pluginConfig) => {
|
|
199
199
|
const routes = await scanRoutes(config, pluginConfig);
|
|
200
|
-
|
|
200
|
+
const processed = processLayoutRoutes(routes, config, pluginConfig);
|
|
201
|
+
// istanbul ignore next - defaults can't be checked
|
|
202
|
+
const { excludeRoutes = [], excludeRoutesProd = [] } = pluginConfig;
|
|
203
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
204
|
+
const allExcludes = [...excludeRoutes, ...(isProd ? excludeRoutesProd : [])];
|
|
205
|
+
if (allExcludes.length) {
|
|
206
|
+
return processed.filter((r) =>
|
|
207
|
+
!allExcludes.some((p) =>
|
|
208
|
+
r.routePath === p || r.routePath.startsWith(p + "/")
|
|
209
|
+
)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return processed;
|
|
201
213
|
};
|
|
202
214
|
|
|
203
215
|
/** @type {(route: RouteFile) => string} */
|
package/plugin/index.mjs
CHANGED
package/plugin/types.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import type { Plugin } from "vite";
|
|
|
10
10
|
export type VanJSPluginOptions = {
|
|
11
11
|
routesDir?: string;
|
|
12
12
|
extensions?: string[];
|
|
13
|
+
excludeRoutes?: string[]; // NEW — excluded in all envs
|
|
14
|
+
excludeRoutesProd?: string[]; // NEW — excluded in production only
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export declare const VitePluginVanJS: (
|
package/server/index.mjs
CHANGED
|
@@ -46,25 +46,17 @@ export const renderToString = async (inputSource) => {
|
|
|
46
46
|
* @param {string} file
|
|
47
47
|
* @returns {string}
|
|
48
48
|
*/
|
|
49
|
+
// return `<link rel="preload" href="${file}" as="style" crossorigin>`;
|
|
49
50
|
function renderPreloadLink(file) {
|
|
50
51
|
if (file.endsWith(".js")) {
|
|
51
|
-
return `<link rel="
|
|
52
|
+
return `<link rel="modulepreload" href="${file}" crossorigin>`;
|
|
52
53
|
} else if (file.endsWith(".css")) {
|
|
53
|
-
return `<link rel="
|
|
54
|
+
return `<link rel="stylesheet" href="${file}" crossorigin>`;
|
|
54
55
|
} else if (file.endsWith(".woff")) {
|
|
55
|
-
return
|
|
56
|
+
return `<link rel="preload" href="${file}" as="font" type="font/woff" crossorigin>`;
|
|
56
57
|
} else if (file.endsWith(".woff2")) {
|
|
57
|
-
return
|
|
58
|
-
} else if (file.endsWith(".gif")) {
|
|
59
|
-
return `<link rel="preload" href="${file}" as="image" type="image/gif">`;
|
|
60
|
-
} else if (file.endsWith(".jpg") || file.endsWith(".jpeg")) {
|
|
61
|
-
return `<link rel="preload" href="${file}" as="image" type="image/jpeg">`;
|
|
62
|
-
} else if (file.endsWith(".png")) {
|
|
63
|
-
return `<link rel="preload" href="${file}" as="image" type="image/png">`;
|
|
64
|
-
} else if (file.endsWith(".webp")) {
|
|
65
|
-
return `<link rel="preload" href="${file}" as="image" type="image/webp">`;
|
|
58
|
+
return `<link rel="preload" href="${file}" as="font" type="font/woff2" crossorigin>`;
|
|
66
59
|
} else {
|
|
67
|
-
// @ts-ignore - this is server side code
|
|
68
60
|
console.warn("Render error! File format not recognized: " + file);
|
|
69
61
|
return "";
|
|
70
62
|
}
|
|
@@ -131,7 +123,7 @@ export const getDataPreload = () => {
|
|
|
131
123
|
|
|
132
124
|
if (cacheEntries.length > 0) {
|
|
133
125
|
const json = JSON.stringify(cacheJSON);
|
|
134
|
-
return `<script id="data-cache">window.__DATA_CACHE=${json}
|
|
126
|
+
return `<script id="data-cache">window.__DATA_CACHE=${json};</script>`;
|
|
135
127
|
}
|
|
136
128
|
return "";
|
|
137
129
|
};
|