vite-react-ssg 0.8.3 → 0.8.5-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.
Files changed (43) hide show
  1. package/README.md +37 -8
  2. package/dist/client/single-page.d.mts +4 -4
  3. package/dist/client/single-page.d.ts +4 -4
  4. package/dist/client/single-page.mjs +7 -6
  5. package/dist/index.d.mts +11 -4
  6. package/dist/index.d.ts +11 -4
  7. package/dist/index.mjs +11 -9
  8. package/dist/node/cli.mjs +9 -9
  9. package/dist/node.d.mts +2 -2
  10. package/dist/node.d.ts +2 -2
  11. package/dist/node.mjs +7 -7
  12. package/dist/shared/{vite-react-ssg.Cm9gBlfg.d.ts → vite-react-ssg.-NlgsPvg.d.mts} +8 -8
  13. package/dist/shared/{vite-react-ssg.Cm9gBlfg.d.mts → vite-react-ssg.-NlgsPvg.d.ts} +8 -8
  14. package/dist/shared/{vite-react-ssg.BgawrvuJ.mjs → vite-react-ssg.2P3UhU88.mjs} +216 -212
  15. package/dist/shared/{vite-react-ssg.C0y5wbxl.mjs → vite-react-ssg.C_MPXL9p.mjs} +1 -1
  16. package/dist/shared/{vite-react-ssg.CfJcpdWF.mjs → vite-react-ssg.Dx4ca9OM.mjs} +18 -4
  17. package/dist/tanstack.d.mts +5 -4
  18. package/dist/tanstack.d.ts +5 -4
  19. package/dist/tanstack.mjs +9 -7
  20. package/package.json +32 -33
  21. package/dist/chunks/jsdomGlobal.cjs +0 -36
  22. package/dist/client/single-page.cjs +0 -75
  23. package/dist/client/single-page.d.cts +0 -11
  24. package/dist/index.cjs +0 -196
  25. package/dist/index.d.cts +0 -20
  26. package/dist/node/cli.cjs +0 -89
  27. package/dist/node/cli.d.cts +0 -2
  28. package/dist/node.cjs +0 -24
  29. package/dist/node.d.cts +0 -11
  30. package/dist/shared/vite-react-ssg.B4jDfvXh.cjs +0 -106
  31. package/dist/shared/vite-react-ssg.C2GpVZF1.cjs +0 -38
  32. package/dist/shared/vite-react-ssg.CFQGqC60.cjs +0 -36
  33. package/dist/shared/vite-react-ssg.CjsEygxB.cjs +0 -37
  34. package/dist/shared/vite-react-ssg.Cm9gBlfg.d.cts +0 -15
  35. package/dist/shared/vite-react-ssg.D5xBH08M.cjs +0 -1079
  36. package/dist/shared/vite-react-ssg.DWHmkjdM.cjs +0 -35
  37. package/dist/shared/vite-react-ssg.Di0pROyF.d.ts +0 -214
  38. package/dist/style-collectors/styled-components.cjs +0 -20
  39. package/dist/style-collectors/styled-components.d.cts +0 -9
  40. package/dist/tanstack.cjs +0 -144
  41. package/dist/tanstack.d.cts +0 -30
  42. package/dist/shared/{vite-react-ssg.Di0pROyF.d.cts → vite-react-ssg.BrImbdZU.d.mts} +1 -1
  43. package/dist/shared/{vite-react-ssg.Di0pROyF.d.mts → vite-react-ssg.BrImbdZU.d.ts} +1 -1
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- const ViteReactSSGTanstackRouterStaticPathsContext = {};
4
- function registerPaths(id, getStaticPaths) {
5
- ViteReactSSGTanstackRouterStaticPathsContext[id] = getStaticPaths;
6
- }
7
- async function convertRouteTreeToRouteOption(routeTree, client, visitNode) {
8
- const routes = [];
9
- async function traverseRouteTree(node) {
10
- if (!client && node.path?.includes("$") && node.lazyFn) {
11
- await node.lazyFn();
12
- }
13
- visitNode?.(node);
14
- const routeRecord = {
15
- path: node.path,
16
- getStaticPaths: ViteReactSSGTanstackRouterStaticPathsContext[node.id]
17
- };
18
- routeRecord.path = routeRecord.path?.replaceAll("$", ":");
19
- const children = node.children;
20
- if (children) {
21
- routeRecord.children = [];
22
- for (const child of Object.values(children)) {
23
- routeRecord.children.push(await traverseRouteTree(child));
24
- }
25
- }
26
- return routeRecord;
27
- }
28
- routes.push(await traverseRouteTree(routeTree));
29
- return routes;
30
- }
31
- const META_CONTAINER_ID = "__SSG_TANSTACK_META_CONTAINER__";
32
-
33
- exports.META_CONTAINER_ID = META_CONTAINER_ID;
34
- exports.convertRouteTreeToRouteOption = convertRouteTreeToRouteOption;
35
- exports.registerPaths = registerPaths;
@@ -1,214 +0,0 @@
1
- import { ReactNode, ReactElement } from 'react';
2
- import { NonIndexRouteObject, IndexRouteObject, FutureConfig, createBrowserRouter } from 'react-router-dom';
3
- import { Options } from 'beasties';
4
-
5
- type Router = ReturnType<typeof createBrowserRouter>;
6
- interface CrittersOptions {
7
- path?: string;
8
- publicPath?: string;
9
- external?: boolean;
10
- inlineThreshold?: number;
11
- minimumExternalSize?: number;
12
- pruneSource?: boolean;
13
- mergeStylesheets?: boolean;
14
- additionalStylesheets?: string[];
15
- preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
16
- noscriptFallback?: boolean;
17
- inlineFonts?: boolean;
18
- preloadFonts?: boolean;
19
- fonts?: boolean;
20
- keyframes?: string;
21
- compress?: boolean;
22
- logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
23
- reduceInlineStyles?: boolean;
24
- }
25
- interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
26
- /**
27
- * Set the scripts' loading mode. Only works for `type="module"`.
28
- *
29
- * @default 'sync'
30
- */
31
- script?: 'sync' | 'async' | 'defer' | 'async defer';
32
- /**
33
- * Build format.
34
- *
35
- * @default 'esm'
36
- */
37
- format?: 'esm' | 'cjs';
38
- /**
39
- * The path of the main entry file (relative to the project root).
40
- *
41
- * @default 'src/main.ts'
42
- */
43
- entry?: string;
44
- /**
45
- * Mock browser global variables (window, document, etc...) from SSG.
46
- *
47
- * @default false
48
- */
49
- mock?: boolean;
50
- /**
51
- * Apply formatter to the generated index file.
52
- *
53
- * **It will cause Hydration Failed.**
54
- *
55
- * @default 'none'
56
- */
57
- formatting?: 'prettify' | 'none';
58
- /**
59
- * Vite environmeng mode.
60
- */
61
- mode?: string;
62
- /**
63
- * Directory style of the output directory.
64
- *
65
- * flat: `/foo` -> `/foo.html`
66
- * nested: `/foo` -> `/foo/index.html`
67
- *
68
- * @default 'flat'
69
- */
70
- dirStyle?: 'flat' | 'nested';
71
- /**
72
- * Generate for all routes, including dynamic routes.
73
- * If enabled, you will need to configGure your serve
74
- * manually to handle dynamic routes properly.
75
- *
76
- * @default false
77
- */
78
- includeAllRoutes?: boolean;
79
- /**
80
- * Options for the critters packages.
81
- *
82
- * @deprecated Use `beastiesOptions` instead.
83
- * @see https://github.com/GoogleChromeLabs/critters
84
- */
85
- crittersOptions?: CrittersOptions | false;
86
- /**
87
- * Options for the beasties package.
88
- *
89
- * @see https://github.com/danielroe/beasties
90
- */
91
- beastiesOptions?: Options | false;
92
- /**
93
- * Custom function to modify the routes to do the SSG.
94
- *
95
- * Works only when `includeAllRoutes` is set to false.
96
- *
97
- * Defaults to a handler that filters out all the dynamic routes.
98
- * When passing your custom handler, you should also take care of the dynamic routes yourself.
99
- */
100
- includedRoutes?: (paths: string[], routes: Readonly<RouteRecord[]>) => Promise<string[]> | string[];
101
- /**
102
- * Callback to be called before every page render.
103
- *
104
- * It can be used to transform the project's `index.html` file before passing it to the renderer.
105
- *
106
- * To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
107
- * The returned value will then be passed to renderer.
108
- */
109
- onBeforePageRender?: (route: string, indexHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
110
- /**
111
- * Callback to be called on every rendered page.
112
- *
113
- * It can be used to transform the current route's rendered HTML.
114
- *
115
- * To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
116
- * The returned value will be used as the HTML of the route.
117
- */
118
- onPageRendered?: (route: string, renderedHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
119
- onFinished?: () => Promise<void> | void;
120
- /**
121
- * The application's root container `id`.
122
- *
123
- * @default `root`
124
- */
125
- rootContainerId?: string;
126
- /**
127
- * The size of the SSG processing queue.
128
- *
129
- * @default 20
130
- */
131
- concurrency?: number;
132
- }
133
- interface ViteReactSSGContext<HasRouter extends boolean = true> {
134
- router?: HasRouter extends true ? Router : undefined;
135
- routes: HasRouter extends true ? Readonly<RouteRecord[]> : undefined;
136
- routerOptions: HasRouter extends true ? RouterOptions : undefined;
137
- initialState: Record<string, any>;
138
- isClient: boolean;
139
- onSSRAppRendered: (cb: Function) => void;
140
- triggerOnSSRAppRendered: (route: string, appHTML: string, appCtx: ViteReactSSGContext) => Promise<unknown[]>;
141
- transformState?: (state: any) => any;
142
- /**
143
- * Current router path on SSG, `undefined` on client side.
144
- */
145
- routePath?: string;
146
- base: string;
147
- getStyleCollector: (() => StyleCollector | Promise<StyleCollector>) | null;
148
- app?: HasRouter extends true ? never : ReactNode;
149
- routerType: 'remix' | 'single-page';
150
- }
151
- interface ViteReactSSGClientOptions {
152
- transformState?: (state: any) => any;
153
- registerComponents?: boolean;
154
- /**
155
- * The application's root container query selector.
156
- *
157
- * @default `#root`
158
- */
159
- rootContainer?: string | Element;
160
- /**
161
- * @deprecated This option is no longer needed
162
- */
163
- ssrWhenDev?: boolean;
164
- getStyleCollector?: (() => StyleCollector | Promise<StyleCollector>) | null;
165
- useLegacyRender?: boolean;
166
- }
167
- interface CommonRouteOptions {
168
- /**
169
- * Used to obtain static resources through manifest
170
- *
171
- * **You are not required to use this field. It is only necessary when "prehydration style loss" occurs.**
172
- *
173
- * @example `src/pages/home.tsx`
174
- */
175
- entry?: string;
176
- /**
177
- * The getStaticPaths() function should return an array of path
178
- * to determine which paths will be pre-rendered by vite-react-ssg.
179
- *
180
- * This function is only valid for dynamic route.
181
- *
182
- * @example () => ['path1', 'path2']
183
- */
184
- getStaticPaths?: () => string[] | Promise<string[]>;
185
- }
186
- type NonIndexRouteRecord = Omit<NonIndexRouteObject, 'children'> & {
187
- children?: RouteRecord[];
188
- } & CommonRouteOptions;
189
- type IndexRouteRecord = IndexRouteObject & CommonRouteOptions;
190
- type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
191
- interface RouterFutureConfig {
192
- v7_fetcherPersist?: boolean;
193
- v7_normalizeFormMethod?: boolean;
194
- v7_partialHydration?: boolean;
195
- v7_relativeSplatPath?: boolean;
196
- v7_skipActionErrorRevalidation?: boolean;
197
- }
198
- interface RouterOptions {
199
- routes: RouteRecord[];
200
- basename?: string;
201
- future?: Partial<RouterFutureConfig & FutureConfig>;
202
- }
203
- interface StyleCollector {
204
- collect: (app: ReactElement) => ReactElement;
205
- toString: (html: string) => string;
206
- cleanup?: () => void;
207
- }
208
- declare module 'vite' {
209
- interface UserConfig {
210
- ssgOptions?: ViteReactSSGOptions;
211
- }
212
- }
213
-
214
- export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterFutureConfig as c, RouterOptions as d };
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- const styledComponents = require('styled-components');
4
-
5
- async function ssrCollector() {
6
- const sheet = new styledComponents.ServerStyleSheet();
7
- return {
8
- collect(app) {
9
- return sheet.collectStyles(app);
10
- },
11
- toString() {
12
- return sheet.getStyleTags();
13
- },
14
- cleanup() {
15
- sheet.seal();
16
- }
17
- };
18
- }
19
-
20
- module.exports = ssrCollector;
@@ -1,9 +0,0 @@
1
- import { ReactElement } from 'react';
2
-
3
- declare function ssrCollector(): Promise<{
4
- collect(app: ReactElement): JSX.Element;
5
- toString(): string;
6
- cleanup(): void;
7
- }>;
8
-
9
- export { ssrCollector as default };
package/dist/tanstack.cjs DELETED
@@ -1,144 +0,0 @@
1
- 'use strict';
2
-
3
- const jsxRuntime = require('react/jsx-runtime');
4
- const reactHelmetAsync = require('react-helmet-async');
5
- const reactRouter = require('@tanstack/react-router');
6
- const start = require('@tanstack/start');
7
- const ClientOnly = require('./shared/vite-react-ssg.B4jDfvXh.cjs');
8
- const state = require('./shared/vite-react-ssg.CjsEygxB.cjs');
9
- const tanstackRouter = require('./shared/vite-react-ssg.DWHmkjdM.cjs');
10
- const path = require('./shared/vite-react-ssg.CFQGqC60.cjs');
11
- require('react');
12
- require('react-dom');
13
-
14
- const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
15
- function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
16
- const {
17
- transformState,
18
- rootContainer = "#root",
19
- ssrWhenDev,
20
- getStyleCollector = null
21
- } = options;
22
- if (process.env.NODE_ENV === "development" && 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__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
30
- /* @__PURE__ */ jsxRuntime.jsx(OriginComponent, {}),
31
- /* @__PURE__ */ jsxRuntime.jsx("div", { id: tanstackRouter.META_CONTAINER_ID, style: { display: "none" }, children: /* @__PURE__ */ jsxRuntime.jsx(start.Meta, {}) })
32
- ] });
33
- component[HAS_ADD_META_FLAG_KEY] = true;
34
- routeTree.update({
35
- component
36
- });
37
- }
38
- async function createRoot(client = false, routePath) {
39
- const routes = await tanstackRouter.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 (process.env.NODE_ENV === "development") {
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 = path.joinUrlSegments(BASE_URL, `static-loader-data-manifest-${window.__VITE_REACT_SSG_HASH__}.json`);
65
- staticLoadData = await (await fetch(path.withLeadingSlash(manifestUrl))).json();
66
- window.__VITE_REACT_SSG_STATIC_LOADER_DATA__ = staticLoadData;
67
- }
68
- if (BASE_URL !== "/") {
69
- pathname = path.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 ClientOnly.documentReady();
104
- context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || 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(true);
122
- const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
123
- if (!isSSR && process.env.NODE_ENV === "development") {
124
- ClientOnly.render(
125
- /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouter.RouterProvider, { router }) }),
126
- container,
127
- options
128
- );
129
- } else {
130
- ClientOnly.hydrate(
131
- /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(start.StartClient, { router }) }),
132
- container,
133
- options
134
- );
135
- }
136
- })();
137
- }
138
- return createRoot;
139
- }
140
-
141
- exports.ClientOnly = ClientOnly.ClientOnly;
142
- exports.Head = ClientOnly.Head;
143
- exports.registerPaths = tanstackRouter.registerPaths;
144
- exports.Experimental_ViteReactSSG = Experimental_ViteReactSSG;
@@ -1,30 +0,0 @@
1
- import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Di0pROyF.cjs';
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.Di0pROyF.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 'beasties';
8
- import 'react-helmet-async';
9
-
10
- declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
11
-
12
- interface RouterOptions {
13
- router: AnyRouter;
14
- routes: AnyRouter['routeTree'];
15
- basename?: string;
16
- }
17
- type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGContext$1, 'router' | 'routerType'> & {
18
- router: HasRouter extends true ? AnyRouter : undefined;
19
- routeTree?: AnyRouter['routeTree'];
20
- routerType: 'tanstack';
21
- };
22
- declare function Experimental_ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
23
- declare global {
24
- interface Window {
25
- __VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
26
- __VITE_REACT_SSG_HASH__: string;
27
- }
28
- }
29
-
30
- export { Experimental_ViteReactSSG, type RouterOptions, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
@@ -1,6 +1,6 @@
1
+ import { Options } from 'beasties';
1
2
  import { ReactNode, ReactElement } from 'react';
2
3
  import { NonIndexRouteObject, IndexRouteObject, FutureConfig, createBrowserRouter } from 'react-router-dom';
3
- import { Options } from 'beasties';
4
4
 
5
5
  type Router = ReturnType<typeof createBrowserRouter>;
6
6
  interface CrittersOptions {
@@ -1,6 +1,6 @@
1
+ import { Options } from 'beasties';
1
2
  import { ReactNode, ReactElement } from 'react';
2
3
  import { NonIndexRouteObject, IndexRouteObject, FutureConfig, createBrowserRouter } from 'react-router-dom';
3
- import { Options } from 'beasties';
4
4
 
5
5
  type Router = ReturnType<typeof createBrowserRouter>;
6
6
  interface CrittersOptions {