vite-react-ssg 0.9.1-beta.1 → 0.9.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/README.md CHANGED
@@ -441,6 +441,39 @@ See: [react-router's optsfuture](https://reactrouter.com/6.28.0/routers/create-b
441
441
 
442
442
  [Example](./examples/lazy-pages/src/main.tsx)
443
443
 
444
+ ## Custom Router Factory
445
+
446
+ You can provide a custom router factory function via `customCreateRouter` option.
447
+ This is useful if you want to use a different router implementation or wrap the default `createBrowserRouter`.
448
+
449
+ ```ts
450
+ import { createBrowserRouter } from 'react-router-dom'
451
+
452
+ export const createRoot = ViteReactSSG(
453
+ {
454
+ routes,
455
+ customCreateRouter: (routes, options) => {
456
+ // Custom logic here
457
+ return createBrowserRouter(routes, options)
458
+ },
459
+ },
460
+ )
461
+ ```
462
+
463
+ eg. [sentry](https://docs.sentry.io/platforms/javascript/guides/react/features/react-router/v6/)
464
+
465
+ ```ts
466
+ import * as Sentry from '@sentry/react'
467
+ import { createBrowserRouter } from 'react-router-dom'
468
+
469
+ export const createRoot = ViteReactSSG(
470
+ {
471
+ routes,
472
+ customCreateRouter: Sentry.wrapCreateBrowserRouterV6(createBrowserRouter),
473
+ },
474
+ )
475
+ ```
476
+
444
477
  ## CSS in JS
445
478
 
446
479
  Use the `getStyleCollector` option to specify an SSR/SSG style collector. Currently only supports `styled-components`.
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.jgFXOhqq.mjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, b as RouterFutureConfig, c as RouterOptions, S as StyleCollector, d as ViteReactSSGOptions } from '../shared/vite-react-ssg.jgFXOhqq.mjs';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.DMvCQLH5.mjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, b as RouteRecord, c as RouterFutureConfig, R as RouterOptions, S as StyleCollector, d as ViteReactSSGOptions } from '../shared/vite-react-ssg.DMvCQLH5.mjs';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.-NlgsPvg.mjs';
5
5
  import 'beasties';
6
6
  import 'react-router-dom';
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.jgFXOhqq.js';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, b as RouterFutureConfig, c as RouterOptions, S as StyleCollector, d as ViteReactSSGOptions } from '../shared/vite-react-ssg.jgFXOhqq.js';
2
+ import { V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from '../shared/vite-react-ssg.DMvCQLH5.js';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, b as RouteRecord, c as RouterFutureConfig, R as RouterOptions, S as StyleCollector, d as ViteReactSSGOptions } from '../shared/vite-react-ssg.DMvCQLH5.js';
4
4
  export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.-NlgsPvg.js';
5
5
  import 'beasties';
6
6
  import 'react-router-dom';
