vite-react-ssg 0.8.0-beta.3 → 0.8.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 (33) hide show
  1. package/README.md +12 -9
  2. package/dist/client/single-page.cjs +3 -3
  3. package/dist/client/single-page.d.cts +3 -2
  4. package/dist/client/single-page.d.mts +3 -2
  5. package/dist/client/single-page.d.ts +3 -2
  6. package/dist/client/single-page.mjs +4 -4
  7. package/dist/index.cjs +4 -4
  8. package/dist/index.d.cts +3 -2
  9. package/dist/index.d.mts +3 -2
  10. package/dist/index.d.ts +3 -2
  11. package/dist/index.mjs +5 -5
  12. package/dist/node/cli.cjs +2 -2
  13. package/dist/node/cli.mjs +2 -2
  14. package/dist/node.cjs +2 -2
  15. package/dist/node.d.cts +2 -1
  16. package/dist/node.d.mts +2 -1
  17. package/dist/node.d.ts +2 -1
  18. package/dist/node.mjs +2 -2
  19. package/dist/shared/{vite-react-ssg.4y2OEiyV.mjs → vite-react-ssg.B-j07kW6.mjs} +1 -1
  20. package/dist/shared/{vite-react-ssg.CphxiYA9.mjs → vite-react-ssg.BdRX-qCI.mjs} +29 -19
  21. package/dist/shared/{vite-react-ssg.D0EGioth.cjs → vite-react-ssg.DWHmkjdM.cjs} +1 -1
  22. package/dist/shared/{vite-react-ssg.B6SGTWpD.mjs → vite-react-ssg.DdDMKzrS.mjs} +1 -1
  23. package/dist/shared/{vite-react-ssg.Txy2EJkI.d.cts → vite-react-ssg.MPbH7GTN.d.cts} +8 -0
  24. package/dist/shared/{vite-react-ssg.Txy2EJkI.d.mts → vite-react-ssg.MPbH7GTN.d.mts} +8 -0
  25. package/dist/shared/{vite-react-ssg.Txy2EJkI.d.ts → vite-react-ssg.MPbH7GTN.d.ts} +8 -0
  26. package/dist/shared/{vite-react-ssg.B_F2Ry8F.cjs → vite-react-ssg.U7W0lHXm.cjs} +30 -20
  27. package/dist/shared/{vite-react-ssg.BuZVBVT6.cjs → vite-react-ssg.yL7u7OP5.cjs} +1 -1
  28. package/dist/tanstack.cjs +7 -7
  29. package/dist/tanstack.d.cts +5 -4
  30. package/dist/tanstack.d.mts +5 -4
  31. package/dist/tanstack.d.ts +5 -4
  32. package/dist/tanstack.mjs +9 -9
  33. package/package.json +12 -7
