vite-react-ssg 0.5.1 → 0.5.2

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
@@ -267,6 +267,21 @@ export default defineConfig({
267
267
  })
268
268
  ```
269
269
 
270
+ ```ts
271
+ // main.ts
272
+ import { ViteReactSSG } from 'vite-react-ssg'
273
+ import { routes } from './App'
274
+ import './index.css'
275
+
276
+ export const createRoot = ViteReactSSG(
277
+ {
278
+ routes,
279
+ // pass your BASE_URL
280
+ basename: import.meta.env.BASE_URL,
281
+ },
282
+ )
283
+ ```
284
+
270
285
  Vite React SSG will give it to the react-router's `basename`.
271
286
 
272
287
  See: [react-router's create-browser-router](https://reactrouter.com/en/main/routers/create-browser-router#basename)
package/dist/index.cjs CHANGED
@@ -113,7 +113,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
113
113
  getStyleCollector = null
114
114
  } = options;
115
115
  const isClient = typeof window !== "undefined";
116
- const BASE_URL = undefined.BASE_URL;
116
+ const BASE_URL = routerOptions.basename ?? "/";
117
117
  async function createRoot(client = false, routePath) {
118
118
  const browserRouter = client ? reactRouterDom.createBrowserRouter(routerOptions.routes, { basename: BASE_URL }) : void 0;
119
119
  const appRenderCallbacks = [];
@@ -166,7 +166,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
166
166
  }
167
167
  const { router } = await createRoot(true);
168
168
  const app = /* @__PURE__ */ React__default.createElement(reactHelmetAsync.HelmetProvider, null, /* @__PURE__ */ React__default.createElement(SiteMetadataDefaults.SiteMetadataDefaults, null), /* @__PURE__ */ React__default.createElement(reactRouterDom.RouterProvider, { router }));
169
- if (!ssrWhenDev && undefined.DEV) {
169
+ if (!ssrWhenDev && process.env.NODE_ENV === "development") {
170
170
  const root = client.createRoot(container);
171
171
  React__default.startTransition(() => {
172
172
  root.render(app);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouterOptions, a as ViteReactSSGContext, b as ViteReactSSGClientOptions } from './shared/vite-react-ssg.91f86102.cjs';
2
- export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, S as StyleCollector, V as ViteReactSSGOptions } from './shared/vite-react-ssg.91f86102.cjs';
1
+ import { R as RouterOptions, a as ViteReactSSGContext, b as ViteReactSSGClientOptions } from './shared/vite-react-ssg.4d8d5138.cjs';
2
+ export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, S as StyleCollector, V as ViteReactSSGOptions } from './shared/vite-react-ssg.4d8d5138.cjs';
3
3
  import React, { ReactNode } from 'react';
4
4
  import { HelmetProps } from 'react-helmet-async';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouterOptions, a as ViteReactSSGContext, b as ViteReactSSGClientOptions } from './shared/vite-react-ssg.91f86102.mjs';
2
- export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, S as StyleCollector, V as ViteReactSSGOptions } from './shared/vite-react-ssg.91f86102.mjs';
1
+ import { R as RouterOptions, a as ViteReactSSGContext, b as ViteReactSSGClientOptions } from './shared/vite-react-ssg.4d8d5138.mjs';
2
+ export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, S as StyleCollector, V as ViteReactSSGOptions } from './shared/vite-react-ssg.4d8d5138.mjs';
3
3
  import React, { ReactNode } from 'react';
4
4
  import { HelmetProps } from 'react-helmet-async';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouterOptions, a as ViteReactSSGContext, b as ViteReactSSGClientOptions } from './shared/vite-react-ssg.91f86102.js';
2
- export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, S as StyleCollector, V as ViteReactSSGOptions } from './shared/vite-react-ssg.91f86102.js';
1
+ import { R as RouterOptions, a as ViteReactSSGContext, b as ViteReactSSGClientOptions } from './shared/vite-react-ssg.4d8d5138.js';
2
+ export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, S as StyleCollector, V as ViteReactSSGOptions } from './shared/vite-react-ssg.4d8d5138.js';
3
3
  import React, { ReactNode } from 'react';
4
4
  import { HelmetProps } from 'react-helmet-async';
5
5
  import { LinkProps, NavLinkProps } from 'react-router-dom';
package/dist/index.mjs CHANGED
@@ -108,7 +108,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
108
108
  getStyleCollector = null
109
109
  } = options;
110
110
  const isClient = typeof window !== "undefined";
111
- const BASE_URL = import.meta.env.BASE_URL;
111
+ const BASE_URL = routerOptions.basename ?? "/";
112
112
  async function createRoot$1(client = false, routePath) {
113
113
  const browserRouter = client ? createBrowserRouter(routerOptions.routes, { basename: BASE_URL }) : void 0;
114
114
  const appRenderCallbacks = [];
@@ -161,7 +161,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
161
161
  }
162
162
  const { router } = await createRoot$1(true);
163
163
  const app = /* @__PURE__ */ React.createElement(HelmetProvider, null, /* @__PURE__ */ React.createElement(SiteMetadataDefaults, null), /* @__PURE__ */ React.createElement(RouterProvider, { router }));
164
- if (!ssrWhenDev && import.meta.env.DEV) {
164
+ if (!ssrWhenDev && process.env.NODE_ENV === "development") {
165
165
  const root = createRoot(container);
166
166
  React.startTransition(() => {
167
167
  root.render(app);
package/dist/node.cjs CHANGED
@@ -29065,7 +29065,9 @@ async function dev(ssgOptions = {}, viteConfig = {}) {
29065
29065
  server: { middlewareMode: true },
29066
29066
  appType: "custom"
29067
29067
  });
29068
- app.use(viteServer.middlewares);
29068
+ app.use((req, res, next) => {
29069
+ viteServer.middlewares.handle(req, res, next);
29070
+ });
29069
29071
  app.use("*", async (req, res) => {
29070
29072
  try {
29071
29073
  const url = req.originalUrl;
package/dist/node.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { V as ViteReactSSGOptions } from './shared/vite-react-ssg.91f86102.cjs';
2
+ import { V as ViteReactSSGOptions } from './shared/vite-react-ssg.4d8d5138.cjs';
3
3
  import 'critters';
4
4
  import 'react';
5
5
  import 'react-router-dom';
package/dist/node.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { V as ViteReactSSGOptions } from './shared/vite-react-ssg.91f86102.mjs';
2
+ import { V as ViteReactSSGOptions } from './shared/vite-react-ssg.4d8d5138.mjs';
3
3
  import 'critters';
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 { V as ViteReactSSGOptions } from './shared/vite-react-ssg.91f86102.js';
2
+ import { V as ViteReactSSGOptions } from './shared/vite-react-ssg.4d8d5138.js';
3
3
  import 'critters';
4
4
  import 'react';
5
5
  import 'react-router-dom';
package/dist/node.mjs CHANGED
@@ -29043,7 +29043,9 @@ async function dev(ssgOptions = {}, viteConfig = {}) {
29043
29043
  server: { middlewareMode: true },
29044
29044
  appType: "custom"
29045
29045
  });
29046
- app.use(viteServer.middlewares);
29046
+ app.use((req, res, next) => {
29047
+ viteServer.middlewares.handle(req, res, next);
29048
+ });
29047
29049
  app.use("*", async (req, res) => {
29048
29050
  try {
29049
29051
  const url = req.originalUrl;
@@ -164,6 +164,7 @@ type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
164
164
  interface RouterOptions {
165
165
  routes: RouteRecord[];
166
166
  createFetchRequest?: <T>(req: T) => Request;
167
+ basename?: string;
167
168
  }
168
169
  interface StyleCollector {
169
170
  collect: (app: ReactElement) => ReactElement;
@@ -164,6 +164,7 @@ type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
164
164
  interface RouterOptions {
165
165
  routes: RouteRecord[];
166
166
  createFetchRequest?: <T>(req: T) => Request;
167
+ basename?: string;
167
168
  }
168
169
  interface StyleCollector {
169
170
  collect: (app: ReactElement) => ReactElement;
@@ -164,6 +164,7 @@ type RouteRecord = NonIndexRouteRecord | IndexRouteRecord;
164
164
  interface RouterOptions {
165
165
  routes: RouteRecord[];
166
166
  createFetchRequest?: <T>(req: T) => Request;
167
+ basename?: string;
167
168
  }
168
169
  interface StyleCollector {
169
170
  collect: (app: ReactElement) => ReactElement;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-react-ssg",
3
3
  "type": "module",
4
- "version": "0.5.1",
4
+ "version": "0.5.2",
5
5
  "packageManager": "pnpm@8.6.6",
6
6
  "description": "",
7
7
  "author": "Riri <Daydreamerriri@outlook.com>",