vite-react-ssg 0.3.0 → 0.3.2
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 +2 -0
- package/dist/index.cjs +11 -11
- package/dist/index.mjs +11 -11
- package/dist/node/cli.cjs +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +1 -1
- package/dist/shared/{vite-react-ssg.677d2862.cjs → vite-react-ssg.9cf631b2.cjs} +6 -5
- package/dist/shared/{vite-react-ssg.eb444549.mjs → vite-react-ssg.f12aa7be.mjs} +4 -3
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Static-site generation for React on Vite.
|
|
4
4
|
|
|
5
|
+
See demo(also document): [docs](https://vite-react-ssg.netlify.app/)
|
|
6
|
+
|
|
5
7
|
[](https://www.npmjs.com/package/vite-react-ssg)
|
|
6
8
|
|
|
7
9
|
# Table of contents
|
package/dist/index.cjs
CHANGED
|
@@ -149,6 +149,17 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
149
149
|
if (isClient) {
|
|
150
150
|
(async () => {
|
|
151
151
|
const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;
|
|
152
|
+
const lazeMatches = reactRouterDom.matchRoutes(routerOptions.routes, window.location)?.filter(
|
|
153
|
+
(m) => m.route.lazy
|
|
154
|
+
);
|
|
155
|
+
if (lazeMatches && lazeMatches?.length > 0) {
|
|
156
|
+
await Promise.all(
|
|
157
|
+
lazeMatches.map(async (m) => {
|
|
158
|
+
const routeModule = await m.route.lazy();
|
|
159
|
+
Object.assign(m.route, { ...routeModule, lazy: void 0 });
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
}
|
|
152
163
|
const { router } = await createRoot(true);
|
|
153
164
|
const app = /* @__PURE__ */ React__default.createElement(reactHelmetAsync.HelmetProvider, null, /* @__PURE__ */ React__default.createElement(SiteMetadataDefaults.SiteMetadataDefaults, null), /* @__PURE__ */ React__default.createElement(reactRouterDom.RouterProvider, { router }));
|
|
154
165
|
if (!ssrWhenDev && undefined.DEV) {
|
|
@@ -157,17 +168,6 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
157
168
|
root.render(app);
|
|
158
169
|
});
|
|
159
170
|
} else {
|
|
160
|
-
const lazeMatches = reactRouterDom.matchRoutes(routerOptions.routes, window.location)?.filter(
|
|
161
|
-
(m) => m.route.lazy
|
|
162
|
-
);
|
|
163
|
-
if (lazeMatches && lazeMatches?.length > 0) {
|
|
164
|
-
await Promise.all(
|
|
165
|
-
lazeMatches.map(async (m) => {
|
|
166
|
-
const routeModule = await m.route.lazy();
|
|
167
|
-
Object.assign(m.route, { ...routeModule, lazy: void 0 });
|
|
168
|
-
})
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
171
|
React__default.startTransition(() => {
|
|
172
172
|
client.hydrateRoot(container, app);
|
|
173
173
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -144,6 +144,17 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
144
144
|
if (isClient) {
|
|
145
145
|
(async () => {
|
|
146
146
|
const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;
|
|
147
|
+
const lazeMatches = matchRoutes(routerOptions.routes, window.location)?.filter(
|
|
148
|
+
(m) => m.route.lazy
|
|
149
|
+
);
|
|
150
|
+
if (lazeMatches && lazeMatches?.length > 0) {
|
|
151
|
+
await Promise.all(
|
|
152
|
+
lazeMatches.map(async (m) => {
|
|
153
|
+
const routeModule = await m.route.lazy();
|
|
154
|
+
Object.assign(m.route, { ...routeModule, lazy: void 0 });
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
}
|
|
147
158
|
const { router } = await createRoot$1(true);
|
|
148
159
|
const app = /* @__PURE__ */ React.createElement(HelmetProvider, null, /* @__PURE__ */ React.createElement(SiteMetadataDefaults, null), /* @__PURE__ */ React.createElement(RouterProvider, { router }));
|
|
149
160
|
if (!ssrWhenDev && import.meta.env.DEV) {
|
|
@@ -152,17 +163,6 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
152
163
|
root.render(app);
|
|
153
164
|
});
|
|
154
165
|
} else {
|
|
155
|
-
const lazeMatches = matchRoutes(routerOptions.routes, window.location)?.filter(
|
|
156
|
-
(m) => m.route.lazy
|
|
157
|
-
);
|
|
158
|
-
if (lazeMatches && lazeMatches?.length > 0) {
|
|
159
|
-
await Promise.all(
|
|
160
|
-
lazeMatches.map(async (m) => {
|
|
161
|
-
const routeModule = await m.route.lazy();
|
|
162
|
-
Object.assign(m.route, { ...routeModule, lazy: void 0 });
|
|
163
|
-
})
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
166
|
React.startTransition(() => {
|
|
167
167
|
hydrateRoot(container, app);
|
|
168
168
|
});
|
package/dist/node/cli.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const kolorist = require('kolorist');
|
|
|
4
4
|
const yargs = require('yargs');
|
|
5
5
|
const helpers = require('yargs/helpers');
|
|
6
6
|
const webFetch = require('@remix-run/web-fetch');
|
|
7
|
-
const dev = require('../shared/vite-react-ssg.
|
|
7
|
+
const dev = require('../shared/vite-react-ssg.9cf631b2.cjs');
|
|
8
8
|
require('node:path');
|
|
9
9
|
require('node:module');
|
|
10
10
|
require('fs-extra');
|
package/dist/node/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { gray, bold, red, reset, underline } from 'kolorist';
|
|
|
2
2
|
import yargs from 'yargs';
|
|
3
3
|
import { hideBin } from 'yargs/helpers';
|
|
4
4
|
import { Request, Response, fetch as fetch$1, Headers, FormData } from '@remix-run/web-fetch';
|
|
5
|
-
import { b as build, d as dev } from '../shared/vite-react-ssg.
|
|
5
|
+
import { b as build, d as dev } from '../shared/vite-react-ssg.f12aa7be.mjs';
|
|
6
6
|
import 'node:path';
|
|
7
7
|
import 'node:module';
|
|
8
8
|
import 'fs-extra';
|
package/dist/node.cjs
CHANGED
package/dist/node.mjs
CHANGED
|
@@ -950,7 +950,7 @@ async function resolveAlias(config, entry) {
|
|
|
950
950
|
return result || node_path.join(config.root, entry);
|
|
951
951
|
}
|
|
952
952
|
const { version } = JSON.parse(
|
|
953
|
-
node_fs.readFileSync(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared/vite-react-ssg.
|
|
953
|
+
node_fs.readFileSync(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared/vite-react-ssg.9cf631b2.cjs', document.baseURI).href)))).toString()
|
|
954
954
|
);
|
|
955
955
|
function createRequest(path) {
|
|
956
956
|
const url = new URL(path, "http://vite-react-ssg.com");
|
|
@@ -1233,7 +1233,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1233
1233
|
const prefix = format === "esm" && process.platform === "win32" ? "file://" : "";
|
|
1234
1234
|
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
1235
1235
|
const serverEntry = node_path.join(prefix, ssgOut, node_path.parse(ssrEntry).name + ext);
|
|
1236
|
-
const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared/vite-react-ssg.
|
|
1236
|
+
const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared/vite-react-ssg.9cf631b2.cjs', document.baseURI).href)));
|
|
1237
1237
|
const { createRoot, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
|
|
1238
1238
|
const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes;
|
|
1239
1239
|
const { routes } = await createRoot(false);
|
|
@@ -1252,15 +1252,16 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1252
1252
|
let indexHTML = await fs__default.readFile(node_path.join(out, "index.html"), "utf-8");
|
|
1253
1253
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
1254
1254
|
const queue = new PQueue({ concurrency });
|
|
1255
|
+
const crittersQueue = new PQueue({ concurrency: 1 });
|
|
1255
1256
|
for (const path of routesPaths) {
|
|
1256
1257
|
queue.add(async () => {
|
|
1257
1258
|
try {
|
|
1258
1259
|
const appCtx = await createRoot(false, path);
|
|
1259
|
-
const { initialState, triggerOnSSRAppRendered, transformState = SiteMetadataDefaults.serializeState, getStyleCollector } = appCtx;
|
|
1260
|
+
const { initialState, routes: routes2, triggerOnSSRAppRendered, transformState = SiteMetadataDefaults.serializeState, getStyleCollector } = appCtx;
|
|
1260
1261
|
const styleCollector = getStyleCollector ? await getStyleCollector() : null;
|
|
1261
1262
|
const transformedIndexHTML = await onBeforePageRender?.(path, indexHTML, appCtx) || indexHTML;
|
|
1262
1263
|
const request = createRequest(path);
|
|
1263
|
-
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await render(
|
|
1264
|
+
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await render([...routes2], request, styleCollector);
|
|
1264
1265
|
await triggerOnSSRAppRendered?.(path, appHTML, appCtx);
|
|
1265
1266
|
const renderedHTML = await renderHTML({
|
|
1266
1267
|
rootContainerId,
|
|
@@ -1277,7 +1278,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1277
1278
|
const html = jsdom.serialize();
|
|
1278
1279
|
let transformed = await onPageRendered?.(path, html, appCtx) || html;
|
|
1279
1280
|
if (critters)
|
|
1280
|
-
transformed = await critters.process(transformed);
|
|
1281
|
+
transformed = await crittersQueue.add(() => critters.process(transformed));
|
|
1281
1282
|
if (styleTag)
|
|
1282
1283
|
transformed = transformed.replace("<head>", `<head>${styleTag}`);
|
|
1283
1284
|
const formatted = await formatHtml(transformed, formatting);
|
|
@@ -1244,15 +1244,16 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1244
1244
|
let indexHTML = await fs.readFile(join(out, "index.html"), "utf-8");
|
|
1245
1245
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
1246
1246
|
const queue = new PQueue({ concurrency });
|
|
1247
|
+
const crittersQueue = new PQueue({ concurrency: 1 });
|
|
1247
1248
|
for (const path of routesPaths) {
|
|
1248
1249
|
queue.add(async () => {
|
|
1249
1250
|
try {
|
|
1250
1251
|
const appCtx = await createRoot(false, path);
|
|
1251
|
-
const { initialState, triggerOnSSRAppRendered, transformState = serializeState, getStyleCollector } = appCtx;
|
|
1252
|
+
const { initialState, routes: routes2, triggerOnSSRAppRendered, transformState = serializeState, getStyleCollector } = appCtx;
|
|
1252
1253
|
const styleCollector = getStyleCollector ? await getStyleCollector() : null;
|
|
1253
1254
|
const transformedIndexHTML = await onBeforePageRender?.(path, indexHTML, appCtx) || indexHTML;
|
|
1254
1255
|
const request = createRequest(path);
|
|
1255
|
-
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await render(
|
|
1256
|
+
const { appHTML, bodyAttributes, htmlAttributes, metaAttributes, styleTag } = await render([...routes2], request, styleCollector);
|
|
1256
1257
|
await triggerOnSSRAppRendered?.(path, appHTML, appCtx);
|
|
1257
1258
|
const renderedHTML = await renderHTML({
|
|
1258
1259
|
rootContainerId,
|
|
@@ -1269,7 +1270,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1269
1270
|
const html = jsdom.serialize();
|
|
1270
1271
|
let transformed = await onPageRendered?.(path, html, appCtx) || html;
|
|
1271
1272
|
if (critters)
|
|
1272
|
-
transformed = await critters.process(transformed);
|
|
1273
|
+
transformed = await crittersQueue.add(() => critters.process(transformed));
|
|
1273
1274
|
if (styleTag)
|
|
1274
1275
|
transformed = transformed.replace("<head>", `<head>${styleTag}`);
|
|
1275
1276
|
const formatted = await formatHtml(transformed, formatting);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-react-ssg",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"packageManager": "pnpm@8.6.6",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "Riri <Daydreamerriri@outlook.com>",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"build": "unbuild",
|
|
63
63
|
"dev": "unbuild --stub",
|
|
64
64
|
"lint": "eslint .",
|
|
65
|
+
"test": "pnpm -r --filter=./examples/* build && vitest run",
|
|
65
66
|
"prepublishOnly": "nr build",
|
|
66
67
|
"release": "bumpp && npm publish",
|
|
67
68
|
"start": "esno src/index.ts",
|
|
@@ -110,9 +111,10 @@
|
|
|
110
111
|
"@types/react-dom": "^18.2.6",
|
|
111
112
|
"@types/yargs": "^17.0.24",
|
|
112
113
|
"bumpp": "^9.1.0",
|
|
113
|
-
"critters": "^0.0.
|
|
114
|
+
"critters": "^0.0.20",
|
|
114
115
|
"eslint": "^8.45.0",
|
|
115
116
|
"esno": "^0.17.0",
|
|
117
|
+
"fast-glob": "3.3.1",
|
|
116
118
|
"p-queue": "^7.3.4",
|
|
117
119
|
"react": "^18.2.0",
|
|
118
120
|
"react-dom": "^18.2.0",
|
|
@@ -121,8 +123,8 @@
|
|
|
121
123
|
"styled-components": "6.0.5",
|
|
122
124
|
"typescript": "5.1.6",
|
|
123
125
|
"unbuild": "^1.2.1",
|
|
124
|
-
"vite": "^4.4.
|
|
126
|
+
"vite": "^4.4.9",
|
|
125
127
|
"vite-plugin-pwa": "^0.16.4",
|
|
126
|
-
"vitest": "0.
|
|
128
|
+
"vitest": "0.34.1"
|
|
127
129
|
}
|
|
128
130
|
}
|