package/README.md CHANGED
@@ -7,6 +7,9 @@ See demo(also document): [docs](https://vite-react-ssg.netlify.app/)
7
7
  **🎈 Support for [`@tanstack/router`](https://tanstack.com/router/latest/docs/framework/react/overview)
8
8
  and [`wouter`](https://github.com/molefrog/wouter) is in progress!**
9
9
 
10
+ Support for the [`@tanstack/router`](https://tanstack.com/router/latest/docs/framework/react/overview) router is still experimental, and `pathname.lazy.tsx routes` are not yet supported.
11
+ For usage examples, see: [`main`/examples/tanstack/src/main.tsx](https://github.com/Daydreamer-riri/vite-react-ssg/blob/main/examples/tanstack/src/main.tsx)
12
+
10
13
  [![NPM version](https://img.shields.io/npm/v/vite-react-ssg?color=a1b858&label=)](https://www.npmjs.com/package/vite-react-ssg)
11
14
 
12
15
  ## Table of contents
@@ -392,26 +395,26 @@ You can provide your own by looking at the [implementation](./src/style-collecto
392
395
 
393
396
  ## Critical CSS
394
397
 
395
- Vite React SSG has built-in support for generating [Critical CSS](https://web.dev/extract-critical-css/) inlined in the HTML via the [`critters`](https://github.com/GoogleChromeLabs/critters) package.
398
+ Vite React SSG has built-in support for generating [Critical CSS](https://web.dev/extract-critical-css/) inlined in the HTML via the [`beasties`](https://github.com/danielroe/beasties) package.
396
399
  Install it with:
397
400
 
398
401
  ```bash
399
- npm i -D critters
402
+ npm i -D beasties
400
403
  ```
401
404
 
402
405
  Critical CSS generation will automatically be enabled for you.
403
406
 
404
- To configure `critters`, pass [its options](https://github.com/GoogleChromeLabs/critters#usage)
405
- into `ssgOptions.crittersOptions` in `vite.config.ts`:
407
+ To configure `beasties`, pass [its options](https://github.com/danielroe/beasties#usage)
408
+ into `ssgOptions.beastiesOptions` in `vite.config.ts`:
406
409
 
407
410
  ```ts
408
411
  // vite.config.ts
409
412
  export default defineConfig({
410
413
  ssgOptions: {
411
- crittersOptions: {
414
+ beastiesOptions: {
412
415
  // E.g., change the preload strategy
413
416
  preload: 'media',
414
- // Other options: https://github.com/GoogleChromeLabs/critters#usage
417
+ // Other options: https://github.com/danielroe/beasties#usage
415
418
  },
416
419
  },
417
420
  })
@@ -488,11 +491,11 @@ interface ViteReactSSGOptions {
488
491
  */
489
492
  includeAllRoutes?: boolean
490
493
  /**
491
- * Options for the critters packages.
494
+ * Options for the beasties packages.
492
495
  *
493
- * @see https://github.com/GoogleChromeLabs/critters
496
+ * @see https://github.com/danielroe/beasties#usage
494
497
  */
495
- crittersOptions?: CrittersOptions | false
498
+ beastiesOptions?: BeastiesOptions | false
496
499
  /**
497
500
  * Custom function to modify the routes to do the SSG.
498
501
  *
@@ -4,7 +4,7 @@ const jsxRuntime = require('react/jsx-runtime');
4
4
  const client = require('react-dom/client');
5
5
  const reactHelmetAsync = require('react-helmet-async');
6
6
  const React = require('react');
7
- const ClientOnly = require('../shared/vite-react-ssg.BuZVBVT6.cjs');
7
+ const ClientOnly = require('../shared/vite-react-ssg.yL7u7OP5.cjs');
8
8
  const state = require('../shared/vite-react-ssg.CjsEygxB.cjs');
9
9
 
10
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -18,7 +18,7 @@ function ViteReactSSG(App, fn, options = {}) {
18
18
  ssrWhenDev,
19
19
  getStyleCollector = null
20
20
  } = options;
21
- if (undefined.DEV && ssrWhenDev !== void 0)
21
+ if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
22
22
  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`.");
23
23
  const isClient = typeof window !== "undefined";
24
24
  async function createRoot(client = false, routePath) {
@@ -64,7 +64,7 @@ function ViteReactSSG(App, fn, options = {}) {
64
64
  await createRoot(true);
65
65
  const app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: App });
66
66
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
67
- if (!isSSR && undefined.DEV) {
67
+ if (!isSSR && process.env.NODE_ENV === "development") {
68
68
  const root = client.createRoot(container);
69
69
  React__default.startTransition(() => {
70
70
  root.render(app);
@@ -1,8 +1,9 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.Txy2EJkI.cjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.Txy2EJkI.cjs';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.MPbH7GTN.cjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.MPbH7GTN.cjs';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.Cm9gBlfg.cjs';
5
5
  import 'react-router-dom';
6
+ import 'beasties';
6
7
  import 'react-helmet-async';
7
8
 
8
9
  declare function ViteReactSSG(App: ReactNode, fn?: (context: ViteReactSSGContext<false>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<false>>;
@@ -1,8 +1,9 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.Txy2EJkI.mjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.Txy2EJkI.mjs';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.MPbH7GTN.mjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.MPbH7GTN.mjs';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.Cm9gBlfg.mjs';
5
5
  import 'react-router-dom';
6
+ import 'beasties';
6
7
  import 'react-helmet-async';
7
8
 
8
9
  declare function ViteReactSSG(App: ReactNode, fn?: (context: ViteReactSSGContext<false>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<false>>;
@@ -1,8 +1,9 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.Txy2EJkI.js';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.Txy2EJkI.js';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.MPbH7GTN.js';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, c as RouterOptions, S as StyleCollector, b as ViteReactSSGOptions } from '../shared/vite-react-ssg.MPbH7GTN.js';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.Cm9gBlfg.js';
5
5
  import 'react-router-dom';
6
+ import 'beasties';
6
7
  import 'react-helmet-async';
7
8
 
8
9
  declare function ViteReactSSG(App: ReactNode, fn?: (context: ViteReactSSGContext<false>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<false>>;
@@ -2,8 +2,8 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { createRoot, hydrateRoot } from 'react-dom/client';
3
3
  import { HelmetProvider } from 'react-helmet-async';
4
4
  import React from 'react';
5
- import { d as documentReady } from '../shared/vite-react-ssg.B6SGTWpD.mjs';
6
- export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.B6SGTWpD.mjs';
5
+ import { d as documentReady } from '../shared/vite-react-ssg.DdDMKzrS.mjs';
6
+ export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.DdDMKzrS.mjs';
7
7
  import { d as deserializeState } from '../shared/vite-react-ssg.C6pK7rvr.mjs';
8
8
 
9
9
  function ViteReactSSG(App, fn, options = {}) {
@@ -13,7 +13,7 @@ function ViteReactSSG(App, fn, options = {}) {
13
13
  ssrWhenDev,
14
14
  getStyleCollector = null
15
15
  } = options;
16
- if (import.meta.env.DEV && ssrWhenDev !== void 0)
16
+ if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
17
17
  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`.");
18
18
  const isClient = typeof window !== "undefined";
19
19
  async function createRoot$1(client = false, routePath) {
@@ -59,7 +59,7 @@ function ViteReactSSG(App, fn, options = {}) {
59
59
  await createRoot$1(true);
60
60
  const app = /* @__PURE__ */ jsx(HelmetProvider, { children: App });
61
61
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
62
- if (!isSSR && import.meta.env.DEV) {
62
+ if (!isSSR && process.env.NODE_ENV === "development") {
63
63
  const root = createRoot(container);
64
64
  React.startTransition(() => {
65
65
  root.render(app);
package/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@ const React = require('react');
5
5
  const client = require('react-dom/client');
6
6
  const reactHelmetAsync = require('react-helmet-async');
7
7
  const reactRouterDom = require('react-router-dom');
8
- const ClientOnly = require('./shared/vite-react-ssg.BuZVBVT6.cjs');
8
+ const ClientOnly = require('./shared/vite-react-ssg.yL7u7OP5.cjs');
9
9
  const state = require('./shared/vite-react-ssg.CjsEygxB.cjs');
10
10
  const path = require('./shared/vite-react-ssg.CFQGqC60.cjs');
11
11
  const remixRouter = require('./shared/vite-react-ssg.C2GpVZF1.cjs');
@@ -84,7 +84,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
84
84
  ssrWhenDev,
85
85
  getStyleCollector = null
86
86
  } = options;
87
- if (undefined.DEV && ssrWhenDev !== void 0)
87
+ if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
88
88
  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`.");
89
89
  const isClient = typeof window !== "undefined";
90
90
  const BASE_URL = routerOptions.basename ?? "/";
@@ -143,7 +143,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
143
143
  const { router } = await createRoot(true);
144
144
  const app = /* @__PURE__ */ jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.RouterProvider, { router }) });
145
145
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
146
- if (!isSSR && undefined.DEV) {
146
+ if (!isSSR && process.env.NODE_ENV === "development") {
147
147
  const root = client.createRoot(container);
148
148
  React__default.startTransition(() => {
149
149
  root.render(app);
@@ -162,7 +162,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
162
162
  return route;
163
163
  }
164
164
  const loader = async ({ request }) => {
165
- if (undefined.DEV) {
165
+ if (process.env.NODE_ENV === "development") {
166
166
  const routeId = encodeURIComponent(route.id);
167
167
  const dataQuery = `_data=${routeId}`;
168
168
  const url = request.url.includes("?") ? `${request.url}&${dataQuery}` : `${request.url}?${dataQuery}`;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
- import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
1
+ import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.cjs';
4
4
  import React from 'react';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
6
+ import 'beasties';
6
7
  import 'react-helmet-async';
7
8
 
8
9
  declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
1
+ import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.mjs';
4
4
  import React from 'react';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
6
+ import 'beasties';
6
7
  import 'react-helmet-async';
7
8
 
8
9
  declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
1
+ import { c as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.js';
4
4
  import React from 'react';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
6
+ import 'beasties';
6
7
  import 'react-helmet-async';
7
8
 
8
9
  declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
package/dist/index.mjs CHANGED
@@ -3,8 +3,8 @@ import React, { forwardRef } from 'react';
3
3
  import { createRoot, hydrateRoot } from 'react-dom/client';
4
4
  import { HelmetProvider } from 'react-helmet-async';
5
5
  import { useLinkClickHandler, Link as Link$1, NavLink as NavLink$1, matchRoutes, createBrowserRouter, RouterProvider } from 'react-router-dom';
6
- import { d as documentReady } from './shared/vite-react-ssg.B6SGTWpD.mjs';
7
- export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.B6SGTWpD.mjs';
6
+ import { d as documentReady } from './shared/vite-react-ssg.DdDMKzrS.mjs';
7
+ export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.DdDMKzrS.mjs';
8
8
  import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
9
9
  import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
10
10
  import { c as convertRoutesToDataRoutes } from './shared/vite-react-ssg.C0y5wbxl.mjs';
@@ -79,7 +79,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
79
79
  ssrWhenDev,
80
80
  getStyleCollector = null
81
81
  } = options;
82
- if (import.meta.env.DEV && ssrWhenDev !== void 0)
82
+ if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
83
83
  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`.");
84
84
  const isClient = typeof window !== "undefined";
85
85
  const BASE_URL = routerOptions.basename ?? "/";
@@ -138,7 +138,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
138
138
  const { router } = await createRoot$1(true);
139
139
  const app = /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) });
140
140
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
141
- if (!isSSR && import.meta.env.DEV) {
141
+ if (!isSSR && process.env.NODE_ENV === "development") {
142
142
  const root = createRoot(container);
143
143
  React.startTransition(() => {
144
144
  root.render(app);
@@ -157,7 +157,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
157
157
  return route;
158
158
  }
159
159
  const loader = async ({ request }) => {
160
- if (import.meta.env.DEV) {
160
+ if (process.env.NODE_ENV === "development") {
161
161
  const routeId = encodeURIComponent(route.id);
162
162
  const dataQuery = `_data=${routeId}`;
163
163
  const url = request.url.includes("?") ? `${request.url}&${dataQuery}` : `${request.url}?${dataQuery}`;
package/dist/node/cli.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  const kolorist = require('kolorist');
4
4
  const yargs = require('yargs');
5
5
  const helpers = require('yargs/helpers');
6
- const dev = require('../shared/vite-react-ssg.B_F2Ry8F.cjs');
6
+ const dev = require('../shared/vite-react-ssg.U7W0lHXm.cjs');
7
7
  const webFetch = require('@remix-run/web-fetch');
8
8
  require('node:path');
9
9
  require('node:module');
@@ -19,7 +19,7 @@ require('node:stream');
19
19
  require('react-dom/server');
20
20
  require('node:events');
21
21
  require('../shared/vite-react-ssg.C2GpVZF1.cjs');
22
- require('../shared/vite-react-ssg.D0EGioth.cjs');
22
+ require('../shared/vite-react-ssg.DWHmkjdM.cjs');
23
23
 
24
24
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
25
25
 
package/dist/node/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { gray, bold, red, reset, underline } from 'kolorist';
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
- import { b as build, d as dev } from '../shared/vite-react-ssg.CphxiYA9.mjs';
4
+ import { b as build, d as dev } from '../shared/vite-react-ssg.BdRX-qCI.mjs';
5
5
  import { Headers, Request, Response, fetch, FormData } from '@remix-run/web-fetch';
6
6
  import 'node:path';
7
7
  import 'node:module';
@@ -17,7 +17,7 @@ import 'node:stream';
17
17
  import 'react-dom/server';
18
18
  import 'node:events';
19
19
  import '../shared/vite-react-ssg.C0y5wbxl.mjs';
20
- import '../shared/vite-react-ssg.4y2OEiyV.mjs';
20
+ import '../shared/vite-react-ssg.B-j07kW6.mjs';
21
21
 
22
22
  function installGlobals() {
23
23
  global.Headers = Headers;
package/dist/node.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const dev = require('./shared/vite-react-ssg.B_F2Ry8F.cjs');
3
+ const dev = require('./shared/vite-react-ssg.U7W0lHXm.cjs');
4
4
  require('node:path');
5
5
  require('node:module');
6
6
  require('kolorist');
@@ -16,7 +16,7 @@ require('node:stream');
16
16
  require('react-dom/server');
17
17
  require('node:events');
18
18
  require('./shared/vite-react-ssg.C2GpVZF1.cjs');
19
- require('./shared/vite-react-ssg.D0EGioth.cjs');
19
+ require('./shared/vite-react-ssg.DWHmkjdM.cjs');
20
20
 
21
21
 
22
22
 
package/dist/node.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
2
+ import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
3
3
  import 'react';
4
4
  import 'react-router-dom';
5
+ import 'beasties';
5
6
 
6
7
  declare function build(ssgOptions?: Partial<ViteReactSSGOptions>, viteConfig?: InlineConfig): Promise<void>;
7
8
 
package/dist/node.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
2
+ import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
3
3
  import 'react';
4
4
  import 'react-router-dom';
5
+ import 'beasties';
5
6
 
6
7
  declare function build(ssgOptions?: Partial<ViteReactSSGOptions>, viteConfig?: InlineConfig): Promise<void>;
7
8
 
package/dist/node.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
2
+ import { b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
3
3
  import 'react';
4
4
  import 'react-router-dom';
5
+ import 'beasties';
5
6
 
6
7
  declare function build(ssgOptions?: Partial<ViteReactSSGOptions>, viteConfig?: InlineConfig): Promise<void>;
7
8
 
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as build, d as dev } from './shared/vite-react-ssg.CphxiYA9.mjs';
1
+ export { b as build, d as dev } from './shared/vite-react-ssg.BdRX-qCI.mjs';
2
2
  import 'node:path';
3
3
  import 'node:module';
4
4
  import 'kolorist';
@@ -14,4 +14,4 @@ import 'node:stream';
14
14
  import 'react-dom/server';
15
15
  import 'node:events';
16
16
  import './shared/vite-react-ssg.C0y5wbxl.mjs';
17
- import './shared/vite-react-ssg.4y2OEiyV.mjs';
17
+ import './shared/vite-react-ssg.B-j07kW6.mjs';
@@ -5,7 +5,7 @@ function registerPaths(id, getStaticPaths) {
5
5
  async function convertRouteTreeToRouteOption(routeTree, client, visitNode) {
6
6
  const routes = [];
7
7
  async function traverseRouteTree(node) {
8
- if (!client && node.path.includes("$") && node.lazyFn) {
8
+ if (!client && node.path?.includes("$") && node.lazyFn) {
9
9
  await node.lazyFn();
10
10
  }
11
11
  visitNode?.(node);
@@ -13,9 +13,9 @@ import { Writable, Readable } from 'node:stream';
13
13
  import { renderToPipeableStream } from 'react-dom/server';
14
14
  import { once } from 'node:events';
15
15
  import { c as convertRoutesToDataRoutes } from './vite-react-ssg.C0y5wbxl.mjs';
16
- import { M as META_CONTAINER_ID } from './vite-react-ssg.4y2OEiyV.mjs';
16
+ import { M as META_CONTAINER_ID } from './vite-react-ssg.B-j07kW6.mjs';
17
17
 
18
- const version = "0.8.0-beta.3";
18
+ const version = "0.8.1";
19
19
 
20
20
  function buildLog(text, count) {
21
21
  console.log(`
@@ -86,9 +86,22 @@ function isDynamicSegmentsRoute(route) {
86
86
  return dynamicRE.test(route);
87
87
  }
88
88
 
89
- async function getCritters(outDir, options = {}) {
89
+ async function getBeastiesOrCritters(outDir, options = {}) {
90
+ try {
91
+ const BeastiesClass = (await import('beasties')).default;
92
+ return new BeastiesClass({
93
+ path: outDir,
94
+ logLevel: "warn",
95
+ external: true,
96
+ inlineFonts: true,
97
+ preloadFonts: true,
98
+ ...options
99
+ });
100
+ } catch {
101
+ }
90
102
  try {
91
103
  const CrittersClass = (await import('critters')).default;
104
+ console.warn("`critters` is deprecated. Please use `beasties` instead.");
92
105
  return new CrittersClass({
93
106
  path: outDir,
94
107
  logLevel: "warn",
@@ -573,9 +586,9 @@ class TanstackAdapter {
573
586
  this.context = context;
574
587
  }
575
588
  render = async (path) => {
576
- const { getStyleCollector, router: _router } = this.context;
589
+ const { getStyleCollector, router: _router, base } = this.context;
577
590
  const styleCollector = getStyleCollector ? await getStyleCollector() : null;
578
- path = withLeadingSlash(path);
591
+ path = `${withTrailingSlash(base)}${removeLeadingSlash(path)}`;
579
592
  const { createRouter, createMemoryHistory } = await import('@tanstack/react-router');
580
593
  const router = createRouter(_router.options);
581
594
  const { StartServer } = await import('@tanstack/start/server');
@@ -690,12 +703,12 @@ async function build(ssgOptions = {}, viteConfig = {}) {
690
703
  const outDir = config.build.outDir || "dist";
691
704
  const out = isAbsolute(outDir) ? outDir : join(root, outDir);
692
705
  const configBase = config.base;
706
+ const mergedOptions = Object.assign({}, config.ssgOptions || {}, ssgOptions);
693
707
  const {
694
708
  script = "sync",
695
709
  mock = false,
696
710
  entry = await detectEntry(root),
697
711
  formatting = "none",
698
- crittersOptions = {},
699
712
  includedRoutes: configIncludedRoutes = DefaultIncludedRoutes,
700
713
  onBeforePageRender,
701
714
  onPageRendered,
@@ -705,7 +718,8 @@ async function build(ssgOptions = {}, viteConfig = {}) {
705
718
  format = "esm",
706
719
  concurrency = 20,
707
720
  rootContainerId = "root"
708
- } = Object.assign({}, config.ssgOptions || {}, ssgOptions);
721
+ } = mergedOptions;
722
+ const beastiesOptions = mergedOptions.beastiesOptions ?? mergedOptions.crittersOptions ?? {};
709
723
  if (fs.existsSync(ssgOut))
710
724
  await fs.remove(ssgOut);
711
725
  const clientLogger = createLogger();
@@ -733,8 +747,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
733
747
  }
734
748
  },
735
749
  customLogger: clientLogger,
736
- mode: config.mode,
737
- ssr: { noExternal: ["vite-react-ssg"] }
750
+ mode: config.mode
738
751
  }));
739
752
  if (mock) {
740
753
  const { jsdomGlobal } = await import('../chunks/jsdomGlobal.mjs');
@@ -766,8 +779,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
766
779
  }
767
780
  }
768
781
  },
769
- mode: config.mode,
770
- ssr: { noExternal: ["vite-react-ssg", "vite-react-ssg/tanstack"] }
782
+ mode: config.mode
771
783
  }));
772
784
  const prefix = format === "esm" && process.platform === "win32" ? "file://" : "";
773
785
  const ext = format === "esm" ? ".mjs" : ".cjs";
@@ -782,9 +794,9 @@ async function build(ssgOptions = {}, viteConfig = {}) {
782
794
  routesPaths = DefaultIncludedRoutes(routesPaths);
783
795
  routesPaths = Array.from(new Set(routesPaths));
784
796
  buildLog("Rendering Pages...", routesPaths.length);
785
- const critters = crittersOptions !== false ? await getCritters(outDir, { publicPath: configBase, ...crittersOptions }) : void 0;
786
- if (critters)
787
- console.log(`${gray("[vite-react-ssg]")} ${blue("Critical CSS generation enabled via `critters`")}`);
797
+ const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, { publicPath: configBase, ...beastiesOptions }) : void 0;
798
+ if (beasties)
799
+ console.log(`${gray("[vite-react-ssg]")} ${blue("Critical CSS generation enabled via `beasties`")}`);
788
800
  const ssrManifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, "ssr-manifest.json"), "utf-8"));
789
801
  const manifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, "manifest.json"), "utf-8"));
790
802
  let indexHTML = await fs.readFile(join(out, "index.html"), "utf-8");
@@ -818,8 +830,8 @@ async function build(ssgOptions = {}, viteConfig = {}) {
818
830
  const html = jsdom.serialize();
819
831
  let transformed = await onPageRendered?.(path, html, appCtx) || html;
820
832
  transformed = transformed.replace(SCRIPT_COMMENT_PLACEHOLDER, `window.__VITE_REACT_SSG_HASH__ = '${hash}'`);
821
- if (critters) {
822
- transformed = await crittersQueue.add(() => critters.process(transformed));
833
+ if (beasties) {
834
+ transformed = await crittersQueue.add(() => beasties.process(transformed));
823
835
  transformed = transformed.replace(/<link\srel="stylesheet"/g, '<link rel="stylesheet" crossorigin');
824
836
  }
825
837
  if (styleTag)
@@ -1001,9 +1013,7 @@ ${err.stack}`
1001
1013
  })
1002
1014
  ]
1003
1015
  },
1004
- {
1005
- ssr: { noExternal: ["vite-react-ssg"] }
1006
- }
1016
+ {}
1007
1017
  )
1008
1018
  );
1009
1019
  await viteServer.listen();
@@ -7,7 +7,7 @@ function registerPaths(id, getStaticPaths) {
7
7
  async function convertRouteTreeToRouteOption(routeTree, client, visitNode) {
8
8
  const routes = [];
9
9
  async function traverseRouteTree(node) {
10
- if (!client && node.path.includes("$") && node.lazyFn) {
10
+ if (!client && node.path?.includes("$") && node.lazyFn) {
11
11
  await node.lazyFn();
12
12
  }
13
13
  visitNode?.(node);
@@ -29,7 +29,7 @@ function ClientOnly({
29
29
  }) {
30
30
  const isBrowser = useIsClient();
31
31
  if (isBrowser) {
32
- if (typeof children !== "function" && import.meta.env.DEV) {
32
+ if (typeof children !== "function" && process.env.NODE_ENV === "development") {
33
33
  throw new Error(
34
34
  `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
35
35
  Current type: ${isValidElement(children) ? "React element" : typeof children}`
@@ -1,5 +1,6 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
2
  import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
3
+ import { Options } from 'beasties';
3
4
 
4
5
  type Router = ReturnType<typeof createBrowserRouter>;
5
6
  interface CrittersOptions {
@@ -78,9 +79,16 @@ interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
78
79
  /**
79
80
  * Options for the critters packages.
80
81
  *
82
+ * @deprecated Use `beastiesOptions` instead.
81
83
  * @see https://github.com/GoogleChromeLabs/critters
82
84
  */
83
85
  crittersOptions?: CrittersOptions | false;
86
+ /**
87
+ * Options for the beasties package.
88
+ *
89
+ * @see https://github.com/danielroe/beasties
90
+ */
91
+ beastiesOptions?: Options | false;
84
92
  /**
85
93
  * Custom function to modify the routes to do the SSG.
86
94
  *
@@ -1,5 +1,6 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
2
  import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
3
+ import { Options } from 'beasties';
3
4
 
4
5
  type Router = ReturnType<typeof createBrowserRouter>;
5
6
  interface CrittersOptions {
@@ -78,9 +79,16 @@ interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
78
79
  /**
79
80
  * Options for the critters packages.
80
81
  *
82
+ * @deprecated Use `beastiesOptions` instead.
81
83
  * @see https://github.com/GoogleChromeLabs/critters
82
84
  */
83
85
  crittersOptions?: CrittersOptions | false;
86
+ /**
87
+ * Options for the beasties package.
88
+ *
89
+ * @see https://github.com/danielroe/beasties
90
+ */
91
+ beastiesOptions?: Options | false;
84
92
  /**
85
93
  * Custom function to modify the routes to do the SSG.
86
94
  *
@@ -1,5 +1,6 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
2
  import { NonIndexRouteObject, IndexRouteObject, createBrowserRouter } from 'react-router-dom';
3
+ import { Options } from 'beasties';
3
4
 
4
5
  type Router = ReturnType<typeof createBrowserRouter>;
5
6
  interface CrittersOptions {
@@ -78,9 +79,16 @@ interface ViteReactSSGOptions<Context = ViteReactSSGContext> {
78
79
  /**
79
80
  * Options for the critters packages.
80
81
  *
82
+ * @deprecated Use `beastiesOptions` instead.
81
83
  * @see https://github.com/GoogleChromeLabs/critters
82
84
  */
83
85
  crittersOptions?: CrittersOptions | false;
86
+ /**
87
+ * Options for the beasties package.
88
+ *
89
+ * @see https://github.com/danielroe/beasties
90
+ */
91
+ beastiesOptions?: Options | false;
84
92
  /**
85
93
  * Custom function to modify the routes to do the SSG.
86
94
  *
@@ -15,7 +15,7 @@ const node_stream = require('node:stream');
15
15
  const server = require('react-dom/server');
16
16
  const node_events = require('node:events');
17
17
  const remixRouter = require('./vite-react-ssg.C2GpVZF1.cjs');
18
- const tanstackRouter = require('./vite-react-ssg.D0EGioth.cjs');
18
+ const tanstackRouter = require('./vite-react-ssg.DWHmkjdM.cjs');
19
19
 
20
20
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
21
21
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -23,7 +23,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
23
23
  const PQueue__default = /*#__PURE__*/_interopDefaultCompat(PQueue);
24
24
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
25
25
 
26
- const version = "0.8.0-beta.3";
26
+ const version = "0.8.1";
27
27
 
28
28
  function buildLog(text, count) {
29
29
  console.log(`
@@ -94,9 +94,22 @@ function isDynamicSegmentsRoute(route) {
94
94
  return dynamicRE.test(route);
95
95
  }
96
96
 
97
- async function getCritters(outDir, options = {}) {
97
+ async function getBeastiesOrCritters(outDir, options = {}) {
98
+ try {
99
+ const BeastiesClass = (await import('beasties')).default;
100
+ return new BeastiesClass({
101
+ path: outDir,
102
+ logLevel: "warn",
103
+ external: true,
104
+ inlineFonts: true,
105
+ preloadFonts: true,
106
+ ...options
107
+ });
108
+ } catch {
109
+ }
98
110
  try {
99
111
  const CrittersClass = (await import('critters')).default;
112
+ console.warn("`critters` is deprecated. Please use `beasties` instead.");
100
113
  return new CrittersClass({
101
114
  path: outDir,
102
115
  logLevel: "warn",
@@ -581,9 +594,9 @@ class TanstackAdapter {
581
594
  this.context = context;
582
595
  }
583
596
  render = async (path$1) => {
584
- const { getStyleCollector, router: _router } = this.context;
597
+ const { getStyleCollector, router: _router, base } = this.context;
585
598
  const styleCollector = getStyleCollector ? await getStyleCollector() : null;
586
- path$1 = path.withLeadingSlash(path$1);
599
+ path$1 = `${path.withTrailingSlash(base)}${path.removeLeadingSlash(path$1)}`;
587
600
  const { createRouter, createMemoryHistory } = await import('@tanstack/react-router');
588
601
  const router = createRouter(_router.options);
589
602
  const { StartServer } = await import('@tanstack/start/server');
@@ -698,12 +711,12 @@ async function build(ssgOptions = {}, viteConfig = {}) {
698
711
  const outDir = config.build.outDir || "dist";
699
712
  const out = node_path.isAbsolute(outDir) ? outDir : node_path.join(root, outDir);
700
713
  const configBase = config.base;
714
+ const mergedOptions = Object.assign({}, config.ssgOptions || {}, ssgOptions);
701
715
  const {
702
716
  script = "sync",
703
717
  mock = false,
704
718
  entry = await detectEntry(root),
705
719
  formatting = "none",
706
- crittersOptions = {},
707
720
  includedRoutes: configIncludedRoutes = DefaultIncludedRoutes,
708
721
  onBeforePageRender,
709
722
  onPageRendered,
@@ -713,7 +726,8 @@ async function build(ssgOptions = {}, viteConfig = {}) {
713
726
  format = "esm",
714
727
  concurrency = 20,
715
728
  rootContainerId = "root"
716
- } = Object.assign({}, config.ssgOptions || {}, ssgOptions);
729
+ } = mergedOptions;
730
+ const beastiesOptions = mergedOptions.beastiesOptions ?? mergedOptions.crittersOptions ?? {};
717
731
  if (fs__default.existsSync(ssgOut))
718
732
  await fs__default.remove(ssgOut);
719
733
  const clientLogger = vite.createLogger();
@@ -741,8 +755,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
741
755
  }
742
756
  },
743
757
  customLogger: clientLogger,
744
- mode: config.mode,
745
- ssr: { noExternal: ["vite-react-ssg"] }
758
+ mode: config.mode
746
759
  }));
747
760
  if (mock) {
748
761
  const { jsdomGlobal } = await import('../chunks/jsdomGlobal.cjs');
@@ -774,14 +787,13 @@ async function build(ssgOptions = {}, viteConfig = {}) {
774
787
  }
775
788
  }
776
789
  },
777
- mode: config.mode,
778
- ssr: { noExternal: ["vite-react-ssg", "vite-react-ssg/tanstack"] }
790
+ mode: config.mode
779
791
  }));
780
792
  const prefix = format === "esm" && process.platform === "win32" ? "file://" : "";
781
793
  const ext = format === "esm" ? ".mjs" : ".cjs";
782
794
  const serverEntry = node_path.join(prefix, ssgOut, node_path.parse(ssrEntry).name + ext);
783
795
  const serverManifest = JSON.parse(await fs__default.readFile(node_path.join(ssgOut, ...dotVitedir, "manifest.json"), "utf-8"));
784
- const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-react-ssg.B_F2Ry8F.cjs', document.baseURI).href)));
796
+ const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-react-ssg.U7W0lHXm.cjs', document.baseURI).href)));
785
797
  const { createRoot, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
786
798
  const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes;
787
799
  const { routes } = await createRoot(false);
@@ -790,9 +802,9 @@ async function build(ssgOptions = {}, viteConfig = {}) {
790
802
  routesPaths = DefaultIncludedRoutes(routesPaths);
791
803
  routesPaths = Array.from(new Set(routesPaths));
792
804
  buildLog("Rendering Pages...", routesPaths.length);
793
- const critters = crittersOptions !== false ? await getCritters(outDir, { publicPath: configBase, ...crittersOptions }) : void 0;
794
- if (critters)
795
- console.log(`${kolorist.gray("[vite-react-ssg]")} ${kolorist.blue("Critical CSS generation enabled via `critters`")}`);
805
+ const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, { publicPath: configBase, ...beastiesOptions }) : void 0;
806
+ if (beasties)
807
+ console.log(`${kolorist.gray("[vite-react-ssg]")} ${kolorist.blue("Critical CSS generation enabled via `beasties`")}`);
796
808
  const ssrManifest = JSON.parse(await fs__default.readFile(node_path.join(out, ...dotVitedir, "ssr-manifest.json"), "utf-8"));
797
809
  const manifest = JSON.parse(await fs__default.readFile(node_path.join(out, ...dotVitedir, "manifest.json"), "utf-8"));
798
810
  let indexHTML = await fs__default.readFile(node_path.join(out, "index.html"), "utf-8");
@@ -826,8 +838,8 @@ async function build(ssgOptions = {}, viteConfig = {}) {
826
838
  const html = jsdom.serialize();
827
839
  let transformed = await onPageRendered?.(path$1, html, appCtx) || html;
828
840
  transformed = transformed.replace(SCRIPT_COMMENT_PLACEHOLDER, `window.__VITE_REACT_SSG_HASH__ = '${hash}'`);
829
- if (critters) {
830
- transformed = await crittersQueue.add(() => critters.process(transformed));
841
+ if (beasties) {
842
+ transformed = await crittersQueue.add(() => beasties.process(transformed));
831
843
  transformed = transformed.replace(/<link\srel="stylesheet"/g, '<link rel="stylesheet" crossorigin');
832
844
  }
833
845
  if (styleTag)
@@ -1009,9 +1021,7 @@ ${err.stack}`
1009
1021
  })
1010
1022
  ]
1011
1023
  },
1012
- {
1013
- ssr: { noExternal: ["vite-react-ssg"] }
1014
- }
1024
+ {}
1015
1025
  )
1016
1026
  );
1017
1027
  await viteServer.listen();
@@ -31,7 +31,7 @@ function ClientOnly({
31
31
  }) {
32
32
  const isBrowser = useIsClient();
33
33
  if (isBrowser) {
34
- if (typeof children !== "function" && undefined.DEV) {
34
+ if (typeof children !== "function" && process.env.NODE_ENV === "development") {
35
35
  throw new Error(
36
36
  `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
37
37
  Current type: ${React.isValidElement(children) ? "React element" : typeof children}`
package/dist/tanstack.cjs CHANGED
@@ -6,9 +6,9 @@ const client = require('react-dom/client');
6
6
  const reactHelmetAsync = require('react-helmet-async');
7
7
  const reactRouter = require('@tanstack/react-router');
8
8
  const start = require('@tanstack/start');
9
- const ClientOnly = require('./shared/vite-react-ssg.BuZVBVT6.cjs');
9
+ const ClientOnly = require('./shared/vite-react-ssg.yL7u7OP5.cjs');
10
10
  const state = require('./shared/vite-react-ssg.CjsEygxB.cjs');
11
- const tanstackRouter = require('./shared/vite-react-ssg.D0EGioth.cjs');
11
+ const tanstackRouter = require('./shared/vite-react-ssg.DWHmkjdM.cjs');
12
12
  const path = require('./shared/vite-react-ssg.CFQGqC60.cjs');
13
13
 
14
14
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -16,14 +16,14 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
16
16
  const React__default = /*#__PURE__*/_interopDefaultCompat(React);
17
17
 
18
18
  const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
19
- function ViteReactSSG(routerOptions, fn, options = {}) {
19
+ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
20
20
  const {
21
21
  transformState,
22
22
  rootContainer = "#root",
23
23
  ssrWhenDev,
24
24
  getStyleCollector = null
25
25
  } = options;
26
- if (undefined.DEV && ssrWhenDev !== void 0)
26
+ if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
27
27
  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`.");
28
28
  const isClient = typeof window !== "undefined";
29
29
  const BASE_URL = routerOptions.basename ?? "/";
@@ -49,7 +49,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
49
49
  return;
50
50
  node.options.loader = async (ctx) => {
51
51
  let pathname = ctx.location.pathname;
52
- if (undefined.DEV) {
52
+ if (process.env.NODE_ENV === "development") {
53
53
  const routeId = encodeURIComponent(node.id);
54
54
  const dataQuery = `_data=${routeId}`;
55
55
  const href = ctx.location.href;
@@ -124,7 +124,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
124
124
  }
125
125
  const { router } = await createRoot(true);
126
126
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
127
- if (!isSSR && undefined.DEV) {
127
+ if (!isSSR && process.env.NODE_ENV === "development") {
128
128
  const root = client.createRoot(container);
129
129
  React__default.startTransition(() => {
130
130
  root.render(
@@ -147,4 +147,4 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
147
147
  exports.ClientOnly = ClientOnly.ClientOnly;
148
148
  exports.Head = ClientOnly.Head;
149
149
  exports.registerPaths = tanstackRouter.registerPaths;
150
- exports.ViteReactSSG = ViteReactSSG;
150
+ exports.Experimental_ViteReactSSG = Experimental_ViteReactSSG;
@@ -1,9 +1,10 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.cjs';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.cjs';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.cjs';
5
5
  import 'react';
6
6
  import 'react-router-dom';
7
+ import 'beasties';
7
8
  import 'react-helmet-async';
8
9
 
9
10
  declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
@@ -18,7 +19,7 @@ type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGCo
18
19
  routeTree?: AnyRouter['routeTree'];
19
20
  routerType: 'tanstack';
20
21
  };
21
- declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
22
+ declare function Experimental_ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
22
23
  declare global {
23
24
  interface Window {
24
25
  __VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
@@ -26,4 +27,4 @@ declare global {
26
27
  }
27
28
  }
28
29
 
29
- export { type RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
30
+ export { Experimental_ViteReactSSG, type RouterOptions, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
@@ -1,9 +1,10 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.mjs';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.mjs';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.mjs';
5
5
  import 'react';
6
6
  import 'react-router-dom';
7
+ import 'beasties';
7
8
  import 'react-helmet-async';
8
9
 
9
10
  declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
@@ -18,7 +19,7 @@ type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGCo
18
19
  routeTree?: AnyRouter['routeTree'];
19
20
  routerType: 'tanstack';
20
21
  };
21
- declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
22
+ declare function Experimental_ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
22
23
  declare global {
23
24
  interface Window {
24
25
  __VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
@@ -26,4 +27,4 @@ declare global {
26
27
  }
27
28
  }
28
29
 
29
- export { type RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
30
+ export { Experimental_ViteReactSSG, type RouterOptions, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
@@ -1,9 +1,10 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.Txy2EJkI.js';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, S as StyleCollector, b as ViteReactSSGOptions } from './shared/vite-react-ssg.MPbH7GTN.js';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.Cm9gBlfg.js';
5
5
  import 'react';
6
6
  import 'react-router-dom';
7
+ import 'beasties';
7
8
  import 'react-helmet-async';
8
9
 
9
10
  declare function registerPaths(id: string, getStaticPaths: () => string[] | Promise<string[]>): void;
@@ -18,7 +19,7 @@ type ViteReactSSGContext<HasRouter extends boolean = true> = Omit<ViteReactSSGCo
18
19
  routeTree?: AnyRouter['routeTree'];
19
20
  routerType: 'tanstack';
20
21
  };
21
- declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
22
+ declare function Experimental_ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
22
23
  declare global {
23
24
  interface Window {
24
25
  __VITE_REACT_SSG_STATIC_LOADER_DATA__: any;
@@ -26,4 +27,4 @@ declare global {
26
27
  }
27
28
  }
28
29
 
29
- export { type RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
30
+ export { Experimental_ViteReactSSG, type RouterOptions, ViteReactSSGClientOptions, type ViteReactSSGContext, registerPaths };
package/dist/tanstack.mjs CHANGED
@@ -4,22 +4,22 @@ import { createRoot, hydrateRoot } from 'react-dom/client';
4
4
  import { HelmetProvider } from 'react-helmet-async';
5
5
  import { RouterProvider } from '@tanstack/react-router';
6
6
  import { StartClient, Meta } from '@tanstack/start';
7
- import { d as documentReady } from './shared/vite-react-ssg.B6SGTWpD.mjs';
8
- export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.B6SGTWpD.mjs';
7
+ import { d as documentReady } from './shared/vite-react-ssg.DdDMKzrS.mjs';
8
+ export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.DdDMKzrS.mjs';
9
9
  import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
10
- import { M as META_CONTAINER_ID, c as convertRouteTreeToRouteOption } from './shared/vite-react-ssg.4y2OEiyV.mjs';
11
- export { r as registerPaths } from './shared/vite-react-ssg.4y2OEiyV.mjs';
10
+ import { M as META_CONTAINER_ID, c as convertRouteTreeToRouteOption } from './shared/vite-react-ssg.B-j07kW6.mjs';
11
+ export { r as registerPaths } from './shared/vite-react-ssg.B-j07kW6.mjs';
12
12
  import { j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.CjIppNIS.mjs';
13
13
 
14
14
  const HAS_ADD_META_FLAG_KEY = "HAS_ADD_META_FLAG_KEY";
15
- function ViteReactSSG(routerOptions, fn, options = {}) {
15
+ function Experimental_ViteReactSSG(routerOptions, fn, options = {}) {
16
16
  const {
17
17
  transformState,
18
18
  rootContainer = "#root",
19
19
  ssrWhenDev,
20
20
  getStyleCollector = null
21
21
  } = options;
22
- if (import.meta.env.DEV && ssrWhenDev !== void 0)
22
+ if (process.env.NODE_ENV === "development" && ssrWhenDev !== void 0)
23
23
  console.warn("[vite-react-ssg] `ssrWhenDev` option is no longer needed. If you want to use csr, just replace `vite-react-ssg dev` with `vite`.");
24
24
  const isClient = typeof window !== "undefined";
25
25
  const BASE_URL = routerOptions.basename ?? "/";
@@ -45,7 +45,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
45
45
  return;
46
46
  node.options.loader = async (ctx) => {
47
47
  let pathname = ctx.location.pathname;
48
- if (import.meta.env.DEV) {
48
+ if (process.env.NODE_ENV === "development") {
49
49
  const routeId = encodeURIComponent(node.id);
50
50
  const dataQuery = `_data=${routeId}`;
51
51
  const href = ctx.location.href;
@@ -120,7 +120,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
120
120
  }
121
121
  const { router } = await createRoot$1(true);
122
122
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
123
- if (!isSSR && import.meta.env.DEV) {
123
+ if (!isSSR && process.env.NODE_ENV === "development") {
124
124
  const root = createRoot(container);
125
125
  React.startTransition(() => {
126
126
  root.render(
@@ -140,4 +140,4 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
140
140
  return createRoot$1;
141
141
  }
142
142
 
143
- export { ViteReactSSG };
143
+ export { Experimental_ViteReactSSG };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vite-react-ssg",
3
3
  "type": "module",
4
- "version": "0.8.0-beta.3",
5
- "packageManager": "pnpm@9.10.0",
4
+ "version": "0.8.1",
5
+ "packageManager": "pnpm@9.12.3",
6
6
  "description": "Static-site generation for React on Vite.",
7
7
  "author": "Riri <Daydreamerriri@outlook.com>",
8
8
  "license": "MIT",
@@ -82,7 +82,8 @@
82
82
  "typecheck": "tsc --noEmit"
83
83
  },
84
84
  "peerDependencies": {
85
- "critters": "^0.0.19",
85
+ "beasties": "^0.1.0",
86
+ "critters": "^0.0.24",
86
87
  "prettier": "*",
87
88
  "react": "^18.0.0",
88
89
  "react-dom": "^18.0.0",
@@ -97,6 +98,9 @@
97
98
  "@tanstack/start": {
98
99
  "optional": true
99
100
  },
101
+ "beasties": {
102
+ "optional": true
103
+ },
100
104
  "critters": {
101
105
  "optional": true
102
106
  },
@@ -131,10 +135,11 @@
131
135
  "@types/react-dom": "~18.2.6",
132
136
  "@types/yargs": "^17.0.33",
133
137
  "@vitejs/plugin-react-swc": "^3.7.1",
134
- "bumpp": "^9.5.2",
138
+ "beasties": "^0.1.0",
139
+ "bumpp": "^9.8.0",
135
140
  "critters": "^0.0.24",
136
- "eslint": "^9.10.0",
137
- "esno": "^4.7.0",
141
+ "eslint": "^9.13.0",
142
+ "esno": "^4.8.0",
138
143
  "fast-glob": "3.3.2",
139
144
  "prettier": "^3.3.3",
140
145
  "react": "^18.2.0",
@@ -144,7 +149,7 @@
144
149
  "styled-components": "6.0.5",
145
150
  "typescript": "^5.6.2",
146
151
  "unbuild": "^3.0.0-rc.11",
147
- "vite": "^5.4.9",
152
+ "vite": "catalog:",
148
153
  "vitest": "1.6.0"
149
154
  }
150
155
  }