@bdocs/ssg 0.0.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/LICENSE +21 -0
- package/bin/vite-react-ssg.js +3 -0
- package/dist/chunk-Bmb41Sf3.cjs +1 -0
- package/dist/client/single-page.cjs +2 -0
- package/dist/client/single-page.d.cts +241 -0
- package/dist/client/single-page.d.ts +241 -0
- package/dist/client/single-page.js +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +34 -0
- package/dist/index.d.mts +34 -0
- package/dist/index.mjs +2 -0
- package/dist/jsdomGlobal-DIW81D0t.cjs +1 -0
- package/dist/jsdomGlobal-DuvGNWb6.mjs +1 -0
- package/dist/node.cjs +1 -0
- package/dist/node.d.cts +11 -0
- package/dist/node.d.mts +11 -0
- package/dist/node.mjs +1 -0
- package/dist/state-BLI6QppB.mjs +1 -0
- package/dist/state-OWuAHBHy.cjs +1 -0
- package/dist/style-collectors/styled-components.cjs +1 -0
- package/dist/style-collectors/styled-components.d.cts +9 -0
- package/dist/style-collectors/styled-components.d.mts +10 -0
- package/dist/style-collectors/styled-components.mjs +1 -0
- package/dist/types-D9xYNy8A.d.mts +221 -0
- package/dist/types-DfHnCTVN.d.cts +221 -0
- package/package.json +129 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Boltdocs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return s}});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react-helmet-async`);c=s(c);let l=require(`react/jsx-runtime`),u=require(`react-dom`);u=s(u,1);let d=require(`react`);d=s(d,1);const f={...u},{version:p,render:m,hydrate:h}=f,g=Number((p||``).split(`.`)[0])>17,_=Number((p||``).split(`.`)[0])>18;function v(e,t,n={}){let{useLegacyRender:r}=n;if(r||!g)m(e,t);else if(_)import(`react-dom/client`).then(({default:{createRoot:n}})=>{let r=n(t);d.startTransition(()=>{r.render(e)})});else{f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{createRoot:n}=f;if(!n)throw Error(`createRoot not found`);let r=n(t);f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1,d.startTransition(()=>{r.render(e)})}}function y(e,t,n={}){let{useLegacyRender:r}=n;if(r||!g)h(e,t);else if(_)import(`react-dom/client`).then(({default:{hydrateRoot:n}})=>{d.startTransition(()=>{n(t,e)})});else{f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{hydrateRoot:n}=f;if(!n)throw Error(`hydrateRoot not found`);d.startTransition(()=>{n(t,e),f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1})}}function b(e){return document.readyState===`loading`?new Promise(t=>{document.addEventListener(`DOMContentLoaded`,()=>t(e))}):Promise.resolve(e)}function x(e){try{return JSON.parse(e||`{}`)}catch(t){return console.error(`[SSG] On state deserialization -`,t,e),{}}}function S(){let[e,t]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{t(!0)},[]),e}function C({children:e,fallback:t}){if(S()){if(typeof e!=`function`&&process.env.NODE_ENV===`development`)throw Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
|
|
2
|
+
Current type: ${(0,d.isValidElement)(e)?`React element`:typeof e}`);return(0,l.jsx)(l.Fragment,{children:e?.()})}return t??null}function w(e){return(0,l.jsx)(c.Helmet,{...e})}const{HelmetProvider:T}=c;function E(e,t,n={}){let{transformState:r,rootContainer:i=`#root`,ssrWhenDev:a,getStyleCollector:o=null}=n;process.env.NODE_ENV===`development`&&a!==void 0&&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`.");let s=typeof window<`u`;async function c(n=!1,i){let a=[],c={isClient:s,onSSRAppRendered:n?()=>{}:e=>a.push(e),triggerOnSSRAppRendered:()=>Promise.all(a.map(e=>e())),initialState:{},transformState:r,routePath:i,getStyleCollector:o,routes:void 0,routerOptions:void 0,base:`/`,app:e,routerType:`single-page`};n&&(await b(),c.initialState=r?.(window.__INITIAL_STATE__||{})||x(window.__INITIAL_STATE__)),await t?.(c);let l=c.initialState;return{...c,initialState:l}}return s&&(async()=>{let t=typeof i==`string`?document.querySelector(i):i;if(!t){typeof $jsdom>`u`&&console.warn(`[vite-react-ssg] Root container not found.`);return}let r=await c(!0);window.__VITE_REACT_SSG_CONTEXT__=r;let a=(0,l.jsx)(T,{children:e});document.querySelector(`[data-server-rendered=true]`)===null&&process.env.NODE_ENV===`development`?v(a,t,n):y(a,t,n)})(),c}exports.ClientOnly=C,exports.Head=w,exports.ViteReactSSG=E;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Options } from "beasties";
|
|
3
|
+
import { FutureConfig, IndexRouteObject, NonIndexRouteObject, createBrowserRouter } from "react-router-dom";
|
|
4
|
+
import { HelmetProps } from "react-helmet-async";
|
|
5
|
+
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
type Router = ReturnType<typeof createBrowserRouter>;
|
|
8
|
+
interface CrittersOptions {
|
|
9
|
+
path?: string;
|
|
10
|
+
publicPath?: string;
|
|
11
|
+
external?: boolean;
|
|
12
|
+
inlineThreshold?: number;
|
|
13
|
+
minimumExternalSize?: number;
|
|
14
|
+
pruneSource?: boolean;
|
|
15
|
+
mergeStylesheets?: boolean;
|
|
16
|
+
additionalStylesheets?: string[];
|
|
17
|
+
preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
|
|
18
|
+
noscriptFallback?: boolean;
|
|
19
|
+
inlineFonts?: boolean;
|
|
20
|
+
preloadFonts?: boolean;
|
|
21
|
+
fonts?: boolean;
|
|
22
|
+
keyframes?: string;
|
|
23
|
+
compress?: boolean;
|
|
24
|
+
logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
|
|
25
|
+
reduceInlineStyles?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
|
|
28
|
+
/**
|
|
29
|
+
* Set the scripts' loading mode. Only works for `type="module"`.
|
|
30
|
+
*
|
|
31
|
+
* @default 'sync'
|
|
32
|
+
*/
|
|
33
|
+
script?: 'sync' | 'async' | 'defer' | 'async defer';
|
|
34
|
+
/**
|
|
35
|
+
* Build format.
|
|
36
|
+
*
|
|
37
|
+
* @default 'esm'
|
|
38
|
+
*/
|
|
39
|
+
format?: 'esm' | 'cjs';
|
|
40
|
+
/**
|
|
41
|
+
* The path of the main entry file (relative to the project root).
|
|
42
|
+
*
|
|
43
|
+
* @default 'src/main.ts'
|
|
44
|
+
*/
|
|
45
|
+
entry?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The path of the index.html file (relative to the project root).
|
|
48
|
+
* @default 'index.html'
|
|
49
|
+
*/
|
|
50
|
+
htmlEntry?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Mock browser global variables (window, document, etc...) from SSG.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
mock?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Apply formatter to the generated index file.
|
|
59
|
+
*
|
|
60
|
+
* **It will cause Hydration Failed.**
|
|
61
|
+
*
|
|
62
|
+
* @default 'none'
|
|
63
|
+
*/
|
|
64
|
+
formatting?: 'prettify' | 'none';
|
|
65
|
+
/**
|
|
66
|
+
* Vite environmeng mode.
|
|
67
|
+
*/
|
|
68
|
+
mode?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Directory style of the output directory.
|
|
71
|
+
*
|
|
72
|
+
* flat: `/foo` -> `/foo.html`
|
|
73
|
+
* nested: `/foo` -> `/foo/index.html`
|
|
74
|
+
*
|
|
75
|
+
* @default 'flat'
|
|
76
|
+
*/
|
|
77
|
+
dirStyle?: 'flat' | 'nested';
|
|
78
|
+
/**
|
|
79
|
+
* Generate for all routes, including dynamic routes.
|
|
80
|
+
* If enabled, you will need to configGure your serve
|
|
81
|
+
* manually to handle dynamic routes properly.
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
includeAllRoutes?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Options for the critters packages.
|
|
88
|
+
*
|
|
89
|
+
* @deprecated Use `beastiesOptions` instead.
|
|
90
|
+
* @see https://github.com/GoogleChromeLabs/critters
|
|
91
|
+
*/
|
|
92
|
+
crittersOptions?: CrittersOptions | false;
|
|
93
|
+
/**
|
|
94
|
+
* Options for the beasties package.
|
|
95
|
+
*
|
|
96
|
+
* @see https://github.com/danielroe/beasties
|
|
97
|
+
*/
|
|
98
|
+
beastiesOptions?: Options | false;
|
|
99
|
+
/**
|
|
100
|
+
* Custom function to modify the routes to do the SSG.
|
|
101
|
+
*
|
|
102
|
+
* Works only when `includeAllRoutes` is set to false.
|
|
103
|
+
*
|
|
104
|
+
* Defaults to a handler that filters out all the dynamic routes.
|
|
105
|
+
* When passing your custom handler, you should also take care of the dynamic routes yourself.
|
|
106
|
+
*/
|
|
107
|
+
includedRoutes?: (paths: string[], routes: Readonly<RouteRecord[]>) => Promise<string[]> | string[];
|
|
108
|
+
/**
|
|
109
|
+
* Callback to be called before every page render.
|
|
110
|
+
*
|
|
111
|
+
* It can be used to transform the project's `index.html` file before passing it to the renderer.
|
|
112
|
+
*
|
|
113
|
+
* To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
|
|
114
|
+
* The returned value will then be passed to renderer.
|
|
115
|
+
*/
|
|
116
|
+
onBeforePageRender?: (route: string, indexHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Callback to be called on every rendered page.
|
|
119
|
+
*
|
|
120
|
+
* It can be used to transform the current route's rendered HTML.
|
|
121
|
+
*
|
|
122
|
+
* To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
|
|
123
|
+
* The returned value will be used as the HTML of the route.
|
|
124
|
+
*/
|
|
125
|
+
onPageRendered?: (route: string, renderedHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
|
|
126
|
+
onFinished?: (dir: string) => Promise<void> | void;
|
|
127
|
+
/**
|
|
128
|
+
* The application's root container `id`.
|
|
129
|
+
*
|
|
130
|
+
* @default `root`
|
|
131
|
+
*/
|
|
132
|
+
rootContainerId?: string;
|
|
133
|
+
/**
|
|
134
|
+
* The size of the SSG processing queue.
|
|
135
|
+
*
|
|
136
|
+
* @default 20
|
|
137
|
+
*/
|
|
138
|
+
concurrency?: number;
|
|
139
|
+
}
|
|
140
|
+
interface ViteReactSSGContext<HasRouter extends boolean = true> {
|
|
141
|
+
router?: HasRouter extends true ? Router : undefined;
|
|
142
|
+
routes: HasRouter extends true ? Readonly<RouteRecord[]> : undefined;
|
|
143
|
+
routerOptions: HasRouter extends true ? RouterOptions : undefined;
|
|
144
|
+
initialState: Record<string, any>;
|
|
145
|
+
isClient: boolean;
|
|
146
|
+
onSSRAppRendered: (cb: Function) => void;
|
|
147
|
+
triggerOnSSRAppRendered: (route: string, appHTML: string, appCtx: ViteReactSSGContext) => Promise<unknown[]>;
|
|
148
|
+
transformState?: (state: any) => any;
|
|
149
|
+
/**
|
|
150
|
+
* Current router path on SSG, `undefined` on client side.
|
|
151
|
+
*/
|
|
152
|
+
routePath?: string;
|
|
153
|
+
base: string;
|
|
154
|
+
getStyleCollector: (() => StyleCollector | Promise<StyleCollector>) | null;
|
|
155
|
+
app?: HasRouter extends true ? never : ReactNode;
|
|
156
|
+
routerType: 'remix' | 'single-page';
|
|
157
|
+
}
|
|
158
|
+
interface ViteReactSSGClientOptions {
|
|
159
|
+
transformState?: (state: any) => any;
|
|
160
|
+
registerComponents?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* The application's root container query selector.
|
|
163
|
+
*
|
|
164
|
+
* @default `#root`
|
|
165
|
+
*/
|
|
166
|
+
rootContainer?: string | Element;
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated This option is no longer needed
|
|
169
|
+
*/
|
|
170
|
+
ssrWhenDev?: boolean;
|
|
171
|
+
getStyleCollector?: (() => StyleCollector | Promise<StyleCollector>) | null;
|
|
172
|
+
useLegacyRender?: boolean;
|
|
173
|
+
}
|
|
174
|
+
interface CommonRouteOptions {
|
|
175
|
+
/**
|
|
176
|
+
* Used to obtain static resources through manifest
|
|
177
|
+
*
|
|
178
|
+
* **You are not required to use this field. It is only necessary when "prehydration style loss" occurs.**
|
|
179
|
+
*
|
|
180
|
+
* @example `src/pages/home.tsx`
|
|
181
|
+
*/
|
|
182
|
+
entry?: string;
|
|
183
|
+
/**
|
|
184
|
+
* The getStaticPaths() function should return an array of path
|
|
185
|
+
* to determine which paths will be pre-rendered by vite-react-ssg.
|
|
186
|
+
*
|
|
187
|
+
* This function is only valid for dynamic route.
|
|
188
|
+
*
|
|
189
|
+
* @example () => ['path1', 'path2']
|
|
190
|
+
*/
|
|
191
|
+
getStaticPaths?: () => string[] | Promise<string[]>;
|
|
192
|
+
}
|
|
193
|
+
type NonIndexRouteRecord = Omit<NonIndexRouteObject, 'children'> & {
|
|
194
|
+
children?: RouteRecord[];
|
|
195
|
+
} & CommonRouteOptions;
|
|
196
|
+
type IndexRouteRecord = IndexRouteObject & CommonRouteOptions;
|
|
197
|
+
type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
|
|
198
|
+
interface RouterFutureConfig {
|
|
199
|
+
v7_fetcherPersist?: boolean;
|
|
200
|
+
v7_normalizeFormMethod?: boolean;
|
|
201
|
+
v7_partialHydration?: boolean;
|
|
202
|
+
v7_relativeSplatPath?: boolean;
|
|
203
|
+
v7_skipActionErrorRevalidation?: boolean;
|
|
204
|
+
}
|
|
205
|
+
interface RouterOptions {
|
|
206
|
+
routes: RouteRecord[];
|
|
207
|
+
basename?: string;
|
|
208
|
+
future?: Partial<RouterFutureConfig & FutureConfig>;
|
|
209
|
+
customCreateRouter?: typeof createBrowserRouter;
|
|
210
|
+
}
|
|
211
|
+
interface StyleCollector {
|
|
212
|
+
collect: (app: ReactElement) => ReactElement;
|
|
213
|
+
toString: (html: string) => string;
|
|
214
|
+
cleanup?: () => void;
|
|
215
|
+
}
|
|
216
|
+
declare module 'vite' {
|
|
217
|
+
interface UserConfig {
|
|
218
|
+
ssgOptions?: ViteReactSSGOptions;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/client/components/ClientOnly.d.ts
|
|
223
|
+
interface ClientOnlyProps {
|
|
224
|
+
children?: () => React.ReactNode;
|
|
225
|
+
fallback?: React.ReactNode;
|
|
226
|
+
}
|
|
227
|
+
declare function ClientOnly({
|
|
228
|
+
children,
|
|
229
|
+
fallback
|
|
230
|
+
}: ClientOnlyProps): React.ReactNode | null;
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/client/components/Head.d.ts
|
|
233
|
+
type Props = HelmetProps & {
|
|
234
|
+
children: ReactNode;
|
|
235
|
+
};
|
|
236
|
+
declare function Head(props: Props): React.ReactNode;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/client/single-page.d.ts
|
|
239
|
+
declare function ViteReactSSG(App: ReactNode, fn?: (context: ViteReactSSGContext<false>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<false>>;
|
|
240
|
+
//#endregion
|
|
241
|
+
export { ClientOnly, CrittersOptions, Head, IndexRouteRecord, NonIndexRouteRecord, RouteRecord, RouterFutureConfig, RouterOptions, StyleCollector, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext, ViteReactSSGOptions };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { HelmetProps } from "react-helmet-async";
|
|
2
|
+
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { Options } from "beasties";
|
|
4
|
+
import { FutureConfig, IndexRouteObject, NonIndexRouteObject, createBrowserRouter } from "react-router-dom";
|
|
5
|
+
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
type Router = ReturnType<typeof createBrowserRouter>;
|
|
8
|
+
interface CrittersOptions {
|
|
9
|
+
path?: string;
|
|
10
|
+
publicPath?: string;
|
|
11
|
+
external?: boolean;
|
|
12
|
+
inlineThreshold?: number;
|
|
13
|
+
minimumExternalSize?: number;
|
|
14
|
+
pruneSource?: boolean;
|
|
15
|
+
mergeStylesheets?: boolean;
|
|
16
|
+
additionalStylesheets?: string[];
|
|
17
|
+
preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
|
|
18
|
+
noscriptFallback?: boolean;
|
|
19
|
+
inlineFonts?: boolean;
|
|
20
|
+
preloadFonts?: boolean;
|
|
21
|
+
fonts?: boolean;
|
|
22
|
+
keyframes?: string;
|
|
23
|
+
compress?: boolean;
|
|
24
|
+
logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
|
|
25
|
+
reduceInlineStyles?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
|
|
28
|
+
/**
|
|
29
|
+
* Set the scripts' loading mode. Only works for `type="module"`.
|
|
30
|
+
*
|
|
31
|
+
* @default 'sync'
|
|
32
|
+
*/
|
|
33
|
+
script?: 'sync' | 'async' | 'defer' | 'async defer';
|
|
34
|
+
/**
|
|
35
|
+
* Build format.
|
|
36
|
+
*
|
|
37
|
+
* @default 'esm'
|
|
38
|
+
*/
|
|
39
|
+
format?: 'esm' | 'cjs';
|
|
40
|
+
/**
|
|
41
|
+
* The path of the main entry file (relative to the project root).
|
|
42
|
+
*
|
|
43
|
+
* @default 'src/main.ts'
|
|
44
|
+
*/
|
|
45
|
+
entry?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The path of the index.html file (relative to the project root).
|
|
48
|
+
* @default 'index.html'
|
|
49
|
+
*/
|
|
50
|
+
htmlEntry?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Mock browser global variables (window, document, etc...) from SSG.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
mock?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Apply formatter to the generated index file.
|
|
59
|
+
*
|
|
60
|
+
* **It will cause Hydration Failed.**
|
|
61
|
+
*
|
|
62
|
+
* @default 'none'
|
|
63
|
+
*/
|
|
64
|
+
formatting?: 'prettify' | 'none';
|
|
65
|
+
/**
|
|
66
|
+
* Vite environmeng mode.
|
|
67
|
+
*/
|
|
68
|
+
mode?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Directory style of the output directory.
|
|
71
|
+
*
|
|
72
|
+
* flat: `/foo` -> `/foo.html`
|
|
73
|
+
* nested: `/foo` -> `/foo/index.html`
|
|
74
|
+
*
|
|
75
|
+
* @default 'flat'
|
|
76
|
+
*/
|
|
77
|
+
dirStyle?: 'flat' | 'nested';
|
|
78
|
+
/**
|
|
79
|
+
* Generate for all routes, including dynamic routes.
|
|
80
|
+
* If enabled, you will need to configGure your serve
|
|
81
|
+
* manually to handle dynamic routes properly.
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
includeAllRoutes?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Options for the critters packages.
|
|
88
|
+
*
|
|
89
|
+
* @deprecated Use `beastiesOptions` instead.
|
|
90
|
+
* @see https://github.com/GoogleChromeLabs/critters
|
|
91
|
+
*/
|
|
92
|
+
crittersOptions?: CrittersOptions | false;
|
|
93
|
+
/**
|
|
94
|
+
* Options for the beasties package.
|
|
95
|
+
*
|
|
96
|
+
* @see https://github.com/danielroe/beasties
|
|
97
|
+
*/
|
|
98
|
+
beastiesOptions?: Options | false;
|
|
99
|
+
/**
|
|
100
|
+
* Custom function to modify the routes to do the SSG.
|
|
101
|
+
*
|
|
102
|
+
* Works only when `includeAllRoutes` is set to false.
|
|
103
|
+
*
|
|
104
|
+
* Defaults to a handler that filters out all the dynamic routes.
|
|
105
|
+
* When passing your custom handler, you should also take care of the dynamic routes yourself.
|
|
106
|
+
*/
|
|
107
|
+
includedRoutes?: (paths: string[], routes: Readonly<RouteRecord[]>) => Promise<string[]> | string[];
|
|
108
|
+
/**
|
|
109
|
+
* Callback to be called before every page render.
|
|
110
|
+
*
|
|
111
|
+
* It can be used to transform the project's `index.html` file before passing it to the renderer.
|
|
112
|
+
*
|
|
113
|
+
* To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
|
|
114
|
+
* The returned value will then be passed to renderer.
|
|
115
|
+
*/
|
|
116
|
+
onBeforePageRender?: (route: string, indexHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Callback to be called on every rendered page.
|
|
119
|
+
*
|
|
120
|
+
* It can be used to transform the current route's rendered HTML.
|
|
121
|
+
*
|
|
122
|
+
* To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
|
|
123
|
+
* The returned value will be used as the HTML of the route.
|
|
124
|
+
*/
|
|
125
|
+
onPageRendered?: (route: string, renderedHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
|
|
126
|
+
onFinished?: (dir: string) => Promise<void> | void;
|
|
127
|
+
/**
|
|
128
|
+
* The application's root container `id`.
|
|
129
|
+
*
|
|
130
|
+
* @default `root`
|
|
131
|
+
*/
|
|
132
|
+
rootContainerId?: string;
|
|
133
|
+
/**
|
|
134
|
+
* The size of the SSG processing queue.
|
|
135
|
+
*
|
|
136
|
+
* @default 20
|
|
137
|
+
*/
|
|
138
|
+
concurrency?: number;
|
|
139
|
+
}
|
|
140
|
+
interface ViteReactSSGContext<HasRouter extends boolean = true> {
|
|
141
|
+
router?: HasRouter extends true ? Router : undefined;
|
|
142
|
+
routes: HasRouter extends true ? Readonly<RouteRecord[]> : undefined;
|
|
143
|
+
routerOptions: HasRouter extends true ? RouterOptions : undefined;
|
|
144
|
+
initialState: Record<string, any>;
|
|
145
|
+
isClient: boolean;
|
|
146
|
+
onSSRAppRendered: (cb: Function) => void;
|
|
147
|
+
triggerOnSSRAppRendered: (route: string, appHTML: string, appCtx: ViteReactSSGContext) => Promise<unknown[]>;
|
|
148
|
+
transformState?: (state: any) => any;
|
|
149
|
+
/**
|
|
150
|
+
* Current router path on SSG, `undefined` on client side.
|
|
151
|
+
*/
|
|
152
|
+
routePath?: string;
|
|
153
|
+
base: string;
|
|
154
|
+
getStyleCollector: (() => StyleCollector | Promise<StyleCollector>) | null;
|
|
155
|
+
app?: HasRouter extends true ? never : ReactNode;
|
|
156
|
+
routerType: 'remix' | 'single-page';
|
|
157
|
+
}
|
|
158
|
+
interface ViteReactSSGClientOptions {
|
|
159
|
+
transformState?: (state: any) => any;
|
|
160
|
+
registerComponents?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* The application's root container query selector.
|
|
163
|
+
*
|
|
164
|
+
* @default `#root`
|
|
165
|
+
*/
|
|
166
|
+
rootContainer?: string | Element;
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated This option is no longer needed
|
|
169
|
+
*/
|
|
170
|
+
ssrWhenDev?: boolean;
|
|
171
|
+
getStyleCollector?: (() => StyleCollector | Promise<StyleCollector>) | null;
|
|
172
|
+
useLegacyRender?: boolean;
|
|
173
|
+
}
|
|
174
|
+
interface CommonRouteOptions {
|
|
175
|
+
/**
|
|
176
|
+
* Used to obtain static resources through manifest
|
|
177
|
+
*
|
|
178
|
+
* **You are not required to use this field. It is only necessary when "prehydration style loss" occurs.**
|
|
179
|
+
*
|
|
180
|
+
* @example `src/pages/home.tsx`
|
|
181
|
+
*/
|
|
182
|
+
entry?: string;
|
|
183
|
+
/**
|
|
184
|
+
* The getStaticPaths() function should return an array of path
|
|
185
|
+
* to determine which paths will be pre-rendered by vite-react-ssg.
|
|
186
|
+
*
|
|
187
|
+
* This function is only valid for dynamic route.
|
|
188
|
+
*
|
|
189
|
+
* @example () => ['path1', 'path2']
|
|
190
|
+
*/
|
|
191
|
+
getStaticPaths?: () => string[] | Promise<string[]>;
|
|
192
|
+
}
|
|
193
|
+
type NonIndexRouteRecord = Omit<NonIndexRouteObject, 'children'> & {
|
|
194
|
+
children?: RouteRecord[];
|
|
195
|
+
} & CommonRouteOptions;
|
|
196
|
+
type IndexRouteRecord = IndexRouteObject & CommonRouteOptions;
|
|
197
|
+
type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
|
|
198
|
+
interface RouterFutureConfig {
|
|
199
|
+
v7_fetcherPersist?: boolean;
|
|
200
|
+
v7_normalizeFormMethod?: boolean;
|
|
201
|
+
v7_partialHydration?: boolean;
|
|
202
|
+
v7_relativeSplatPath?: boolean;
|
|
203
|
+
v7_skipActionErrorRevalidation?: boolean;
|
|
204
|
+
}
|
|
205
|
+
interface RouterOptions {
|
|
206
|
+
routes: RouteRecord[];
|
|
207
|
+
basename?: string;
|
|
208
|
+
future?: Partial<RouterFutureConfig & FutureConfig>;
|
|
209
|
+
customCreateRouter?: typeof createBrowserRouter;
|
|
210
|
+
}
|
|
211
|
+
interface StyleCollector {
|
|
212
|
+
collect: (app: ReactElement) => ReactElement;
|
|
213
|
+
toString: (html: string) => string;
|
|
214
|
+
cleanup?: () => void;
|
|
215
|
+
}
|
|
216
|
+
declare module 'vite' {
|
|
217
|
+
interface UserConfig {
|
|
218
|
+
ssgOptions?: ViteReactSSGOptions;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/client/components/ClientOnly.d.ts
|
|
223
|
+
interface ClientOnlyProps {
|
|
224
|
+
children?: () => React.ReactNode;
|
|
225
|
+
fallback?: React.ReactNode;
|
|
226
|
+
}
|
|
227
|
+
declare function ClientOnly({
|
|
228
|
+
children,
|
|
229
|
+
fallback
|
|
230
|
+
}: ClientOnlyProps): React.ReactNode | null;
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/client/components/Head.d.ts
|
|
233
|
+
type Props = HelmetProps & {
|
|
234
|
+
children: ReactNode;
|
|
235
|
+
};
|
|
236
|
+
declare function Head(props: Props): React.ReactNode;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/client/single-page.d.ts
|
|
239
|
+
declare function ViteReactSSG(App: ReactNode, fn?: (context: ViteReactSSGContext<false>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<false>>;
|
|
240
|
+
//#endregion
|
|
241
|
+
export { ClientOnly, CrittersOptions, Head, IndexRouteRecord, NonIndexRouteRecord, RouteRecord, RouterFutureConfig, RouterOptions, StyleCollector, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext, ViteReactSSGOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"react-helmet-async";import{Helmet as t}from"react-helmet-async";import{Fragment as n,jsx as r}from"react/jsx-runtime";import*as i from"react-dom";import*as a from"react";import{useEffect as o,useState as s}from"react";const c={...i},{version:l,render:u,hydrate:d}=c,f=Number((l||``).split(`.`)[0])>17,p=Number((l||``).split(`.`)[0])>18;function m(e,t,n={}){let{useLegacyRender:r}=n;if(r||!f)d(e,t);else if(p)import(`react-dom/client`).then(({default:{hydrateRoot:n}})=>{a.startTransition(()=>{n(t,e)})});else{c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{hydrateRoot:n}=c;if(!n)throw Error(`hydrateRoot not found`);a.startTransition(()=>{n(t,e),c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1})}}function h(e){return document.readyState===`loading`?new Promise(t=>{document.addEventListener(`DOMContentLoaded`,()=>t(e))}):Promise.resolve(e)}function g(e){try{return JSON.parse(e||`{}`)}catch(t){return console.error(`[SSG] On state deserialization -`,t,e),{}}}function _(){let[e,t]=s(!1);return o(()=>{t(!0)},[]),e}function v({children:e,fallback:t}){return _()?r(n,{children:e?.()}):t??null}function y(e){return r(t,{...e})}const{HelmetProvider:b}=e;function x(e,t,n={}){let{transformState:i,rootContainer:a=`#root`,ssrWhenDev:o,getStyleCollector:s=null}=n,c=typeof window<`u`;async function l(n=!1,r){let a=[],o={isClient:c,onSSRAppRendered:n?()=>{}:e=>a.push(e),triggerOnSSRAppRendered:()=>Promise.all(a.map(e=>e())),initialState:{},transformState:i,routePath:r,getStyleCollector:s,routes:void 0,routerOptions:void 0,base:`/`,app:e,routerType:`single-page`};n&&(await h(),o.initialState=i?.(window.__INITIAL_STATE__||{})||g(window.__INITIAL_STATE__)),await t?.(o);let l=o.initialState;return{...o,initialState:l}}return c&&(async()=>{let t=typeof a==`string`?document.querySelector(a):a;if(!t){typeof $jsdom>`u`&&console.warn(`[vite-react-ssg] Root container not found.`);return}let i=await l(!0);window.__VITE_REACT_SSG_CONTEXT__=i;let o=r(b,{children:e});document.querySelector(`[data-server-rendered=true]`),m(o,t,n)})(),l}export{v as ClientOnly,y as Head,x as ViteReactSSG};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./state-OWuAHBHy.cjs`);let n=require(`react-helmet-async`);n=e.t(n);let r=require(`react/jsx-runtime`),i=require(`react-router-dom`),a=require(`react-dom`);a=e.t(a,1);let o=require(`react`);o=e.t(o,1);const s={...a},{version:c,render:l,hydrate:u}=s,d=Number((c||``).split(`.`)[0])>17,f=Number((c||``).split(`.`)[0])>18;function p(e,t,n={}){let{useLegacyRender:r}=n;if(r||!d)l(e,t);else if(f)import(`react-dom/client`).then(({default:{createRoot:n}})=>{let r=n(t);o.startTransition(()=>{r.render(e)})});else{s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{createRoot:n}=s;if(!n)throw Error(`createRoot not found`);let r=n(t);s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1,o.startTransition(()=>{r.render(e)})}}function m(e,t,n={}){let{useLegacyRender:r}=n;if(r||!d)u(e,t);else if(f)import(`react-dom/client`).then(({default:{hydrateRoot:n}})=>{o.startTransition(()=>{n(t,e)})});else{s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{hydrateRoot:n}=s;if(!n)throw Error(`hydrateRoot not found`);o.startTransition(()=>{n(t,e),s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1})}}function h(e){return document.readyState===`loading`?new Promise(t=>{document.addEventListener(`DOMContentLoaded`,()=>t(e))}):Promise.resolve(e)}function g(){let[e,t]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{t(!0)},[]),e}function _({children:e,fallback:t}){if(g()){if(typeof e!=`function`&&process.env.NODE_ENV===`development`)throw Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
|
|
2
|
+
Current type: ${(0,o.isValidElement)(e)?`React element`:typeof e}`);return(0,r.jsx)(r.Fragment,{children:e?.()})}return t??null}function v(e){return(0,r.jsx)(n.Helmet,{...e})}const{HelmetProvider:y}=n;function b(e,n,a={}){let{transformState:o,rootContainer:s=`#root`,ssrWhenDev:c,getStyleCollector:l=null}=a;process.env.NODE_ENV===`development`&&c!==void 0&&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`.");let u=typeof window<`u`,d=e.basename??`/`,{v7_startTransition:f=!0,...g}=e.future??{};async function _(r=!1,a){let s=e.customCreateRouter??i.createBrowserRouter,c=r?s(t.r(e.routes,v),{future:g}):void 0,f=[],p=r?()=>{}:e=>f.push(e),m={isClient:u,routes:e.routes,router:c,routerOptions:e,onSSRAppRendered:p,triggerOnSSRAppRendered:()=>Promise.all(f.map(e=>e())),initialState:{},transformState:o,routePath:a,base:d,getStyleCollector:l,routerType:`remix`};r&&(await h(),m.initialState=o?.(window.__INITIAL_STATE__||{})||t.t(window.__INITIAL_STATE__)),await n?.(m);let _=m.initialState;return{...m,initialState:_}}return u&&(async()=>{let t=typeof s==`string`?document.querySelector(s):s;if(!t){typeof $jsdom>`u`&&console.warn(`[vite-react-ssg] Root container not found.`);return}let n=(0,i.matchRoutes)(e.routes,window.location)?.filter(e=>e.route.lazy);n&&n?.length>0&&await Promise.all(n.map(async e=>{let t=await e.route.lazy();Object.assign(e.route,{...t,lazy:void 0})}));let o=await _(!0);window.__VITE_REACT_SSG_CONTEXT__=o;let{router:c}=o,l=(0,r.jsx)(y,{children:(0,r.jsx)(i.RouterProvider,{router:c})});document.querySelector(`[data-server-rendered=true]`)===null&&process.env.NODE_ENV===`development`?p(l,t,a):m(l,t,a)})(),_;function v(e){return document.querySelector(`[data-server-rendered=true]`)===null||(e.loader=async({request:n})=>{if(process.env.NODE_ENV===`development`){let t=`_data=${encodeURIComponent(e.id)}`,r=n.url.includes(`?`)?`${n.url}&${t}`:`${n.url}?${t}`;return fetch(r)}else{if(!window.__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__){let e=t.i(d,`static-loader-data-manifest-${window.__VITE_REACT_SSG_HASH__}.json`);window.__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__=await(await fetch(t.s(e))).json()}let{url:r}=n,{pathname:i}=new URL(r),a=window.__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__?.[i];if(!a)return null;if(window.__VITE_REACT_SSG_STATIC_LOADER_DATA__||(window.__VITE_REACT_SSG_STATIC_LOADER_DATA__={}),!window.__VITE_REACT_SSG_STATIC_LOADER_DATA__[i]){let e=t.i(d,a);window.__VITE_REACT_SSG_STATIC_LOADER_DATA__[i]=await(await fetch(t.s(e))).json()}return window.__VITE_REACT_SSG_STATIC_LOADER_DATA__[i]?.[e.id]??null}}),e}}exports.ClientOnly=_,exports.Head=v,exports.ViteReactSSG=b;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { a as RouterFutureConfig, c as ViteReactSSGClientOptions, i as RouteRecord, l as ViteReactSSGContext, n as IndexRouteRecord, o as RouterOptions, r as NonIndexRouteRecord, s as StyleCollector, t as CrittersOptions, u as ViteReactSSGOptions } from "./types-DfHnCTVN.cjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { HelmetProps } from "react-helmet-async";
|
|
4
|
+
|
|
5
|
+
//#region src/client/components/ClientOnly.d.ts
|
|
6
|
+
interface ClientOnlyProps {
|
|
7
|
+
children?: () => React.ReactNode;
|
|
8
|
+
fallback?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare function ClientOnly({
|
|
11
|
+
children,
|
|
12
|
+
fallback
|
|
13
|
+
}: ClientOnlyProps): React.ReactNode | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/client/components/Head.d.ts
|
|
16
|
+
type Props = HelmetProps & {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
declare function Head(props: Props): React.ReactNode;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/client/index.d.ts
|
|
22
|
+
declare function 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
|
+
/** Manifest index: route path -> data file path */
|
|
26
|
+
__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__: Record<string, string>;
|
|
27
|
+
/** Cached loader data: route path -> loader data */
|
|
28
|
+
__VITE_REACT_SSG_STATIC_LOADER_DATA__: Record<string, Record<string, unknown>>;
|
|
29
|
+
__VITE_REACT_SSG_HASH__: string;
|
|
30
|
+
__VITE_REACT_SSG_CONTEXT__: ViteReactSSGContext<true>;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ClientOnly, CrittersOptions, Head, IndexRouteRecord, NonIndexRouteRecord, RouteRecord, RouterFutureConfig, RouterOptions, StyleCollector, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext, ViteReactSSGOptions };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { a as RouterFutureConfig, c as ViteReactSSGClientOptions, i as RouteRecord, l as ViteReactSSGContext, n as IndexRouteRecord, o as RouterOptions, r as NonIndexRouteRecord, s as StyleCollector, t as CrittersOptions, u as ViteReactSSGOptions } from "./types-D9xYNy8A.mjs";
|
|
2
|
+
import { HelmetProps } from "react-helmet-async";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/client/components/ClientOnly.d.ts
|
|
6
|
+
interface ClientOnlyProps {
|
|
7
|
+
children?: () => React.ReactNode;
|
|
8
|
+
fallback?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare function ClientOnly({
|
|
11
|
+
children,
|
|
12
|
+
fallback
|
|
13
|
+
}: ClientOnlyProps): React.ReactNode | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/client/components/Head.d.ts
|
|
16
|
+
type Props = HelmetProps & {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
declare function Head(props: Props): React.ReactNode;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/client/index.d.ts
|
|
22
|
+
declare function 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
|
+
/** Manifest index: route path -> data file path */
|
|
26
|
+
__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__: Record<string, string>;
|
|
27
|
+
/** Cached loader data: route path -> loader data */
|
|
28
|
+
__VITE_REACT_SSG_STATIC_LOADER_DATA__: Record<string, Record<string, unknown>>;
|
|
29
|
+
__VITE_REACT_SSG_HASH__: string;
|
|
30
|
+
__VITE_REACT_SSG_CONTEXT__: ViteReactSSGContext<true>;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ClientOnly, CrittersOptions, Head, IndexRouteRecord, NonIndexRouteRecord, RouteRecord, RouterFutureConfig, RouterOptions, StyleCollector, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext, ViteReactSSGOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{i as e,r as t,s as n,t as r}from"./state-BLI6QppB.mjs";import*as i from"react-helmet-async";import{Helmet as a}from"react-helmet-async";import{Fragment as o,jsx as s}from"react/jsx-runtime";import{RouterProvider as c,createBrowserRouter as l,matchRoutes as u}from"react-router-dom";import*as d from"react-dom";import*as f from"react";import{isValidElement as p,useEffect as m,useState as h}from"react";const g={...d},{version:_,render:v,hydrate:y}=g,b=Number((_||``).split(`.`)[0])>17,x=Number((_||``).split(`.`)[0])>18;function S(e,t,n={}){let{useLegacyRender:r}=n;if(r||!b)v(e,t);else if(x)import(`react-dom/client`).then(({default:{createRoot:n}})=>{let r=n(t);f.startTransition(()=>{r.render(e)})});else{g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{createRoot:n}=g;if(!n)throw Error(`createRoot not found`);let r=n(t);g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1,f.startTransition(()=>{r.render(e)})}}function C(e,t,n={}){let{useLegacyRender:r}=n;if(r||!b)y(e,t);else if(x)import(`react-dom/client`).then(({default:{hydrateRoot:n}})=>{f.startTransition(()=>{n(t,e)})});else{g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!0;let{hydrateRoot:n}=g;if(!n)throw Error(`hydrateRoot not found`);f.startTransition(()=>{n(t,e),g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint=!1})}}function w(e){return document.readyState===`loading`?new Promise(t=>{document.addEventListener(`DOMContentLoaded`,()=>t(e))}):Promise.resolve(e)}function T(){let[e,t]=h(!1);return m(()=>{t(!0)},[]),e}function E({children:e,fallback:t}){if(T()){if(typeof e!=`function`&&process.env.NODE_ENV===`development`)throw Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
|
|
2
|
+
Current type: ${p(e)?`React element`:typeof e}`);return s(o,{children:e?.()})}return t??null}function D(e){return s(a,{...e})}const{HelmetProvider:O}=i;function k(i,a,o={}){let{transformState:d,rootContainer:f=`#root`,ssrWhenDev:p,getStyleCollector:m=null}=o;process.env.NODE_ENV===`development`&&p!==void 0&&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`.");let h=typeof window<`u`,g=i.basename??`/`,{v7_startTransition:_=!0,...v}=i.future??{};async function y(e=!1,n){let o=i.customCreateRouter??l,s=e?o(t(i.routes,b),{future:v}):void 0,c=[],u=e?()=>{}:e=>c.push(e),f={isClient:h,routes:i.routes,router:s,routerOptions:i,onSSRAppRendered:u,triggerOnSSRAppRendered:()=>Promise.all(c.map(e=>e())),initialState:{},transformState:d,routePath:n,base:g,getStyleCollector:m,routerType:`remix`};e&&(await w(),f.initialState=d?.(window.__INITIAL_STATE__||{})||r(window.__INITIAL_STATE__)),await a?.(f);let p=f.initialState;return{...f,initialState:p}}return h&&(async()=>{let e=typeof f==`string`?document.querySelector(f):f;if(!e){typeof $jsdom>`u`&&console.warn(`[vite-react-ssg] Root container not found.`);return}let t=u(i.routes,window.location)?.filter(e=>e.route.lazy);t&&t?.length>0&&await Promise.all(t.map(async e=>{let t=await e.route.lazy();Object.assign(e.route,{...t,lazy:void 0})}));let n=await y(!0);window.__VITE_REACT_SSG_CONTEXT__=n;let{router:r}=n,a=s(O,{children:s(c,{router:r})});document.querySelector(`[data-server-rendered=true]`)===null&&process.env.NODE_ENV===`development`?S(a,e,o):C(a,e,o)})(),y;function b(t){return document.querySelector(`[data-server-rendered=true]`)===null||(t.loader=async({request:r})=>{if(process.env.NODE_ENV===`development`){let e=`_data=${encodeURIComponent(t.id)}`,n=r.url.includes(`?`)?`${r.url}&${e}`:`${r.url}?${e}`;return fetch(n)}else{if(!window.__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__){let t=e(g,`static-loader-data-manifest-${window.__VITE_REACT_SSG_HASH__}.json`);window.__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__=await(await fetch(n(t))).json()}let{url:i}=r,{pathname:a}=new URL(i),o=window.__VITE_REACT_SSG_STATIC_LOADER_MANIFEST__?.[a];if(!o)return null;if(window.__VITE_REACT_SSG_STATIC_LOADER_DATA__||(window.__VITE_REACT_SSG_STATIC_LOADER_DATA__={}),!window.__VITE_REACT_SSG_STATIC_LOADER_DATA__[a]){let t=e(g,o);window.__VITE_REACT_SSG_STATIC_LOADER_DATA__[a]=await(await fetch(n(t))).json()}return window.__VITE_REACT_SSG_STATIC_LOADER_DATA__[a]?.[t.id]??null}}),t}}export{E as ClientOnly,D as Head,k as ViteReactSSG};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`jsdom`);t=e.t(t,1);const n=[];function r(e=`<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>`,r={}){if(global.navigator&&global.navigator.userAgent&&global.navigator.userAgent.includes(`Node.js`)&&global.document&&typeof global.document.destroy==`function`)return global.document.destroy;`url`in r||Object.assign(r,{url:`http://localhost:3000`}),`pretendToBeVisual`in r||Object.assign(r,{pretendToBeVisual:!0});let i=new t.default.JSDOM(e,r),{window:a}=i,{document:o}=a;n.length===0&&(n.push(...Object.getOwnPropertyNames(a).filter(e=>!e.startsWith(`_`)).filter(e=>!(e in global))),n.push(`$jsdom`)),n.forEach(e=>global[e]=a[e]),global.document=o,global.window=a,a.console=global.console,global.$jsdom=i;let s=()=>n.forEach(e=>delete global[e]);return o.destroy=s,s}exports.jsdomGlobal=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"jsdom";const t=[];function n(n=`<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>`,r={}){if(global.navigator&&global.navigator.userAgent&&global.navigator.userAgent.includes(`Node.js`)&&global.document&&typeof global.document.destroy==`function`)return global.document.destroy;`url`in r||Object.assign(r,{url:`http://localhost:3000`}),`pretendToBeVisual`in r||Object.assign(r,{pretendToBeVisual:!0});let i=new e.JSDOM(n,r),{window:a}=i,{document:o}=a;t.length===0&&(t.push(...Object.getOwnPropertyNames(a).filter(e=>!e.startsWith(`_`)).filter(e=>!(e in global))),t.push(`$jsdom`)),t.forEach(e=>global[e]=a[e]),global.document=o,global.window=a,a.console=global.console,global.$jsdom=i;let s=()=>t.forEach(e=>delete global[e]);return o.destroy=s,s}export{n as jsdomGlobal};
|