vite-react-ssg 0.7.2 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +10 -4
  2. package/dist/chunks/jsdomGlobal.cjs +10 -65
  3. package/dist/chunks/jsdomGlobal.mjs +10 -65
  4. package/dist/client/single-page.cjs +8 -6
  5. package/dist/client/single-page.d.cts +3 -4
  6. package/dist/client/single-page.d.mts +3 -4
  7. package/dist/client/single-page.d.ts +3 -4
  8. package/dist/client/single-page.mjs +9 -7
  9. package/dist/index.cjs +19 -12
  10. package/dist/index.d.cts +3 -4
  11. package/dist/index.d.mts +3 -4
  12. package/dist/index.d.ts +3 -4
  13. package/dist/index.mjs +17 -10
  14. package/dist/node/cli.cjs +9 -8
  15. package/dist/node/cli.mjs +7 -6
  16. package/dist/node.cjs +22 -1722
  17. package/dist/node.d.cts +1 -2
  18. package/dist/node.d.mts +1 -2
  19. package/dist/node.d.ts +1 -2
  20. package/dist/node.mjs +17 -1716
  21. package/dist/shared/vite-react-ssg.4y2OEiyV.mjs +31 -0
  22. package/dist/shared/{vite-react-ssg.a292c181.mjs → vite-react-ssg.B6SGTWpD.mjs} +5 -4
  23. package/dist/shared/{vite-react-ssg.c1d49976.cjs → vite-react-ssg.BuZVBVT6.cjs} +5 -8
  24. package/dist/shared/{vite-react-ssg.054e813a.mjs → vite-react-ssg.C0y5wbxl.mjs} +1 -30
  25. package/dist/shared/{vite-react-ssg.0408f7e1.cjs → vite-react-ssg.C2GpVZF1.cjs} +0 -34
  26. package/dist/shared/vite-react-ssg.CFQGqC60.cjs +36 -0
  27. package/dist/shared/vite-react-ssg.CZ2uxKni.mjs +1029 -0
  28. package/dist/shared/vite-react-ssg.CjIppNIS.mjs +30 -0
  29. package/dist/shared/vite-react-ssg.D0EGioth.cjs +35 -0
  30. package/dist/shared/{vite-react-ssg.4d155759.d.ts → vite-react-ssg.Txy2EJkI.d.cts} +26 -7
  31. package/dist/shared/{vite-react-ssg.4d155759.d.cts → vite-react-ssg.Txy2EJkI.d.mts} +26 -7
  32. package/dist/shared/{vite-react-ssg.4d155759.d.mts → vite-react-ssg.Txy2EJkI.d.ts} +26 -7
  33. package/dist/shared/vite-react-ssg.sc14Rk9F.cjs +1038 -0
  34. package/dist/tanstack.cjs +150 -0
  35. package/dist/tanstack.d.cts +29 -0
  36. package/dist/tanstack.d.mts +29 -0
  37. package/dist/tanstack.d.ts +29 -0
  38. package/dist/tanstack.mjs +143 -0
  39. package/package.json +33 -22
  40. /package/dist/shared/{vite-react-ssg.579feabb.mjs → vite-react-ssg.C6pK7rvr.mjs} +0 -0
  41. /package/dist/shared/{vite-react-ssg.bee8a5a9.cjs → vite-react-ssg.CjsEygxB.cjs} +0 -0
  42. /package/dist/shared/{vite-react-ssg.faf3855a.d.cts → vite-react-ssg.Cm9gBlfg.d.cts} +0 -0
  43. /package/dist/shared/{vite-react-ssg.faf3855a.d.mts → vite-react-ssg.Cm9gBlfg.d.mts} +0 -0
  44. /package/dist/shared/{vite-react-ssg.faf3855a.d.ts → vite-react-ssg.Cm9gBlfg.d.ts} +0 -0
@@ -0,0 +1,30 @@
1
+ function joinUrlSegments(a, b) {
2
+ if (!a || !b)
3
+ return a || b || "";
4
+ if (a[a.length - 1] === "/")
5
+ a = a.substring(0, a.length - 1);
6
+ if (b[0] !== "/")
7
+ b = `/${b}`;
8
+ return a + b;
9
+ }
10
+ function removeLeadingSlash(str) {
11
+ return str[0] === "/" ? str.slice(1) : str;
12
+ }
13
+ function stripBase(path, base) {
14
+ if (path === base)
15
+ return "/";
16
+ const devBase = withTrailingSlash(base);
17
+ return path.startsWith(devBase) ? path.slice(devBase.length - 1) : path;
18
+ }
19
+ function withTrailingSlash(path) {
20
+ if (path[path.length - 1] !== "/")
21
+ return `${path}/`;
22
+ return path;
23
+ }
24
+ function withLeadingSlash(path) {
25
+ if (path[0] !== "/")
26
+ return `/${path}`;
27
+ return path;
28
+ }
29
+
30
+ export { withTrailingSlash as a, joinUrlSegments as j, removeLeadingSlash as r, stripBase as s, withLeadingSlash as w };
@@ -0,0 +1,35 @@
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,9 +1,27 @@
1
- import { Options } from 'critters';
2
1
  import { ReactNode, ReactElement } from 'react';