@@ -60,7 +60,7 @@ function ViteReactSSG(App, fn, options = {}) {
60
60
  window.__VITE_REACT_SSG_CONTEXT__ = context;
61
61
  const app = /* @__PURE__ */ jsx(HelmetProvider, { children: App });
62
62
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
63
- if (!isSSR && process.env.NODE_ENV === "development") {
63
+ if (!isSSR) {
64
64
  render(app, container, options);
65
65
  } else {
66
66
  hydrate(app, container, options);
package/dist/index.d.mts CHANGED
@@ -1,33 +1,11 @@
1
- import { V as ViteReactSSGContext, c as RouterOptions, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.jgFXOhqq.mjs';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, b as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.jgFXOhqq.mjs';
1
+ import { V as ViteReactSSGContext, R as RouterOptions, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.DMvCQLH5.mjs';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, b as RouteRecord, c as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.DMvCQLH5.mjs';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.mjs';
4
- import * as react_jsx_runtime from 'react/jsx-runtime';
5
4
  import 'beasties';
6
5
  import 'react';
7
6
  import 'react-router-dom';
8
7
  import 'react-helmet-async';
9
8
 
10
- /**
11
- * @deprecated Please use `Link` from 'react-router-dom' instead.
12
- */
13
- declare function Link({ ref, ...props }: {
14
- [x: string]: any;
15
- ref: any;
16
- }): react_jsx_runtime.JSX.Element;
17
- declare namespace Link {
18
- var displayName: string;
19
- }
20
- /**
21
- * @deprecated Please use `NavLink` from 'react-router-dom' instead.
22
- */
23
- declare function NavLink({ ref, ...props }: {
24
- [x: string]: any;
25
- ref: any;
26
- }): react_jsx_runtime.JSX.Element;
27
- declare namespace NavLink {
28
- var displayName: string;
29
- }
30
-
31
9
  declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
32
10
  declare global {
33
11
  interface Window {
@@ -40,4 +18,4 @@ declare global {
40
18
  }
41
19
  }
42
20
 
43
- export { Link, NavLink, RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext };
21
+ export { RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,11 @@
1
- import { V as ViteReactSSGContext, c as RouterOptions, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.jgFXOhqq.js';
2
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, b as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.jgFXOhqq.js';
1
+ import { V as ViteReactSSGContext, R as RouterOptions, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.DMvCQLH5.js';
2
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, b as RouteRecord, c as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.DMvCQLH5.js';
3
3
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.js';
4
- import * as react_jsx_runtime from 'react/jsx-runtime';
5
4
  import 'beasties';
6
5
  import 'react';
7
6
  import 'react-router-dom';
8
7
  import 'react-helmet-async';
9
8
 
10
- /**
11
- * @deprecated Please use `Link` from 'react-router-dom' instead.
12
- */
13
- declare function Link({ ref, ...props }: {
14
- [x: string]: any;
15
- ref: any;
16
- }): react_jsx_runtime.JSX.Element;
17
- declare namespace Link {
18
- var displayName: string;
19
- }
20
- /**
21
- * @deprecated Please use `NavLink` from 'react-router-dom' instead.
22
- */
23
- declare function NavLink({ ref, ...props }: {
24
- [x: string]: any;
25
- ref: any;
26
- }): react_jsx_runtime.JSX.Element;
27
- declare namespace NavLink {
28
- var displayName: string;
29
- }
30
-
31
9
  declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
32
10
  declare global {
33
11
  interface Window {
@@ -40,4 +18,4 @@ declare global {
40
18
  }
41
19
  }
42
20
 
43
- export { Link, NavLink, RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext };
21
+ export { RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext };
package/dist/index.mjs CHANGED
@@ -1,76 +1,13 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { HelmetProvider } from 'react-helmet-async';
3
- import { useLinkClickHandler, Link as Link$1, NavLink as NavLink$1, matchRoutes, createBrowserRouter, RouterProvider } from 'react-router-dom';
3
+ import { matchRoutes, createBrowserRouter, RouterProvider } from 'react-router-dom';
4
4
  import { r as render, h as hydrate, d as documentReady } from './shared/vite-react-ssg.DTTf7HZy.mjs';
5
5
  import { c as convertRoutesToDataRoutes, j as joinUrlSegments, w as withLeadingSlash, s as stripBase } from './shared/vite-react-ssg.BhGKpaqQ.mjs';
6
6
  import { d as deserializeState } from './shared/vite-react-ssg.C6pK7rvr.mjs';
7
7
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.CoMLbIiW.mjs';
8
- import React from 'react';
8
+ import 'react';
9
9
  import 'react-dom';
10
10
 
11
- function Link({ ref, ...props }) {
12
- const {
13
- replace,
14
- state,
15
- target,
16
- preventScrollReset,
17
- relative,
18
- to,
19
- onClick
20
- } = props;
21
- const internalOnClick = useLinkClickHandler(to, {
22
- replace,
23
- state,
24
- target,
25
- preventScrollReset,
26
- relative
27
- });
28
- function handleClick(event) {
29
- if (onClick)
30
- onClick(event);
31
- if (!event.defaultPrevented) {
32
- React.startTransition(() => {
33
- internalOnClick(event);
34
- });
35
- }
36
- event.defaultPrevented = true;
37
- event.preventDefault();
38
- }
39
- return /* @__PURE__ */ jsx(Link$1, { ...props, ref, onClick: handleClick });
40
- }
41
- Link.displayName = "Link";
42
- function NavLink({ ref, ...props }) {
43
- const {
44
- replace,
45
- state,
46
- target,
47
- preventScrollReset,
48
- relative,
49
- to,
50
- onClick
51
- } = props;
52
- const internalOnClick = useLinkClickHandler(to, {
53
- replace,
54
- state,
55
- target,
56
- preventScrollReset,
57
- relative
58
- });
59
- function handleClick(event) {
60
- if (onClick)
61
- onClick(event);
62
- if (!event.defaultPrevented) {
63
- React.startTransition(() => {
64
- internalOnClick(event);
65
- });
66
- }
67
- event.defaultPrevented = true;
68
- event.preventDefault();
69
- }
70
- return /* @__PURE__ */ jsx(NavLink$1, { ...props, ref, onClick: handleClick });
71
- }
72
- NavLink.displayName = "NavLink";
73
-
74
11
  function ViteReactSSG(routerOptions, fn, options = {}) {
75
12
  const {
76
13
  transformState,
@@ -152,7 +89,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
152
89
  const { router } = context;
153
90
  const app = /* @__PURE__ */ jsx(HelmetProvider, { children: /* @__PURE__ */ jsx(RouterProvider, { router, future: { v7_startTransition } }) });
154
91
  const isSSR = document.querySelector("[data-server-rendered=true]") !== null;
155
- if (!isSSR && process.env.NODE_ENV === "development") {
92
+ if (!isSSR) {
156
93
  render(app, container, options);
157
94
  } else {
158
95
  hydrate(app, container, options);
@@ -205,4 +142,4 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
205
142
  }
206
143
  }
207
144
 
208
- export { Link, NavLink, ViteReactSSG };
145
+ export { ViteReactSSG };
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.DUkzxBEb.mjs';
4
+ import { b as build, d as dev } from '../shared/vite-react-ssg.Dj8AUNXT.mjs';
5
5
  import 'node:module';
6
6
  import 'node:path';
7
7
  import 'fs-extra';
package/dist/node.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { d as ViteReactSSGOptions } from './shared/vite-react-ssg.jgFXOhqq.mjs';
2
+ import { d as ViteReactSSGOptions } from './shared/vite-react-ssg.DMvCQLH5.mjs';
3
3
  import 'beasties';
4
4
  import 'react';
5
5
  import 'react-router-dom';
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { d as ViteReactSSGOptions } from './shared/vite-react-ssg.jgFXOhqq.js';
2
+ import { d as ViteReactSSGOptions } from './shared/vite-react-ssg.DMvCQLH5.js';
3
3
  import 'beasties';
4
4
  import 'react';
5
5
  import 'react-router-dom';
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as build, d as dev } from './shared/vite-react-ssg.DUkzxBEb.mjs';
1
+ export { b as build, d as dev } from './shared/vite-react-ssg.Dj8AUNXT.mjs';
2
2
  import 'node:module';
3
3
  import 'node:path';
4
4
  import 'fs-extra';
@@ -217,4 +217,4 @@ declare module 'vite' {
217
217
  }
218
218
  }
219
219
 
220
- export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, RouterFutureConfig as b, RouterOptions as c, ViteReactSSGOptions as d };
220
+ export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouterOptions as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, RouteRecord as b, RouterFutureConfig as c, ViteReactSSGOptions as d };
@@ -217,4 +217,4 @@ declare module 'vite' {
217
217
  }
218
218
  }
219
219
 
220
- export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouteRecord as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, RouterFutureConfig as b, RouterOptions as c, ViteReactSSGOptions as d };
220
+ export type { CrittersOptions as C, IndexRouteRecord as I, NonIndexRouteRecord as N, RouterOptions as R, StyleCollector as S, ViteReactSSGContext as V, ViteReactSSGClientOptions as a, RouteRecord as b, RouterFutureConfig as c, ViteReactSSGOptions as d };
@@ -355,7 +355,7 @@ class WritableAsPromise extends Writable {
355
355
  }
356
356
  }
357
357
 
358
- const version = "0.9.1-beta.1";
358
+ const version = "0.9.1";
359
359
 
360
360
  function buildLog(text, count) {
361
361
  console.log(`
@@ -693,6 +693,9 @@ function getAdapter(context) {
693
693
  }
694
694
 
695
695
  const dotVitedir = Number.parseInt(version$1) >= 5 ? [".vite"] : [];
696
+ function buildBundlerOptions(options) {
697
+ return Number.parseInt(version$1) >= 8 ? { rolldownOptions: options } : { rollupOptions: options };
698
+ }
696
699
  function getLoaderDataFilePath(routePath, hash) {
697
700
  const normalized = routePath === "/" ? "/index" : routePath.endsWith("/") ? `${routePath}index` : routePath;
698
701
  return `static-loader-data${withLeadingSlash(normalized)}.${hash}.json`;
@@ -743,7 +746,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
743
746
  build: {
744
747
  manifest: true,
745
748
  ssrManifest: true,
746
- rollupOptions: {
749
+ ...buildBundlerOptions({
747
750
  input: {
748
751
  app: join(root, htmlEntry || "./index.html")
749
752
  },
@@ -753,7 +756,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
753
756
  return;
754
757
  handler(level, log);
755
758
  }
756
- }
759
+ })
757
760
  },
758
761
  customLogger: clientLogger,
759
762
  mode: config.mode,
@@ -784,7 +787,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
784
787
  outDir: ssgOut,
785
788
  minify: false,
786
789
  cssCodeSplit: false,
787
- rollupOptions: {
790
+ ...buildBundlerOptions({
788
791
  output: format === "esm" ? {
789
792
  entryFileNames: "[name].mjs",
790
793
  format: "esm"
@@ -798,7 +801,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
798
801
  return;
799
802
  handler(level, log);
800
803
  }
801
- }
804
+ })
802
805
  },
803
806
  mode: config.mode
804
807
  })
@@ -1,6 +1,6 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.jgFXOhqq.mjs';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, b as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.jgFXOhqq.mjs';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.DMvCQLH5.mjs';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, b as RouteRecord, c as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.DMvCQLH5.mjs';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.mjs';
5
5
  import 'beasties';
6
6
  import 'react';
@@ -1,6 +1,6 @@
1
1
  import { AnyRouter } from '@tanstack/react-router';
2
- import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.jgFXOhqq.js';
3
- export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, R as RouteRecord, b as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.jgFXOhqq.js';
2
+ import { V as ViteReactSSGContext$1, a as ViteReactSSGClientOptions } from './shared/vite-react-ssg.DMvCQLH5.js';
3
+ export { C as CrittersOptions, I as IndexRouteRecord, N as NonIndexRouteRecord, b as RouteRecord, c as RouterFutureConfig, S as StyleCollector, d as ViteReactSSGOptions } from './shared/vite-react-ssg.DMvCQLH5.js';
4
4
  export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.-NlgsPvg.js';
5
5
  import 'beasties';
6
6
  import 'react';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-react-ssg",
3
3
  "type": "module",
4
- "version": "0.9.1-beta.1",
4
+ "version": "0.9.1",
5
5
  "packageManager": "pnpm@10.28.2",
6
6
  "description": "Static-site generation for React on Vite.",
7
7
  "author": "Riri <Daydreamerriri@outlook.com>",
@@ -69,10 +69,11 @@
69
69
  "build": "unbuild",
70
70
  "dev": "unbuild --stub",
71
71
  "lint": "eslint .",
72
- "test": "pnpm -r build && vitest run",
72
+ "test": "pnpm --filter \"./examples/*\" --filter=\"!./examples/tanstack\" build && vitest run",
73
73
  "prepublishOnly": "nr build",
74
74
  "release": "bumpp && npm publish",
75
75
  "start": "esno src/index.ts",
76
+ "test:unit": "vitest run --project unit",
76
77
  "typecheck": "tsc --noEmit"
77
78
  },
78
79
  "peerDependencies": {
@@ -83,7 +84,7 @@
83
84
  "react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0",
84
85
  "react-router-dom": "^6.14.1",
85
86
  "styled-components": "^6.0.0",
86
- "vite": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
87
+ "vite": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
87
88
  },
88
89
  "peerDependenciesMeta": {
89
90
  "@tanstack/react-router": {
@@ -123,7 +124,7 @@
123
124
  "@tanstack/start": "^1.120.20",
124
125
  "@types/fs-extra": "^11.0.4",
125
126
  "@types/jsdom": "^21.1.7",
126
- "@types/node": "^18.19.130",
127
+ "@types/node": "^24.10.0",
127
128
  "@types/react": "catalog:",
128
129
  "@types/react-dom": "catalog:",
129
130
  "@types/yargs": "^17.0.35",
@@ -143,7 +144,7 @@
143
144
  "typescript": "^5.9.3",
144
145
  "unbuild": "^3.6.1",
145
146
  "vite": "catalog:",
146
- "vitest": "1.6.1"
147
+ "vitest": "^4.1.5"
147
148
  },
148
149
  "pnpm": {
149
150
  "overrides": {