vite-react-ssg 0.8.4 → 0.8.5
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 +10 -8
- package/dist/client/single-page.d.mts +4 -4
- package/dist/client/single-page.d.ts +4 -4
- package/dist/client/single-page.mjs +7 -6
- package/dist/index.d.mts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.mjs +10 -8
- package/dist/node/cli.mjs +9 -9
- package/dist/node.d.mts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.mjs +7 -7
- package/dist/shared/{vite-react-ssg.Cm9gBlfg.d.ts → vite-react-ssg.-NlgsPvg.d.mts} +8 -8
- package/dist/shared/{vite-react-ssg.Cm9gBlfg.d.mts → vite-react-ssg.-NlgsPvg.d.ts} +8 -8
- package/dist/shared/{vite-react-ssg.C0y5wbxl.mjs → vite-react-ssg.C_MPXL9p.mjs} +1 -1
- package/dist/shared/{vite-react-ssg.Di0pROyF.d.cts → vite-react-ssg.D2OE2Bw1.d.mts} +6 -1
- package/dist/shared/{vite-react-ssg.Di0pROyF.d.mts → vite-react-ssg.D2OE2Bw1.d.ts} +6 -1
- package/dist/shared/{vite-react-ssg.CfJcpdWF.mjs → vite-react-ssg.Dx4ca9OM.mjs} +18 -4
- package/dist/shared/{vite-react-ssg.CKcl-j8g.mjs → vite-react-ssg.EDckwhJo.mjs} +222 -218
- package/dist/tanstack.d.mts +5 -4
- package/dist/tanstack.d.ts +5 -4
- package/dist/tanstack.mjs +9 -7
- package/package.json +32 -33
- package/dist/chunks/jsdomGlobal.cjs +0 -36
- package/dist/client/single-page.cjs +0 -75
- package/dist/client/single-page.d.cts +0 -11
- package/dist/index.cjs +0 -196
- package/dist/index.d.cts +0 -26
- package/dist/node/cli.cjs +0 -89
- package/dist/node/cli.d.cts +0 -2
- package/dist/node.cjs +0 -24
- package/dist/node.d.cts +0 -11
- package/dist/shared/vite-react-ssg.B4jDfvXh.cjs +0 -106
- package/dist/shared/vite-react-ssg.C2GpVZF1.cjs +0 -38
- package/dist/shared/vite-react-ssg.CFQGqC60.cjs +0 -36
- package/dist/shared/vite-react-ssg.CjsEygxB.cjs +0 -37
- package/dist/shared/vite-react-ssg.Cm9gBlfg.d.cts +0 -15
- package/dist/shared/vite-react-ssg.DWHmkjdM.cjs +0 -35
- package/dist/shared/vite-react-ssg.Di0pROyF.d.ts +0 -214
- package/dist/shared/vite-react-ssg.Dus0yLsZ.cjs +0 -1082
- package/dist/style-collectors/styled-components.cjs +0 -20
- package/dist/style-collectors/styled-components.d.cts +0 -9
- package/dist/tanstack.cjs +0 -144
- package/dist/tanstack.d.cts +0 -30
|
@@ -1,89 +1,81 @@
|
|
|
1
|
-
import { join, isAbsolute, parse, dirname } from 'node:path';
|
|
2
1
|
import { createRequire } from 'node:module';
|
|
2
|
+
import { join, isAbsolute, parse, dirname } from 'node:path';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import { JSDOM } from 'jsdom';
|
|
3
5
|
import { gray, yellow, blue, dim, cyan, red, green, reset, bold, bgLightCyan } from 'kolorist';
|
|
4
6
|
import PQueue from 'p-queue';
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
7
|
import { resolveConfig, createLogger, build as build$1, mergeConfig, version as version$1, send, createServer } from 'vite';
|
|
7
|
-
import { JSDOM } from 'jsdom';
|
|
8
|
-
import { s as serializeState } from './vite-react-ssg.C6pK7rvr.mjs';
|
|
9
8
|
import { a as withTrailingSlash, r as removeLeadingSlash, w as withLeadingSlash, s as stripBase, j as joinUrlSegments } from './vite-react-ssg.CjIppNIS.mjs';
|
|
9
|
+
import { s as serializeState } from './vite-react-ssg.C6pK7rvr.mjs';
|
|
10
10
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
11
11
|
import { HelmetProvider } from 'react-helmet-async';
|
|
12
|
-
import { Writable, Readable } from 'node:stream';
|
|
13
|
-
import * as ReactDomServer from 'react-dom/server';
|
|
14
12
|
import { once } from 'node:events';
|
|
15
|
-
import {
|
|
13
|
+
import { Readable, Writable } from 'node:stream';
|
|
14
|
+
import { c as convertRoutesToDataRoutes } from './vite-react-ssg.C_MPXL9p.mjs';
|
|
15
|
+
import * as ReactDomServer from 'react-dom/server';
|
|
16
16
|
import { M as META_CONTAINER_ID } from './vite-react-ssg.B-j07kW6.mjs';
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const lazyData = await route.lazy();
|
|
36
|
-
if (lazyData) {
|
|
37
|
-
route = {
|
|
38
|
-
...route,
|
|
39
|
-
...lazyData
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let path = route.path;
|
|
44
|
-
path = handlePath(path, prefix);
|
|
45
|
-
if (route.getStaticPaths && isDynamicSegmentsRoute(path)) {
|
|
46
|
-
const staticPaths = await route.getStaticPaths();
|
|
47
|
-
for (let staticPath of staticPaths) {
|
|
48
|
-
staticPath = handlePath(staticPath, prefix);
|
|
49
|
-
if (Array.isArray(route.children))
|
|
50
|
-
await getPaths(route.children, staticPath);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (route.index && !path) {
|
|
54
|
-
paths.add("/");
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(route.children))
|
|
57
|
-
await getPaths(route.children, path);
|
|
18
|
+
const DYNAMIC_IMPORT_REGEX = /import\("([^)]+)"\)/g;
|
|
19
|
+
async function collectAssets({
|
|
20
|
+
routes,
|
|
21
|
+
locationArg,
|
|
22
|
+
base,
|
|
23
|
+
serverManifest,
|
|
24
|
+
manifest,
|
|
25
|
+
ssrManifest
|
|
26
|
+
}) {
|
|
27
|
+
const { matchRoutes } = await import('react-router-dom');
|
|
28
|
+
const matches = matchRoutes([...routes], locationArg, base);
|
|
29
|
+
const routeEntries = matches?.map((item) => item.route.entry).filter(Boolean) ?? [];
|
|
30
|
+
const dynamicImports = /* @__PURE__ */ new Set();
|
|
31
|
+
matches?.forEach((item) => {
|
|
32
|
+
let lazyStr = "";
|
|
33
|
+
if (item.route.lazy) {
|
|
34
|
+
lazyStr += item.route.lazy.toString();
|
|
58
35
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return { paths: Array.from(paths) };
|
|
62
|
-
function handlePath(path, prefix) {
|
|
63
|
-
if (path != null) {
|
|
64
|
-
path = prefix && !path.startsWith("/") ? `${prefix}${path ? `/${path}` : ""}` : path;
|
|
65
|
-
paths.add(path);
|
|
36
|
+
if (item.route.Component?._payload?._result) {
|
|
37
|
+
lazyStr += item.route.Component._payload._result.toString();
|
|
66
38
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
39
|
+
const match = lazyStr.matchAll(DYNAMIC_IMPORT_REGEX);
|
|
40
|
+
for (const m of match) {
|
|
41
|
+
dynamicImports.add(m[1].split("/").at(-1) ?? "");
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const entries = /* @__PURE__ */ new Set();
|
|
45
|
+
routeEntries.forEach((e) => entries.add(e));
|
|
46
|
+
const manifestEntries = [...Object.entries(serverManifest)];
|
|
47
|
+
dynamicImports.forEach((name) => {
|
|
48
|
+
const result = manifestEntries.find(([_, value]) => value.file.endsWith(name));
|
|
49
|
+
if (result) {
|
|
50
|
+
entries.add(result[0]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const modules = collectModulesForEntries(manifest, entries);
|
|
54
|
+
const assets = /* @__PURE__ */ new Set();
|
|
55
|
+
Array.from(modules).forEach((id) => {
|
|
56
|
+
const files = ssrManifest[id] || [];
|
|
57
|
+
files.forEach((file) => {
|
|
58
|
+
assets.add(file);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return assets;
|
|
74
62
|
}
|
|
75
|
-
function
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
function collectModulesForEntries(manifest, entries) {
|
|
64
|
+
const mods = /* @__PURE__ */ new Set();
|
|
65
|
+
if (!entries)
|
|
66
|
+
return mods;
|
|
67
|
+
for (const entry of entries)
|
|
68
|
+
collectModules(manifest, entry, mods);
|
|
69
|
+
return mods;
|
|
81
70
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
function collectModules(manifest, entry, mods = /* @__PURE__ */ new Set()) {
|
|
72
|
+
if (!entry)
|
|
73
|
+
return mods;
|
|
74
|
+
mods.add(entry);
|
|
75
|
+
manifest[entry]?.dynamicImports?.forEach((item) => {
|
|
76
|
+
collectModules(manifest, item, mods);
|
|
77
|
+
});
|
|
78
|
+
return mods;
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
async function getBeastiesOrCritters(outDir, options = {}) {
|
|
@@ -111,7 +103,7 @@ async function getBeastiesOrCritters(outDir, options = {}) {
|
|
|
111
103
|
...options
|
|
112
104
|
});
|
|
113
105
|
} catch (e) {
|
|
114
|
-
return
|
|
106
|
+
return undefined;
|
|
115
107
|
}
|
|
116
108
|
}
|
|
117
109
|
|
|
@@ -160,9 +152,9 @@ async function renderHTML({
|
|
|
160
152
|
throw new Error(`Could not find a tag with id="${rootContainerId}" to replace it with server-side rendered HTML`);
|
|
161
153
|
return renderedOutput;
|
|
162
154
|
}
|
|
163
|
-
async function detectEntry(root) {
|
|
155
|
+
async function detectEntry(root, htmlEntry = "index.html") {
|
|
164
156
|
const scriptSrcReg = /<script(?:.*?)src=["'](.+?)["'](?!<)(?:.*)\>(?:[\n\r\s]*?)(?:<\/script>)/gim;
|
|
165
|
-
const html = await fs.readFile(join(root,
|
|
157
|
+
const html = await fs.readFile(join(root, htmlEntry), "utf-8");
|
|
166
158
|
const scripts = [...html.matchAll(scriptSrcReg)];
|
|
167
159
|
const [, entry] = scripts.find((matchResult) => {
|
|
168
160
|
const [script] = matchResult;
|
|
@@ -233,138 +225,6 @@ function appendLink(document, attrs) {
|
|
|
233
225
|
document.head.appendChild(link);
|
|
234
226
|
}
|
|
235
227
|
|
|
236
|
-
const DYNAMIC_IMPORT_REGEX = /import\("([^)]+)"\)/g;
|
|
237
|
-
async function collectAssets({
|
|
238
|
-
routes,
|
|
239
|
-
locationArg,
|
|
240
|
-
base,
|
|
241
|
-
serverManifest,
|
|
242
|
-
manifest,
|
|
243
|
-
ssrManifest
|
|
244
|
-
}) {
|
|
245
|
-
const { matchRoutes } = await import('react-router-dom');
|
|
246
|
-
const matches = matchRoutes([...routes], locationArg, base);
|
|
247
|
-
const routeEntries = matches?.map((item) => item.route.entry).filter(Boolean) ?? [];
|
|
248
|
-
const dynamicImports = /* @__PURE__ */ new Set();
|
|
249
|
-
matches?.forEach((item) => {
|
|
250
|
-
let lazyStr = "";
|
|
251
|
-
if (item.route.lazy) {
|
|
252
|
-
lazyStr += item.route.lazy.toString();
|
|
253
|
-
}
|
|
254
|
-
if (item.route.Component?._payload?._result) {
|
|
255
|
-
lazyStr += item.route.Component._payload._result.toString();
|
|
256
|
-
}
|
|
257
|
-
const match = lazyStr.matchAll(DYNAMIC_IMPORT_REGEX);
|
|
258
|
-
for (const m of match) {
|
|
259
|
-
dynamicImports.add(m[1].split("/").at(-1) ?? "");
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
const entries = /* @__PURE__ */ new Set();
|
|
263
|
-
routeEntries.forEach((e) => entries.add(e));
|
|
264
|
-
const manifestEntries = [...Object.entries(serverManifest)];
|
|
265
|
-
dynamicImports.forEach((name) => {
|
|
266
|
-
const result = manifestEntries.find(([_, value]) => value.file.endsWith(name));
|
|
267
|
-
if (result) {
|
|
268
|
-
entries.add(result[0]);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
const modules = collectModulesForEntries(manifest, entries);
|
|
272
|
-
const assets = /* @__PURE__ */ new Set();
|
|
273
|
-
Array.from(modules).forEach((id) => {
|
|
274
|
-
const files = ssrManifest[id] || [];
|
|
275
|
-
files.forEach((file) => {
|
|
276
|
-
assets.add(file);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
return assets;
|
|
280
|
-
}
|
|
281
|
-
function collectModulesForEntries(manifest, entries) {
|
|
282
|
-
const mods = /* @__PURE__ */ new Set();
|
|
283
|
-
if (!entries)
|
|
284
|
-
return mods;
|
|
285
|
-
for (const entry of entries)
|
|
286
|
-
collectModules(manifest, entry, mods);
|
|
287
|
-
return mods;
|
|
288
|
-
}
|
|
289
|
-
function collectModules(manifest, entry, mods = /* @__PURE__ */ new Set()) {
|
|
290
|
-
if (!entry)
|
|
291
|
-
return mods;
|
|
292
|
-
mods.add(entry);
|
|
293
|
-
manifest[entry]?.dynamicImports?.forEach((item) => {
|
|
294
|
-
collectModules(manifest, item, mods);
|
|
295
|
-
});
|
|
296
|
-
return mods;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async function renderStaticApp(app) {
|
|
300
|
-
if (!ReactDomServer.renderToPipeableStream) {
|
|
301
|
-
return ReactDomServer.renderToString(/* @__PURE__ */ jsx(Fragment, { children: app }));
|
|
302
|
-
}
|
|
303
|
-
const writableStream = new WritableAsPromise();
|
|
304
|
-
const { pipe } = ReactDomServer.renderToPipeableStream(app, {
|
|
305
|
-
onError(error) {
|
|
306
|
-
writableStream.destroy(error);
|
|
307
|
-
},
|
|
308
|
-
onAllReady() {
|
|
309
|
-
pipe(writableStream);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
return writableStream.getPromise();
|
|
313
|
-
}
|
|
314
|
-
class WritableAsPromise extends Writable {
|
|
315
|
-
_output;
|
|
316
|
-
_deferred;
|
|
317
|
-
constructor() {
|
|
318
|
-
super();
|
|
319
|
-
this._output = "";
|
|
320
|
-
this._deferred = {
|
|
321
|
-
promise: null,
|
|
322
|
-
resolve: () => null,
|
|
323
|
-
reject: () => null
|
|
324
|
-
};
|
|
325
|
-
this._deferred.promise = new Promise((resolve, reject) => {
|
|
326
|
-
this._deferred.resolve = resolve;
|
|
327
|
-
this._deferred.reject = reject;
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
_write(chunk, _enc, next) {
|
|
331
|
-
this._output += chunk.toString();
|
|
332
|
-
next();
|
|
333
|
-
}
|
|
334
|
-
_destroy(error, next) {
|
|
335
|
-
if (error instanceof Error)
|
|
336
|
-
this._deferred.reject(error);
|
|
337
|
-
else
|
|
338
|
-
next();
|
|
339
|
-
}
|
|
340
|
-
end() {
|
|
341
|
-
this._deferred.resolve(this._output);
|
|
342
|
-
return this.destroy();
|
|
343
|
-
}
|
|
344
|
-
getPromise() {
|
|
345
|
-
return this._deferred.promise;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function extractHelmet(context, styleCollector) {
|
|
350
|
-
const { helmet } = context;
|
|
351
|
-
const htmlAttributes = helmet.htmlAttributes.toString();
|
|
352
|
-
const bodyAttributes = helmet.bodyAttributes.toString();
|
|
353
|
-
let titleString = helmet.title.toString();
|
|
354
|
-
if (titleString.split(">")[1] === "</title") {
|
|
355
|
-
titleString = "";
|
|
356
|
-
}
|
|
357
|
-
const metaStrings = [
|
|
358
|
-
titleString,
|
|
359
|
-
helmet.meta.toString(),
|
|
360
|
-
helmet.link.toString(),
|
|
361
|
-
helmet.script.toString()
|
|
362
|
-
];
|
|
363
|
-
const styleTag = styleCollector?.toString?.("") ?? "";
|
|
364
|
-
const metaAttributes = metaStrings.filter(Boolean);
|
|
365
|
-
return { htmlAttributes, bodyAttributes, metaAttributes, styleTag };
|
|
366
|
-
}
|
|
367
|
-
|
|
368
228
|
function invariant(value, message) {
|
|
369
229
|
if (value === false || value === null || typeof value === "undefined") {
|
|
370
230
|
console.error(
|
|
@@ -417,7 +277,7 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
417
277
|
}
|
|
418
278
|
}
|
|
419
279
|
function json(data, init) {
|
|
420
|
-
if (init ===
|
|
280
|
+
if (init === undefined) {
|
|
421
281
|
init = {};
|
|
422
282
|
}
|
|
423
283
|
const responseInit = typeof init === "number" ? {
|
|
@@ -447,6 +307,146 @@ function stripDataParam(request) {
|
|
|
447
307
|
return new Request(url.href, init);
|
|
448
308
|
}
|
|
449
309
|
|
|
310
|
+
async function renderStaticApp(app) {
|
|
311
|
+
if (!ReactDomServer.renderToPipeableStream) {
|
|
312
|
+
return ReactDomServer.renderToString(/* @__PURE__ */ jsx(Fragment, { children: app }));
|
|
313
|
+
}
|
|
314
|
+
const writableStream = new WritableAsPromise();
|
|
315
|
+
const { pipe } = ReactDomServer.renderToPipeableStream(app, {
|
|
316
|
+
onError(error) {
|
|
317
|
+
writableStream.destroy(error);
|
|
318
|
+
},
|
|
319
|
+
onAllReady() {
|
|
320
|
+
pipe(writableStream);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
return writableStream.getPromise();
|
|
324
|
+
}
|
|
325
|
+
class WritableAsPromise extends Writable {
|
|
326
|
+
_output;
|
|
327
|
+
_deferred;
|
|
328
|
+
constructor() {
|
|
329
|
+
super();
|
|
330
|
+
this._output = "";
|
|
331
|
+
this._deferred = {
|
|
332
|
+
promise: null,
|
|
333
|
+
resolve: () => null,
|
|
334
|
+
reject: () => null
|
|
335
|
+
};
|
|
336
|
+
this._deferred.promise = new Promise((resolve, reject) => {
|
|
337
|
+
this._deferred.resolve = resolve;
|
|
338
|
+
this._deferred.reject = reject;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
_write(chunk, _enc, next) {
|
|
342
|
+
this._output += chunk.toString();
|
|
343
|
+
next();
|
|
344
|
+
}
|
|
345
|
+
_destroy(error, next) {
|
|
346
|
+
if (error instanceof Error)
|
|
347
|
+
this._deferred.reject(error);
|
|
348
|
+
else
|
|
349
|
+
next();
|
|
350
|
+
}
|
|
351
|
+
end() {
|
|
352
|
+
this._deferred.resolve(this._output);
|
|
353
|
+
return this.destroy();
|
|
354
|
+
}
|
|
355
|
+
getPromise() {
|
|
356
|
+
return this._deferred.promise;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const version = "0.8.5";
|
|
361
|
+
|
|
362
|
+
function buildLog(text, count) {
|
|
363
|
+
console.log(`
|
|
364
|
+
${gray("[vite-react-ssg]")} ${yellow(text)}${count ? blue(` (${count})`) : ""}`);
|
|
365
|
+
}
|
|
366
|
+
function getSize(str) {
|
|
367
|
+
return `${(str.length / 1024).toFixed(2)} KiB`;
|
|
368
|
+
}
|
|
369
|
+
async function routesToPaths(routes) {
|
|
370
|
+
if (!routes || routes.length === 0)
|
|
371
|
+
return { paths: ["/"] };
|
|
372
|
+
const paths = /* @__PURE__ */ new Set();
|
|
373
|
+
const getPaths = async (routes2, prefix = "") => {
|
|
374
|
+
prefix = prefix.replace(/\/$/g, "");
|
|
375
|
+
for (let route of routes2) {
|
|
376
|
+
if (route.lazy) {
|
|
377
|
+
const lazyData = await route.lazy();
|
|
378
|
+
if (lazyData) {
|
|
379
|
+
route = {
|
|
380
|
+
...route,
|
|
381
|
+
...lazyData
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
let path = route.path;
|
|
386
|
+
path = handlePath(path, prefix);
|
|
387
|
+
if (route.getStaticPaths && isDynamicSegmentsRoute(path)) {
|
|
388
|
+
const staticPaths = await route.getStaticPaths();
|
|
389
|
+
for (let staticPath of staticPaths) {
|
|
390
|
+
staticPath = handlePath(staticPath, prefix);
|
|
391
|
+
if (Array.isArray(route.children))
|
|
392
|
+
await getPaths(route.children, staticPath);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (route.index && !path) {
|
|
396
|
+
paths.add("/");
|
|
397
|
+
}
|
|
398
|
+
if (Array.isArray(route.children))
|
|
399
|
+
await getPaths(route.children, path);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
await getPaths(routes);
|
|
403
|
+
return { paths: Array.from(paths) };
|
|
404
|
+
function handlePath(path, prefix) {
|
|
405
|
+
if (path != null) {
|
|
406
|
+
path = prefix && !path.startsWith("/") ? `${prefix}${path ? `/${path}` : ""}` : path;
|
|
407
|
+
paths.add(path);
|
|
408
|
+
}
|
|
409
|
+
return path;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async function resolveAlias(config, entry) {
|
|
413
|
+
const resolver = config.createResolver();
|
|
414
|
+
const result = await resolver(entry, config.root);
|
|
415
|
+
return result || join(config.root, entry);
|
|
416
|
+
}
|
|
417
|
+
function createRequest(path) {
|
|
418
|
+
const url = new URL(path, "http://vite-react-ssg.com");
|
|
419
|
+
url.search = "";
|
|
420
|
+
url.hash = "";
|
|
421
|
+
url.pathname = path;
|
|
422
|
+
return new Request(url.href);
|
|
423
|
+
}
|
|
424
|
+
const dynamicRE = /[:*?]/;
|
|
425
|
+
function isDynamicSegmentsRoute(route) {
|
|
426
|
+
if (!route)
|
|
427
|
+
return false;
|
|
428
|
+
return dynamicRE.test(route);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function extractHelmet(context, styleCollector) {
|
|
432
|
+
const { helmet } = context;
|
|
433
|
+
const htmlAttributes = helmet.htmlAttributes.toString();
|
|
434
|
+
const bodyAttributes = helmet.bodyAttributes.toString();
|
|
435
|
+
let titleString = helmet.title.toString();
|
|
436
|
+
if (titleString.split(">")[1] === "</title") {
|
|
437
|
+
titleString = "";
|
|
438
|
+
}
|
|
439
|
+
const metaStrings = [
|
|
440
|
+
titleString,
|
|
441
|
+
helmet.meta.toString(),
|
|
442
|
+
helmet.link.toString(),
|
|
443
|
+
helmet.script.toString()
|
|
444
|
+
];
|
|
445
|
+
const styleTag = styleCollector?.toString?.("") ?? "";
|
|
446
|
+
const metaAttributes = metaStrings.filter(Boolean);
|
|
447
|
+
return { htmlAttributes, bodyAttributes, metaAttributes, styleTag };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
450
|
class RemixAdapter {
|
|
451
451
|
context;
|
|
452
452
|
constructor(context) {
|
|
@@ -528,7 +528,7 @@ async function callRouteLoader({
|
|
|
528
528
|
request: stripDataParam(stripIndexParam(request)),
|
|
529
529
|
params
|
|
530
530
|
});
|
|
531
|
-
if (result ===
|
|
531
|
+
if (result === undefined) {
|
|
532
532
|
throw new Error(
|
|
533
533
|
`You defined a loader for route "${routeId}" but didn't return anything from your \`loader\` function. Please return a value or \`null\`.`
|
|
534
534
|
);
|
|
@@ -710,7 +710,8 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
710
710
|
const {
|
|
711
711
|
script = "sync",
|
|
712
712
|
mock = false,
|
|
713
|
-
|
|
713
|
+
htmlEntry = "index.html",
|
|
714
|
+
entry = await detectEntry(root, htmlEntry),
|
|
714
715
|
formatting = "none",
|
|
715
716
|
includedRoutes: configIncludedRoutes = DefaultIncludedRoutes,
|
|
716
717
|
onBeforePageRender,
|
|
@@ -739,7 +740,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
739
740
|
ssrManifest: true,
|
|
740
741
|
rollupOptions: {
|
|
741
742
|
input: {
|
|
742
|
-
app: join(root, "./index.html")
|
|
743
|
+
app: join(root, htmlEntry || "./index.html")
|
|
743
744
|
},
|
|
744
745
|
// @ts-expect-error rollup type
|
|
745
746
|
onLog(level, log, handler) {
|
|
@@ -788,7 +789,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
788
789
|
}));
|
|
789
790
|
const prefix = format === "esm" && process.platform === "win32" ? "file://" : "";
|
|
790
791
|
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
791
|
-
const serverEntry = join(
|
|
792
|
+
const serverEntry = prefix + join(ssgOut, parse(ssrEntry).name + ext).replace(/\\/g, "/");
|
|
792
793
|
const serverManifest = JSON.parse(await fs.readFile(join(ssgOut, ...dotVitedir, "manifest.json"), "utf-8"));
|
|
793
794
|
const _require = createRequire(import.meta.url);
|
|
794
795
|
const { createRoot, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
|
|
@@ -799,12 +800,13 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
799
800
|
routesPaths = DefaultIncludedRoutes(routesPaths);
|
|
800
801
|
routesPaths = Array.from(new Set(routesPaths));
|
|
801
802
|
buildLog("Rendering Pages...", routesPaths.length);
|
|
802
|
-
const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, { publicPath: configBase, ...beastiesOptions }) :
|
|
803
|
+
const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, { publicPath: configBase, ...beastiesOptions }) : undefined;
|
|
803
804
|
if (beasties)
|
|
804
805
|
console.log(`${gray("[vite-react-ssg]")} ${blue("Critical CSS generation enabled via `beasties`")}`);
|
|
805
806
|
const ssrManifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, "ssr-manifest.json"), "utf-8"));
|
|
806
807
|
const manifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, "manifest.json"), "utf-8"));
|
|
807
|
-
let indexHTML = await fs.readFile(join(out,
|
|
808
|
+
let indexHTML = await fs.readFile(join(out, htmlEntry), "utf-8");
|
|
809
|
+
fs.rmSync(join(out, htmlEntry));
|
|
808
810
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
809
811
|
const queue = new PQueue({ concurrency });
|
|
810
812
|
const crittersQueue = new PQueue({ concurrency: 1 });
|
|
@@ -916,13 +918,14 @@ function ssrServerPlugin({
|
|
|
916
918
|
const appCtx = await createRoot(false, url);
|
|
917
919
|
const adapter = getAdapter(appCtx);
|
|
918
920
|
const { app, base } = appCtx;
|
|
919
|
-
const
|
|
921
|
+
const [pathname, search] = url.split("?");
|
|
922
|
+
const searchParams = new URLSearchParams(search);
|
|
920
923
|
if (!app && searchParams.has("_data")) {
|
|
921
924
|
return adapter.handleLoader(req, res);
|
|
922
925
|
}
|
|
923
926
|
const indexHTML = await server.transformIndexHtml(url, template);
|
|
924
927
|
const transformedIndexHTML = await onBeforePageRender?.(url, indexHTML, appCtx) || indexHTML;
|
|
925
|
-
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await adapter.render(stripBase(
|
|
928
|
+
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await adapter.render(stripBase(pathname, base));
|
|
926
929
|
metaAttributes.push(styleTag);
|
|
927
930
|
const mods = await Promise.all(
|
|
928
931
|
[ssrEntry, entry].map(async (entry2) => await server.moduleGraph.getModuleByUrl(entry2))
|
|
@@ -982,14 +985,15 @@ async function dev(ssgOptions = {}, viteConfig = {}, customOptions) {
|
|
|
982
985
|
const cwd = process.cwd();
|
|
983
986
|
const root = config.root || cwd;
|
|
984
987
|
const {
|
|
985
|
-
|
|
988
|
+
htmlEntry = "index.html",
|
|
989
|
+
entry = await detectEntry(root, htmlEntry),
|
|
986
990
|
onBeforePageRender,
|
|
987
991
|
onPageRendered,
|
|
988
992
|
rootContainerId = "root",
|
|
989
993
|
mock = false
|
|
990
994
|
} = Object.assign({}, config.ssgOptions || {}, ssgOptions);
|
|
991
995
|
const ssrEntry = await resolveAlias(config, entry);
|
|
992
|
-
const template = await fs.readFile(join(root,
|
|
996
|
+
const template = await fs.readFile(join(root, htmlEntry), "utf-8");
|
|
993
997
|
let viteServer;
|
|
994
998
|
globalThis.__ssr_start_time = performance.now();
|
|
995
999
|
createServer$1().catch((err) => {
|
package/dist/tanstack.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnyRouter } from '@tanstack/react-router';
|
|
2
|
-
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.
|
|
3
|
-
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.
|
|
4
|
-
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.D2OE2Bw1.mjs';
|
|
3
|
+
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.D2OE2Bw1.mjs';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.mjs';
|
|
5
|
+
import 'beasties';
|
|
5
6
|
import 'react';
|
|
6
7
|
import 'react-router-dom';
|
|
7
|
-
import 'beasties';
|
|
8
8
|
import 'react-helmet-async';
|
|
9
9
|
|
|
10
10
|
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
@@ -24,6 +24,7 @@ declare global {
|
|
|
24
24
|
interface Window {
|
|
25
25
|
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
26
26
|
__VITE_REACT_SSG_HASH__: string;
|
|
27
|
+
__VITE_REACT_SSG_CONTEXT__: ViteReactSSGContext<true>;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
package/dist/tanstack.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnyRouter } from '@tanstack/react-router';
|
|
2
|
-
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.
|
|
3
|
-
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.
|
|
4
|
-
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.
|
|
2
|
+
import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.D2OE2Bw1.js';
|
|
3
|
+
export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterFutureConfig, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.D2OE2Bw1.js';
|
|
4
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.js';
|
|
5
|
+
import 'beasties';
|
|
5
6
|
import 'react';
|
|
6
7
|
import 'react-router-dom';
|
|
7
|
-
import 'beasties';
|
|
8
8
|
import 'react-helmet-async';
|
|
9
9
|
|
|
10
10
|
declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
|
|
@@ -24,6 +24,7 @@ declare global {
|
|
|
24
24
|
interface Window {
|
|
25
25
|
__VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
|
|
26
26
|
__VITE_REACT_SSG_HASH__: string;
|
|
27
|
+
__VITE_REACT_SSG_CONTEXT__: ViteReactSSGContext<true>;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
package/dist/tanstack.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { HelmetProvider } from 'react-helmet-async';
|
|
3
2
|
import { RouterProvider } from '@tanstack/react-router';
|
|
4
3
|
import { Meta, StartClient } from '@tanstack/start';
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { HelmetProvider } from 'react-helmet-async';
|
|
5
|
+
import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.Dx4ca9OM.mjs';
|
|
6
|
+
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Dx4ca9OM.mjs';
|
|
7
|
+
import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
|
|
7
8
|
import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
|
|
8
9
|
import { M as META_CONTAINER_ID, c as convertRouteTreeToRouteOption } from './shared/vite-react-ssg.B-j07kW6.mjs';
|
|
9
10
|
export { r as registerPaths } from './shared/vite-react-ssg.B-j07kW6.mjs';
|
|
10
|
-
import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
|
|
11
11
|
import 'react';
|
|
12
12
|
import 'react-dom';
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
19
19
|
ssrWhenDev,
|
|
20
20
|
getStyleCollector = null
|
|
21
21
|
} = options;
|
|
22
|
-
if (process.env.NODE_ENV === "development" && ssrWhenDev !==
|
|
22
|
+
if (process.env.NODE_ENV === "development" && ssrWhenDev !== undefined)
|
|
23
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
24
|
const isClient = typeof window !== "undefined";
|
|
25
25
|
const BASE_URL = routerOptions.basename ?? "/";
|
|
@@ -71,7 +71,7 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
71
71
|
const routeData = staticLoadData?.[pathname]?.find((item) => item.id === node.id);
|
|
72
72
|
return routeData?.loaderData ?? null;
|
|
73
73
|
};
|
|
74
|
-
} :
|
|
74
|
+
} : undefined
|
|
75
75
|
);
|
|
76
76
|
const router = routerOptions.router;
|
|
77
77
|
router.options.isServer = !client;
|
|
@@ -118,7 +118,9 @@ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
118
118
|
console.warn("[vite-react-ssg] Root container not found.");
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
const
|
|
121
|
+
const context = await createRoot(true);
|
|
122
|
+
window.__VITE_REACT_SSG_CONTEXT__ = context;
|
|
123
|
+
const { router } = context;
|
|
122
124
|
const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
|
|
123
125
|
if (!isSSR && process.env.NODE_ENV === "development") {
|
|
124
126
|
render(
|