3
2
  import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
4
3
 
5
4
  type Router = ReturnType<typeof createBrowserRouter>;
6
- interface ViteReactSSGOptions {
5
+ interface CrittersOptions {
6
+ path?: string;
7
+ publicPath?: string;
8
+ external?: boolean;
9
+ inlineThreshold?: number;
10
+ minimumExternalSize?: number;
11
+ pruneSource?: boolean;
12
+ mergeStylesheets?: boolean;
13
+ additionalStylesheets?: string[];
14
+ preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
15
+ noscriptFallback?: boolean;
16
+ inlineFonts?: boolean;
17
+ preloadFonts?: boolean;
18
+ fonts?: boolean;
19
+ keyframes?: string;
20
+ compress?: boolean;
21
+ logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
22
+ reduceInlineStyles?: boolean;
23
+ }
24
+ interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
7
25
  /**
8
26
  * Set the scripts' loading mode. Only works for `type="module"`.
9
27
  *
@@ -35,7 +53,7 @@ interface ViteReactSSGOptions {
35
53
  *
36
54
  * @default 'none'
37
55
  */
38
- formatting?: 'minify' | 'prettify' | 'none';
56
+ formatting?: 'prettify' | 'none';
39
57
  /**
40
58
  * Vite environmeng mode.
41
59
  */
@@ -62,7 +80,7 @@ interface ViteReactSSGOptions {
62
80
  *
63
81
  * @see https://github.com/GoogleChromeLabs/critters
64
82
  */
65
- crittersOptions?: Options | false;
83
+ crittersOptions?: CrittersOptions | false;
66
84
  /**
67
85
  * Custom function to modify the routes to do the SSG.
68
86
  *
@@ -80,7 +98,7 @@ interface ViteReactSSGOptions {
80
98
  * To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
81
99
  * The returned value will then be passed to renderer.
82
100
  */
83
- onBeforePageRender?: (route: string, indexHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
101
+ onBeforePageRender?: (route: string, indexHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
84
102
  /**
85
103
  * Callback to be called on every rendered page.
86
104
  *
@@ -89,7 +107,7 @@ interface ViteReactSSGOptions {
89
107
  * To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
90
108
  * The returned value will be used as the HTML of the route.
91
109
  */
92
- onPageRendered?: (route: string, renderedHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
110
+ onPageRendered?: (route: string, renderedHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
93
111
  onFinished?: () => Promise<void> | void;
94
112
  /**
95
113
  * The application's root container `id`.
@@ -120,6 +138,7 @@ interface ViteReactSSGContext<HasRouter extends boolean = true> {
120
138
  base: string;
121
139
  getStyleCollector: (() => StyleCollector | Promise<StyleCollector>) | null;
122
140
  app?: HasRouter extends true ? never : ReactNode;
141
+ routerType: 'remix' | 'single-page';
123
142
  }
124
143
  interface ViteReactSSGClientOptions {
125
144
  transformState?: (state: any) => any;
@@ -176,4 +195,4 @@ declare module 'vite' {
176
195
  }
177
196
  }
178
197
 
179
- export type { IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterOptions as c };
198
+ 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, RouterOptions as c };
@@ -1,9 +1,27 @@
1
- import { Options } from 'critters';
2
1
  import { ReactNode, ReactElement } from 'react';
3
2
  import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
4
3
 
5
4
  type Router = ReturnType<typeof createBrowserRouter>;
6
- interface ViteReactSSGOptions {
5
+ interface CrittersOptions {
6
+ path?: string;
7
+ publicPath?: string;
8
+ external?: boolean;
9
+ inlineThreshold?: number;
10
+ minimumExternalSize?: number;
11
+ pruneSource?: boolean;
12
+ mergeStylesheets?: boolean;
13
+ additionalStylesheets?: string[];
14
+ preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
15
+ noscriptFallback?: boolean;
16
+ inlineFonts?: boolean;
17
+ preloadFonts?: boolean;
18
+ fonts?: boolean;
19
+ keyframes?: string;
20
+ compress?: boolean;
21
+ logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
22
+ reduceInlineStyles?: boolean;
23
+ }
24
+ interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
7
25
  /**
8
26
  * Set the scripts' loading mode. Only works for `type="module"`.
9
27
  *
@@ -35,7 +53,7 @@ interface ViteReactSSGOptions {
35
53
  *
36
54
  * @default 'none'
37
55
  */
38
- formatting?: 'minify' | 'prettify' | 'none';
56
+ formatting?: 'prettify' | 'none';
39
57
  /**
40
58
  * Vite environmeng mode.
41
59
  */
@@ -62,7 +80,7 @@ interface ViteReactSSGOptions {
62
80
  *
63
81
  * @see https://github.com/GoogleChromeLabs/critters
64
82
  */
65
- crittersOptions?: Options | false;
83
+ crittersOptions?: CrittersOptions | false;
66
84
  /**
67
85
  * Custom function to modify the routes to do the SSG.
68
86
  *
@@ -80,7 +98,7 @@ interface ViteReactSSGOptions {
80
98
  * To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
81
99
  * The returned value will then be passed to renderer.
82
100
  */
83
- onBeforePageRender?: (route: string, indexHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
101
+ onBeforePageRender?: (route: string, indexHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
84
102
  /**
85
103
  * Callback to be called on every rendered page.
86
104
  *
@@ -89,7 +107,7 @@ interface ViteReactSSGOptions {
89
107
  * To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
90
108
  * The returned value will be used as the HTML of the route.
91
109
  */
92
- onPageRendered?: (route: string, renderedHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
110
+ onPageRendered?: (route: string, renderedHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
93
111
  onFinished?: () => Promise<void> | void;
94
112
  /**
95
113
  * The application's root container `id`.
@@ -120,6 +138,7 @@ interface ViteReactSSGContext<HasRouter extends boolean = true> {
120
138
  base: string;
121
139
  getStyleCollector: (() => StyleCollector | Promise<StyleCollector>) | null;
122
140
  app?: HasRouter extends true ? never : ReactNode;
141
+ routerType: 'remix' | 'single-page';
123
142
  }
124
143
  interface ViteReactSSGClientOptions {
125
144
  transformState?: (state: any) => any;
@@ -176,4 +195,4 @@ declare module 'vite' {
176
195
  }
177
196
  }
178
197
 
179
- export type { IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterOptions as c };
198
+ 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, RouterOptions as c };
@@ -1,9 +1,27 @@
1
- import { Options } from 'critters';
2
1
  import { ReactNode, ReactElement } from 'react';
3
2
  import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
4
3
 
5
4
  type Router = ReturnType<typeof createBrowserRouter>;
6
- interface ViteReactSSGOptions {
5
+ interface CrittersOptions {
6
+ path?: string;
7
+ publicPath?: string;
8
+ external?: boolean;
9
+ inlineThreshold?: number;
10
+ minimumExternalSize?: number;
11
+ pruneSource?: boolean;
12
+ mergeStylesheets?: boolean;
13
+ additionalStylesheets?: string[];
14
+ preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
15
+ noscriptFallback?: boolean;
16
+ inlineFonts?: boolean;
17
+ preloadFonts?: boolean;
18
+ fonts?: boolean;
19
+ keyframes?: string;
20
+ compress?: boolean;
21
+ logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
22
+ reduceInlineStyles?: boolean;
23
+ }
24
+ interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
7
25
  /**
8
26
  * Set the scripts' loading mode. Only works for `type="module"`.
9
27
  *
@@ -35,7 +53,7 @@ interface ViteReactSSGOptions {
35
53
  *
36
54
  * @default 'none'
37
55
  */
38
- formatting?: 'minify' | 'prettify' | 'none';
56
+ formatting?: 'prettify' | 'none';
39
57
  /**
40
58
  * Vite environmeng mode.
41
59
  */
@@ -62,7 +80,7 @@ interface ViteReactSSGOptions {
62
80
  *
63
81
  * @see https://github.com/GoogleChromeLabs/critters
64
82
  */
65
- crittersOptions?: Options | false;
83
+ crittersOptions?: CrittersOptions | false;
66
84
  /**
67
85
  * Custom function to modify the routes to do the SSG.
68
86
  *
@@ -80,7 +98,7 @@ interface ViteReactSSGOptions {
80
98
  * To do so, you can change the 'index.html' file contents (passed in through the `indexHTML` parameter), and return it.
81
99
  * The returned value will then be passed to renderer.
82
100
  */
83
- onBeforePageRender?: (route: string, indexHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
101
+ onBeforePageRender?: (route: string, indexHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
84
102
  /**
85
103
  * Callback to be called on every rendered page.
86
104
  *
@@ -89,7 +107,7 @@ interface ViteReactSSGOptions {
89
107
  * To do so, you can transform the route's rendered HTML (passed in through the `renderedHTML` parameter), and return it.
90
108
  * The returned value will be used as the HTML of the route.
91
109
  */
92
- onPageRendered?: (route: string, renderedHTML: string, appCtx: ViteReactSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined;
110
+ onPageRendered?: (route: string, renderedHTML: string, appCtx: Context) => Promise<string | null | undefined> | string | null | undefined;
93
111
  onFinished?: () => Promise<void> | void;
94
112
  /**
95
113
  * The application's root container `id`.
@@ -120,6 +138,7 @@ interface ViteReactSSGContext<HasRouter extends boolean = true> {
120
138
  base: string;
121
139
  getStyleCollector: (() => StyleCollector | Promise<StyleCollector>) | null;
122
140
  app?: HasRouter extends true ? never : ReactNode;
141
+ routerType: 'remix' | 'single-page';
123
142
  }
124
143
  interface ViteReactSSGClientOptions {
125
144
  transformState?: (state: any) => any;
@@ -176,4 +195,4 @@ declare module 'vite' {
176
195
  }
177
196
  }
178
197
 
179
- export type { IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, ViteReactSSGOptions as b, RouterOptions as c };
198
+ 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, RouterOptions as c };