vite-react-ssg 0.7.3 → 0.8.0-beta.1
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 +7 -1
- package/dist/chunks/jsdomGlobal.cjs +10 -65
- package/dist/chunks/jsdomGlobal.mjs +10 -65
- package/dist/client/single-page.cjs +8 -6
- package/dist/client/single-page.d.cts +3 -4
- package/dist/client/single-page.d.mts +3 -4
- package/dist/client/single-page.d.ts +3 -4
- package/dist/client/single-page.mjs +9 -7
- package/dist/index.cjs +19 -12
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +17 -10
- package/dist/node/cli.cjs +9 -8
- package/dist/node/cli.mjs +7 -6
- package/dist/node.cjs +22 -1713
- package/dist/node.d.cts +1 -2
- package/dist/node.d.mts +1 -2
- package/dist/node.d.ts +1 -2
- package/dist/node.mjs +17 -1707
- package/dist/shared/vite-react-ssg.4y2OEiyV.mjs +31 -0
- package/dist/shared/{vite-react-ssg.a292c181.mjs → vite-react-ssg.B6SGTWpD.mjs} +5 -4
- package/dist/shared/{vite-react-ssg.c1d49976.cjs → vite-react-ssg.BuZVBVT6.cjs} +5 -8
- package/dist/shared/{vite-react-ssg.054e813a.mjs → vite-react-ssg.C0y5wbxl.mjs} +1 -30
- package/dist/shared/{vite-react-ssg.0408f7e1.cjs → vite-react-ssg.C2GpVZF1.cjs} +0 -34
- package/dist/shared/vite-react-ssg.CFQGqC60.cjs +36 -0
- package/dist/shared/vite-react-ssg.CZ2uxKni.mjs +1029 -0
- package/dist/shared/vite-react-ssg.CjIppNIS.mjs +30 -0
- package/dist/shared/vite-react-ssg.D0EGioth.cjs +35 -0
- package/dist/shared/{vite-react-ssg.de54c34e.d.cts → vite-react-ssg.Txy2EJkI.d.cts} +25 -6
- package/dist/shared/{vite-react-ssg.de54c34e.d.mts → vite-react-ssg.Txy2EJkI.d.mts} +25 -6
- package/dist/shared/{vite-react-ssg.de54c34e.d.ts → vite-react-ssg.Txy2EJkI.d.ts} +25 -6
- package/dist/shared/vite-react-ssg.sc14Rk9F.cjs +1038 -0
- package/dist/tanstack.cjs +150 -0
- package/dist/tanstack.d.cts +29 -0
- package/dist/tanstack.d.mts +29 -0
- package/dist/tanstack.d.ts +29 -0
- package/dist/tanstack.mjs +143 -0
- package/package.json +30 -17
- /package/dist/shared/{vite-react-ssg.579feabb.mjs → vite-react-ssg.C6pK7rvr.mjs} +0 -0
- /package/dist/shared/{vite-react-ssg.bee8a5a9.cjs → vite-react-ssg.CjsEygxB.cjs} +0 -0
- /package/dist/shared/{vite-react-ssg.faf3855a.d.cts → vite-react-ssg.Cm9gBlfg.d.cts} +0 -0
- /package/dist/shared/{vite-react-ssg.faf3855a.d.mts → vite-react-ssg.Cm9gBlfg.d.mts} +0 -0
- /package/dist/shared/{vite-react-ssg.faf3855a.d.ts → vite-react-ssg.Cm9gBlfg.d.ts} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const client = require('react-dom/client');
|
|
6
|
+
const reactHelmetAsync = require('react-helmet-async');
|
|
7
|
+
const reactRouter = require('@tanstack/react-router');
|
|
8
|
+
const start = require('@tanstack/start');
|
|
9
|
+
const ClientOnly = require('./shared/vite-react-ssg.BuZVBVT6.cjs');
|
|
10
|
+
const state = require('./shared/vite-react-ssg.CjsEygxB.cjs');
|
|
11
|
+
const tanstackRouter = require('./shared/vite-react-ssg.D0EGioth.cjs');
|
|
12
|
+
const path = require('./shared/vite-react-ssg.CFQGqC60.cjs');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
|
+
|
|
16
|
+
const React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
17
|
+
|
|
18
|
+
const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
|
|
19
|
+
function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
20
|
+
const {
|
|
21
|
+
transformState,
|
|
22
|
+
rootContainer = "#root",
|
|
23
|
+
ssrWhenDev,
|
|
24
|
+
getStyleCollector = null
|
|
25
|
+
} = options;
|
|
26
|
+
if (undefined.DEV && ssrWhenDev !== void 0)
|
|
27
|
+
console.warn("[vite-react-ssg] `ssrWhenDev` option is no longer needed. If you want to use csr, just replace `vite-react-ssg dev` with `vite`.");
|
|
28
|
+
const isClient = typeof window !== "undefined";
|
|
29
|
+
const BASE_URL = routerOptions.basename ?? "/";
|
|
30
|
+
const routeTree = routerOptions.routes;
|
|
31
|
+
const OriginComponent = routeTree.options.component;
|
|
32
|
+
if (!OriginComponent[HAS_ADD_META_FLAG_KEY]) {
|
|
33
|
+
const component = () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
34
|
+
/* @__PURE__ */ jsxRuntime.jsx(OriginComponent, {}),
|
|
35
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { id: tanstackRouter.META_CONTAINER_ID, style: { display: "none" }, children: /* @__PURE__ */ jsxRuntime.jsx(start.Meta, {}) })
|
|
36
|
+
] });
|
|
37
|
+
component[HAS_ADD_META_FLAG_KEY] = true;
|
|
38
|
+
routeTree.update({
|
|
39
|
+
component
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function createRoot(client = false, routePath) {
|
|
43
|
+
const routes = await tanstackRouter.convertRouteTreeToRouteOption(
|
|
44
|
+
routerOptions.routes,
|
|
45
|
+
client,
|
|
46
|
+
client ? (node) => {
|
|
47
|
+
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
48
|
+
if (!isSSR)
|
|
49
|
+
return;
|
|
50
|
+
node.options.loader = async (ctx) => {
|
|
51
|
+
let pathname = ctx.location.pathname;
|
|
52
|
+
if (undefined.DEV) {
|
|
53
|
+
const routeId = encodeURIComponent(node.id);
|
|
54
|
+
const dataQuery = `_data=${routeId}`;
|
|
55
|
+
const href = ctx.location.href;
|
|
56
|
+
const url = href.includes("?") ? `${href}&${dataQuery}` : `${href}?${dataQuery}`;
|
|
57
|
+
const res = await fetch(url);
|
|
58
|
+
const header = res.headers;
|
|
59
|
+
const contentType = header.get("content-type");
|
|
60
|
+
if (contentType?.startsWith("application/json"))
|
|
61
|
+
return res.json();
|
|
62
|
+
return res.text();
|
|
63
|
+
}
|
|
64
|
+
let staticLoadData;
|
|
65
|
+
if (window.__VITE_REACT_SSG_STATIC_LOADER_DATA__) {
|
|
66
|
+
staticLoadData = window.__VITE_REACT_SSG_STATIC_LOADER_DATA__;
|
|
67
|
+
} else {
|
|
68
|
+
const manifestUrl = path.joinUrlSegments(BASE_URL, `static-loader-data-manifest-${window.__VITE_REACT_SSG_HASH__}.json`);
|
|
69
|
+
staticLoadData = await (await fetch(path.withLeadingSlash(manifestUrl))).json();
|
|
70
|
+
window.__VITE_REACT_SSG_STATIC_LOADER_DATA__ = staticLoadData;
|
|
71
|
+
}
|
|
72
|
+
if (BASE_URL !== "/") {
|
|
73
|
+
pathname = path.stripBase(pathname, BASE_URL);
|
|
74
|
+
}
|
|
75
|
+
const routeData = staticLoadData?.[pathname]?.find((item) => item.id === node.id);
|
|
76
|
+
return routeData?.loaderData ?? null;
|
|
77
|
+
};
|
|
78
|
+
} : void 0
|
|
79
|
+
);
|
|
80
|
+
const router = routerOptions.router;
|
|
81
|
+
router.options.isServer = !client;
|
|
82
|
+
const appRenderCallbacks = [];
|
|
83
|
+
const onSSRAppRendered = client ? () => {
|
|
84
|
+
} : (cb) => appRenderCallbacks.push(cb);
|
|
85
|
+
const triggerOnSSRAppRendered = () => {
|
|
86
|
+
return Promise.all(appRenderCallbacks.map((cb) => cb()));
|
|
87
|
+
};
|
|
88
|
+
const context = {
|
|
89
|
+
isClient,
|
|
90
|
+
routes,
|
|
91
|
+
routeTree,
|
|
92
|
+
router,
|
|
93
|
+
routerOptions: {
|
|
94
|
+
routes,
|
|
95
|
+
basename: BASE_URL
|
|
96
|
+
},
|
|
97
|
+
onSSRAppRendered,
|
|
98
|
+
triggerOnSSRAppRendered,
|
|
99
|
+
initialState: {},
|
|
100
|
+
transformState,
|
|
101
|
+
routePath,
|
|
102
|
+
base: BASE_URL,
|
|
103
|
+
getStyleCollector,
|
|
104
|
+
routerType: "tanstack"
|
|
105
|
+
};
|
|
106
|
+
if (client) {
|
|
107
|
+
await ClientOnly.documentReady();
|
|
108
|
+
context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || state.deserializeState(window.__INITIAL_STATE__);
|
|
109
|
+
}
|
|
110
|
+
await fn?.(context);
|
|
111
|
+
const initialState = context.initialState;
|
|
112
|
+
return {
|
|
113
|
+
...context,
|
|
114
|
+
initialState
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (isClient) {
|
|
118
|
+
(async () => {
|
|
119
|
+
const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;
|
|
120
|
+
if (!container) {
|
|
121
|
+
if (typeof $jsdom === "undefined")
|
|
122
|
+
console.warn("[vite-react-ssg] Root container not found.");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { router } = await createRoot(true);
|
|
126
|
+
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
127
|
+
if (!isSSR && undefined.DEV) {
|
|
128
|
+
const root = client.createRoot(container);
|
|
129
|
+
React__default.startTransition(() => {
|
|
130
|
+
root.render(
|
|
131
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouter.RouterProvider, { router }) })
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
React__default.startTransition(() => {
|
|
136
|
+
client.hydrateRoot(
|
|
137
|
+
container,
|
|
138
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(start.StartClient, { router }) })
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
})();
|
|
143
|
+
}
|
|
144
|
+
return createRoot;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
exports.ClientOnly = ClientOnly.ClientOnly;
|
|
148
|
+
exports.Head = ClientOnly.Head;
|
|
149
|
+
exports.registerPaths = tanstackRouter.registerPaths;
|
|
150
|
+
exports.ViteReactSSG = ViteReactSSG;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AnyRouter } from '@tanstack/react-router';
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
|
|
3
|
+
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.cjs';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'react-router-dom';
|
|
7
|
+
import 'react-helmet-async';
|
|
8
|
+
|
|
9
|
+
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
10
|
+
|
|
11
|
+
interface RouterOptions {
|
|
12
|
+
router: AnyRouter;
|
|
13
|
+
routes: AnyRouter['routeTree'];
|
|
14
|
+
basename?: string;
|
|
15
|
+
}
|
|
16
|
+
type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGContext$1, 'router' | 'routerType'> & {
|
|
17
|
+
router: HasRouter extends true ? AnyRouter : undefined;
|
|
18
|
+
routeTree?: AnyRouter['routeTree'];
|
|
19
|
+
routerType: 'tanstack';
|
|
20
|
+
};
|
|
21
|
+
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
25
|
+
__VITE_REACT_SSG_HASH__: string;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { type RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AnyRouter } from '@tanstack/react-router';
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
|
|
3
|
+
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.mjs';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'react-router-dom';
|
|
7
|
+
import 'react-helmet-async';
|
|
8
|
+
|
|
9
|
+
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
10
|
+
|
|
11
|
+
interface RouterOptions {
|
|
12
|
+
router: AnyRouter;
|
|
13
|
+
routes: AnyRouter['routeTree'];
|
|
14
|
+
basename?: string;
|
|
15
|
+
}
|
|
16
|
+
type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGContext$1, 'router' | 'routerType'> & {
|
|
17
|
+
router: HasRouter extends true ? AnyRouter : undefined;
|
|
18
|
+
routeTree?: AnyRouter['routeTree'];
|
|
19
|
+
routerType: 'tanstack';
|
|
20
|
+
};
|
|
21
|
+
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
25
|
+
__VITE_REACT_SSG_HASH__: string;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { type RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AnyRouter } from '@tanstack/react-router';
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
|
|
3
|
+
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.js';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'react-router-dom';
|
|
7
|
+
import 'react-helmet-async';
|
|
8
|
+
|
|
9
|
+
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
10
|
+
|
|
11
|
+
interface RouterOptions {
|
|
12
|
+
router: AnyRouter;
|
|
13
|
+
routes: AnyRouter['routeTree'];
|
|
14
|
+
basename?: string;
|
|
15
|
+
}
|
|
16
|
+
type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGContext$1, 'router' | 'routerType'> & {
|
|
17
|
+
router: HasRouter extends true ? AnyRouter : undefined;
|
|
18
|
+
routeTree?: AnyRouter['routeTree'];
|
|
19
|
+
routerType: 'tanstack';
|
|
20
|
+
};
|
|
21
|
+
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
25
|
+
__VITE_REACT_SSG_HASH__: string;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { type RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
4
|
+
import { HelmetProvider } from 'react-helmet-async';
|
|
5
|
+
import { RouterProvider } from '@tanstack/react-router';
|
|
6
|
+
import { StartClient, Meta } from '@tanstack/start';
|
|
7
|
+
import { d as documentReady } from './shared/vite-react-ssg.B6SGTWpD.mjs';
|
|
8
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.B6SGTWpD.mjs';
|
|
9
|
+
import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
|
|
10
|
+
import { M as META_CONTAINER_ID, c as convertRouteTreeToRouteOption } from './shared/vite-react-ssg.4y2OEiyV.mjs';
|
|
11
|
+
export { r as registerPaths } from './shared/vite-react-ssg.4y2OEiyV.mjs';
|
|
12
|
+
import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
|
|
13
|
+
|
|
14
|
+
const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
|
|
15
|
+
function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
16
|
+
const {
|
|
17
|
+
transformState,
|
|
18
|
+
rootContainer = "#root",
|
|
19
|
+
ssrWhenDev,
|
|
20
|
+
getStyleCollector = null
|
|
21
|
+
} = options;
|
|
22
|
+
if (import.meta.env.DEV && ssrWhenDev !== void 0)
|
|
23
|
+
console.warn("[vite-react-ssg] `ssrWhenDev` option is no longer needed. If you want to use csr, just replace `vite-react-ssg dev` with `vite`.");
|
|
24
|
+
const isClient = typeof window !== "undefined";
|
|
25
|
+
const BASE_URL = routerOptions.basename ?? "/";
|
|
26
|
+
const routeTree = routerOptions.routes;
|
|
27
|
+
const OriginComponent = routeTree.options.component;
|
|
28
|
+
if (!OriginComponent[HAS_ADD_META_FLAG_KEY]) {
|
|
29
|
+
const component = () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
30
|
+
/* @__PURE__ */ jsx(OriginComponent, {}),
|
|
31
|
+
/* @__PURE__ */ jsx("div", { id: META_CONTAINER_ID, style: { display: "none" }, children: /* @__PURE__ */ jsx(Meta, {}) })
|
|
32
|
+
] });
|
|
33
|
+
component[HAS_ADD_META_FLAG_KEY] = true;
|
|
34
|
+
routeTree.update({
|
|
35
|
+
component
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function createRoot$1(client = false, routePath) {
|
|
39
|
+
const routes = await convertRouteTreeToRouteOption(
|
|
40
|
+
routerOptions.routes,
|
|
41
|
+
client,
|
|
42
|
+
client ? (node) => {
|
|
43
|
+
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
44
|
+
if (!isSSR)
|
|
45
|
+
return;
|
|
46
|
+
node.options.loader = async (ctx) => {
|
|
47
|
+
let pathname = ctx.location.pathname;
|
|
48
|
+
if (import.meta.env.DEV) {
|
|
49
|
+
const routeId = encodeURIComponent(node.id);
|
|
50
|
+
const dataQuery = `_data=${routeId}`;
|
|
51
|
+
const href = ctx.location.href;
|
|
52
|
+
const url = href.includes("?") ? `${href}&${dataQuery}` : `${href}?${dataQuery}`;
|
|
53
|
+
const res = await fetch(url);
|
|
54
|
+
const header = res.headers;
|
|
55
|
+
const contentType = header.get("content-type");
|
|
56
|
+
if (contentType?.startsWith("application/json"))
|
|
57
|
+
return res.json();
|
|
58
|
+
return res.text();
|
|
59
|
+
}
|
|
60
|
+
let staticLoadData;
|
|
61
|
+
if (window.__VITE_REACT_SSG_STATIC_LOADER_DATA__) {
|
|
62
|
+
staticLoadData = window.__VITE_REACT_SSG_STATIC_LOADER_DATA__;
|
|
63
|
+
} else {
|
|
64
|
+
const manifestUrl = joinUrlSegments(BASE_URL, `static-loader-data-manifest-${window.__VITE_REACT_SSG_HASH__}.json`);
|
|
65
|
+
staticLoadData = await (await fetch(withLeadingSlash(manifestUrl))).json();
|
|
66
|
+
window.__VITE_REACT_SSG_STATIC_LOADER_DATA__ = staticLoadData;
|
|
67
|
+
}
|
|
68
|
+
if (BASE_URL !== "/") {
|
|
69
|
+
pathname = stripBase(pathname, BASE_URL);
|
|
70
|
+
}
|
|
71
|
+
const routeData = staticLoadData?.[pathname]?.find((item) => item.id === node.id);
|
|
72
|
+
return routeData?.loaderData ?? null;
|
|
73
|
+
};
|
|
74
|
+
} : void 0
|
|
75
|
+
);
|
|
76
|
+
const router = routerOptions.router;
|
|
77
|
+
router.options.isServer = !client;
|
|
78
|
+
const appRenderCallbacks = [];
|
|
79
|
+
const onSSRAppRendered = client ? () => {
|
|
80
|
+
} : (cb) => appRenderCallbacks.push(cb);
|
|
81
|
+
const triggerOnSSRAppRendered = () => {
|
|
82
|
+
return Promise.all(appRenderCallbacks.map((cb) => cb()));
|
|
83
|
+
};
|
|
84
|
+
const context = {
|
|
85
|
+
isClient,
|
|
86
|
+
routes,
|
|
87
|
+
routeTree,
|
|
88
|
+
router,
|
|
89
|
+
routerOptions: {
|
|
90
|
+
routes,
|
|
91
|
+
basename: BASE_URL
|
|
92
|
+
},
|
|
93
|
+
onSSRAppRendered,
|
|
94
|
+
triggerOnSSRAppRendered,
|
|
95
|
+
initialState: {},
|
|
96
|
+
transformState,
|
|
97
|
+
routePath,
|
|
98
|
+
base: BASE_URL,
|
|
99
|
+
getStyleCollector,
|
|
100
|
+
routerType: "tanstack"
|
|
101
|
+
};
|
|
102
|
+
if (client) {
|
|
103
|
+
await documentReady();
|
|
104
|
+
context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || deserializeState(window.__INITIAL_STATE__);
|
|
105
|
+
}
|
|
106
|
+
await fn?.(context);
|
|
107
|
+
const initialState = context.initialState;
|
|
108
|
+
return {
|
|
109
|
+
...context,
|
|
110
|
+
initialState
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (isClient) {
|
|
114
|
+
(async () => {
|
|
115
|
+
const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;
|
|
116
|
+
if (!container) {
|
|
117
|
+
if (typeof $jsdom === "undefined")
|
|
118
|
+
console.warn("[vite-react-ssg] Root container not found.");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const { router } = await createRoot$1(true);
|
|
122
|
+
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
123
|
+
if (!isSSR && import.meta.env.DEV) {
|
|
124
|
+
const root = createRoot(container);
|
|
125
|
+
React.startTransition(() => {
|
|
126
|
+
root.render(
|
|
127
|
+
/* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) })
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
React.startTransition(() => {
|
|
132
|
+
hydrateRoot(
|
|
133
|
+
container,
|
|
134
|
+
/* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(StartClient, { router }) })
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
}
|
|
140
|
+
return createRoot$1;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { ViteReactSSG };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-react-ssg",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@9.
|
|
4
|
+
"version": "0.8.0-beta.1",
|
|
5
|
+
"packageManager": "pnpm@9.10.0",
|
|
6
6
|
"description": "Static-site generation for React on Vite.",
|
|
7
7
|
"author": "Riri <Daydreamerriri@outlook.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
"import": "./dist/client/single-page.mjs",
|
|
37
37
|
"require": "./dist/client/single-page.cjs"
|
|
38
38
|
},
|
|
39
|
+
"./tanstack": {
|
|
40
|
+
"types": "./dist/tanstack.d.ts",
|
|
41
|
+
"import": "./dist/tanstack.mjs",
|
|
42
|
+
"require": "./dist/tanstack.cjs"
|
|
43
|
+
},
|
|
39
44
|
"./style-collectors/styled-components": {
|
|
40
45
|
"types": "./dist/style-collectors/styled-components.d.ts",
|
|
41
46
|
"import": "./dist/style-collectors/styled-components.mjs",
|
|
@@ -86,6 +91,12 @@
|
|
|
86
91
|
"vite": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
87
92
|
},
|
|
88
93
|
"peerDependenciesMeta": {
|
|
94
|
+
"@tanstack/react-router": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"@tanstack/start": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
89
100
|
"critters": {
|
|
90
101
|
"optional": true
|
|
91
102
|
},
|
|
@@ -103,35 +114,37 @@
|
|
|
103
114
|
"@remix-run/web-fetch": "^4.4.2",
|
|
104
115
|
"fs-extra": "^11.2.0",
|
|
105
116
|
"html5parser": "^2.0.2",
|
|
106
|
-
"jsdom": "^24.1.
|
|
117
|
+
"jsdom": "^24.1.3",
|
|
107
118
|
"kolorist": "^1.8.0",
|
|
119
|
+
"p-queue": "^8.0.1",
|
|
108
120
|
"react-helmet-async": "^1.3.0",
|
|
109
121
|
"yargs": "^17.7.2"
|
|
110
122
|
},
|
|
111
123
|
"devDependencies": {
|
|
112
|
-
"@ririd/eslint-config": "^1.3.
|
|
124
|
+
"@ririd/eslint-config": "^1.3.4",
|
|
125
|
+
"@tanstack/react-router": "^1.57.15",
|
|
126
|
+
"@tanstack/start": "^1.57.15",
|
|
113
127
|
"@types/fs-extra": "^11.0.4",
|
|
114
128
|
"@types/jsdom": "^21.1.7",
|
|
115
|
-
"@types/node": "^18.19.
|
|
116
|
-
"@types/react": "
|
|
117
|
-
"@types/react-dom": "
|
|
129
|
+
"@types/node": "^18.19.50",
|
|
130
|
+
"@types/react": "~18.2.14",
|
|
131
|
+
"@types/react-dom": "~18.2.6",
|
|
118
132
|
"@types/yargs": "^17.0.33",
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
133
|
+
"@vitejs/plugin-react-swc": "^3.7.1",
|
|
134
|
+
"bumpp": "^9.5.2",
|
|
135
|
+
"critters": "^0.0.24",
|
|
136
|
+
"eslint": "^9.10.0",
|
|
122
137
|
"esno": "^4.7.0",
|
|
123
138
|
"fast-glob": "3.3.2",
|
|
124
|
-
"
|
|
125
|
-
"prettier": "^3.2.4",
|
|
139
|
+
"prettier": "^3.3.3",
|
|
126
140
|
"react": "^18.2.0",
|
|
127
141
|
"react-dom": "^18.2.0",
|
|
128
|
-
"react-router-dom": "^6.
|
|
142
|
+
"react-router-dom": "^6.26.2",
|
|
129
143
|
"rimraf": "5.0.1",
|
|
130
144
|
"styled-components": "6.0.5",
|
|
131
|
-
"typescript": "^5.
|
|
132
|
-
"unbuild": "^
|
|
133
|
-
"vite": "^5.4.
|
|
134
|
-
"vite-plugin-pwa": "^0.17.5",
|
|
145
|
+
"typescript": "^5.6.2",
|
|
146
|
+
"unbuild": "^3.0.0-rc.11",
|
|
147
|
+
"vite": "^5.4.9",
|
|
135
148
|
"vitest": "1.6.0"
|
|
136
149
|
}
|
|
137
150
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|