vike-lite 1.0.17 → 1.0.19
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 +4 -3
- package/dist/__internal/server.mjs +1 -1
- package/dist/server.mjs +5 -2
- package/dist/{store-CU7IkMCz.mjs → store-CfUB1COP.mjs} +4 -5
- package/dist/vite.mjs +13 -21
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -17,18 +17,19 @@ Add Vite plugin
|
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
// vite.config.ts
|
|
20
|
+
import type { UserConfig } from 'vite'
|
|
20
21
|
import vikeLite from 'vike-lite/vite'
|
|
21
22
|
|
|
22
23
|
export default {
|
|
23
24
|
plugins: [
|
|
24
25
|
vikeLite()
|
|
25
26
|
]
|
|
26
|
-
}
|
|
27
|
+
} satisfies UserConfig
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
### 🪝 Hooks
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
#### renderPage
|
|
32
33
|
```ts
|
|
33
34
|
// /server/index.ts
|
|
34
35
|
import { cors } from 'hono/cors'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as store, t as setVikeState } from "../store-
|
|
1
|
+
import { n as store, t as setVikeState } from "../store-CfUB1COP.mjs";
|
|
2
2
|
export { setVikeState, store };
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as matchRoute } from "./matchRoute-BONrLRYy.mjs";
|
|
2
|
-
import { n as store } from "./store-
|
|
2
|
+
import { n as store } from "./store-CfUB1COP.mjs";
|
|
3
3
|
//#region src/utils/serializeContext.ts
|
|
4
4
|
const ESCAPE_LOOKUP = {
|
|
5
5
|
"&": String.raw`\u0026`,
|
|
@@ -34,12 +34,15 @@ function getAssets(pageModuleId) {
|
|
|
34
34
|
};
|
|
35
35
|
const cssFiles = /* @__PURE__ */ new Set();
|
|
36
36
|
const jsFiles = /* @__PURE__ */ new Set();
|
|
37
|
+
const visitedKeys = /* @__PURE__ */ new Set();
|
|
37
38
|
const { manifest } = store;
|
|
38
39
|
function getVirtualEntryClientKey() {
|
|
39
40
|
for (const key in manifest) if (manifest[key].isEntry) return key;
|
|
40
41
|
throw new Error("entry-client not found in manifest");
|
|
41
42
|
}
|
|
42
43
|
function collectAssets(key) {
|
|
44
|
+
if (visitedKeys.has(key)) return;
|
|
45
|
+
visitedKeys.add(key);
|
|
43
46
|
const chunk = manifest[key];
|
|
44
47
|
if (!chunk) throw new Error(`Asset not found in manifest for key: ${key}`);
|
|
45
48
|
jsFiles.add(chunk.file);
|
|
@@ -52,7 +55,7 @@ function getAssets(pageModuleId) {
|
|
|
52
55
|
return {
|
|
53
56
|
cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="/${href}">`).join(""),
|
|
54
57
|
jsPreloads: [...jsFiles].map((href) => `<link rel="modulepreload" href="/${href}">`).join(""),
|
|
55
|
-
entryClient:
|
|
58
|
+
entryClient: `/${manifest[virtualEntryClientKey].file}`
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
61
|
async function buildPageContext(urlPathname, urlOriginal, isJsonRequest) {
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
//#region src/server/store.ts
|
|
2
2
|
const STORE_KEY = "_vike_lite";
|
|
3
|
-
|
|
4
|
-
if (!g[STORE_KEY]) g[STORE_KEY] = {
|
|
3
|
+
if (!Object.hasOwn(globalThis, STORE_KEY)) globalThis[STORE_KEY] = {
|
|
5
4
|
routes: [],
|
|
6
5
|
errorRoute: null,
|
|
7
6
|
config: null,
|
|
8
7
|
manifest: void 0
|
|
9
8
|
};
|
|
10
9
|
const store = new Proxy({}, {
|
|
11
|
-
get: (_, prop) =>
|
|
10
|
+
get: (_, prop) => globalThis[STORE_KEY][prop],
|
|
12
11
|
set: (_, prop, value) => {
|
|
13
|
-
|
|
12
|
+
globalThis[STORE_KEY][prop] = value;
|
|
14
13
|
return true;
|
|
15
14
|
}
|
|
16
15
|
});
|
|
17
16
|
function setVikeState(newState) {
|
|
18
|
-
Object.assign(
|
|
17
|
+
Object.assign(globalThis[STORE_KEY], newState);
|
|
19
18
|
}
|
|
20
19
|
//#endregion
|
|
21
20
|
export { store as n, setVikeState as t };
|
package/dist/vite.mjs
CHANGED
|
@@ -54,31 +54,27 @@ function generateRoutes(pagesAbsPath) {
|
|
|
54
54
|
errorRoute
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
const cssCache = /* @__PURE__ */ new Map();
|
|
58
57
|
/**
|
|
59
58
|
* Anti-FOUC: Inspect all known SSR modules, ask the client environment
|
|
60
59
|
* to translate them into plain text (thanks to ?direct) and return them.
|
|
61
60
|
*/
|
|
62
61
|
async function injectFOUCStyles(server, html) {
|
|
62
|
+
const styles = /* @__PURE__ */ new Set();
|
|
63
63
|
const ssrEnv = server.environments.ssr;
|
|
64
64
|
const clientEnv = server.environments.client;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
cssCache.set(mod.file, css);
|
|
65
|
+
for (const mod of ssrEnv.moduleGraph.idToModuleMap.values()) {
|
|
66
|
+
if (!(mod.file && /\.(css|scss|sass|less|styl|stylus)($|\?)/.test(mod.file))) continue;
|
|
67
|
+
const url = mod.url.split("?", 1)[0] + "?direct";
|
|
68
|
+
try {
|
|
69
|
+
const result = await clientEnv.transformRequest(url);
|
|
70
|
+
if (result?.code) styles.add(result.code);
|
|
72
71
|
} catch {}
|
|
73
|
-
if (css) styles.add(css);
|
|
74
72
|
}
|
|
75
73
|
if (styles.size === 0) return html;
|
|
74
|
+
const cssContent = [...styles].join("");
|
|
76
75
|
const headEndIndex = html.lastIndexOf("</head>");
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (const s of styles) cssContent += s;
|
|
80
|
-
const inlineCss = `<style type="text/css" data-vite-dev-fouc>${cssContent}</style>`;
|
|
81
|
-
return html.slice(0, headEndIndex) + inlineCss + html.slice(headEndIndex, bodyEndIndex) + `<script type="module" data-vite-dev-fouc-cleanup>requestAnimationFrame(()=>{document.querySelectorAll('[data-vite-dev-fouc]').forEach(el=>el.remove());document.currentScript?.remove();})<\/script>` + html.slice(bodyEndIndex);
|
|
76
|
+
if (headEndIndex === -1) return html;
|
|
77
|
+
return `${html.slice(0, headEndIndex)}<style type="text/css" data-vite-dev-fouc>${cssContent}</style>${html.slice(headEndIndex)}`;
|
|
82
78
|
}
|
|
83
79
|
function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", apiPrefix = "/api" } = {}) {
|
|
84
80
|
const isProd = process.env.NODE_ENV === "production";
|
|
@@ -177,11 +173,10 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
177
173
|
const manifestPath = path.join(viteConfigRoot, "../dist/client/.vite/manifest.json");
|
|
178
174
|
return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
|
|
179
175
|
}
|
|
180
|
-
if (id === resolvedVirtualEntryClientId) return `
|
|
181
|
-
import { routes, errorRoute } from '${virtualModuleId}';
|
|
176
|
+
if (id === resolvedVirtualEntryClientId) return `import { routes, errorRoute } from '${virtualModuleId}';
|
|
182
177
|
import { onRenderClient } from '${virtualAdapterId}';
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
const render = await onRenderClient();
|
|
179
|
+
await render({ routes, errorRoute });`;
|
|
185
180
|
if (id === resolvedVirtualSetupId) return `
|
|
186
181
|
import { routes, errorRoute, config } from '${virtualModuleId}';
|
|
187
182
|
import { setVikeState } from 'vike-lite/__internal/server';
|
|
@@ -243,9 +238,6 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
243
238
|
}
|
|
244
239
|
});
|
|
245
240
|
};
|
|
246
|
-
},
|
|
247
|
-
handleHotUpdate(ctx) {
|
|
248
|
-
if (/\.(css|scss|sass|less|styl|stylus)$/.test(ctx.file)) cssCache.delete(ctx.file);
|
|
249
241
|
}
|
|
250
242
|
};
|
|
251
243
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike-lite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"od": "yarn outdated"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^26.0.
|
|
46
|
+
"@types/node": "^26.0.1",
|
|
47
47
|
"@yarnpkg/sdks": "^3.3.0",
|
|
48
|
-
"eslint": "^10.
|
|
49
|
-
"eslint-plugin-unicorn": "^
|
|
48
|
+
"eslint": "^10.6.0",
|
|
49
|
+
"eslint-plugin-unicorn": "^69.0.0",
|
|
50
50
|
"tsdown": "^0.22.3",
|
|
51
51
|
"typescript": "^6.0.3",
|
|
52
52
|
"typescript-eslint": "^8.62.0",
|