vite-react-ssg 0.8.3 → 0.8.4
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 +32 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +1 -1
- package/dist/node/cli.cjs +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +1 -1
- package/dist/shared/{vite-react-ssg.BgawrvuJ.mjs → vite-react-ssg.CKcl-j8g.mjs} +5 -2
- package/dist/shared/{vite-react-ssg.D5xBH08M.cjs → vite-react-ssg.Dus0yLsZ.cjs} +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,9 @@ For usage examples, see: [`main`/examples/tanstack/src/main.tsx](https://github.
|
|
|
24
24
|
- [`<ClientOnly/>`](#clientonly)
|
|
25
25
|
- [Document head](#document-head)
|
|
26
26
|
- [Reactive head](#reactive-head)
|
|
27
|
+
- [Redirect](#redirect)
|
|
27
28
|
- [Public Base Path](#public-base-path)
|
|
29
|
+
- [Future config](#future-config)
|
|
28
30
|
- [CSS in JS](#css-in-js)
|
|
29
31
|
- [Critical CSS](#critical-css)
|
|
30
32
|
- [Configuration](#configuration)
|
|
@@ -337,6 +339,36 @@ export default function MyHead() {
|
|
|
337
339
|
}
|
|
338
340
|
```
|
|
339
341
|
|
|
342
|
+
## Redirect
|
|
343
|
+
|
|
344
|
+
You should not use redirect in the loader.
|
|
345
|
+
In vite-react-ssg, the loader only executes during the build process for data fetching.
|
|
346
|
+
If you need to perform a redirect in certain situations, you can use the following method to redirect on the client side:
|
|
347
|
+
|
|
348
|
+
```tsx
|
|
349
|
+
export const routes: RouteRecord[] = [
|
|
350
|
+
{
|
|
351
|
+
path: '/:lng',
|
|
352
|
+
Component: Layout,
|
|
353
|
+
getStaticPaths: () => Object.keys(resources),
|
|
354
|
+
children: [
|
|
355
|
+
// ... some routes
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
path: '/',
|
|
360
|
+
Component: () => {
|
|
361
|
+
const navigate = useNavigate()
|
|
362
|
+
useEffect(() => {
|
|
363
|
+
navigate('/en', { replace: true })
|
|
364
|
+
}, [navigate])
|
|
365
|
+
|
|
366
|
+
return null
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
]
|
|
370
|
+
```
|
|
371
|
+
|
|
340
372
|
## Public Base Path
|
|
341
373
|
|
|
342
374
|
Just set `base` in vite.config.ts like:
|
package/dist/index.cjs
CHANGED
|
@@ -88,7 +88,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
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 ?? "/";
|
|
91
|
-
const { v7_startTransition, ...routerFeature } = routerOptions.future ?? {};
|
|
91
|
+
const { v7_startTransition = true, ...routerFeature } = routerOptions.future ?? {};
|
|
92
92
|
async function createRoot(client = false, routePath) {
|
|
93
93
|
const browserRouter = client ? reactRouterDom.createBrowserRouter(
|
|
94
94
|
remixRouter.convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute),
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,13 @@ import { LinkProps, NavLinkProps } from 'react-router-dom';
|
|
|
6
6
|
import 'beasties';
|
|
7
7
|
import 'react-helmet-async';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Please use `Link` from 'react-router-dom' instead.
|
|
11
|
+
*/
|
|
9
12
|
declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Please use `NavLink` from 'react-router-dom' instead.
|
|
15
|
+
*/
|
|
10
16
|
declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
11
17
|
|
|
12
18
|
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,13 @@ import { LinkProps, NavLinkProps } from 'react-router-dom';
|
|
|
6
6
|
import 'beasties';
|
|
7
7
|
import 'react-helmet-async';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Please use `Link` from 'react-router-dom' instead.
|
|
11
|
+
*/
|
|
9
12
|
declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Please use `NavLink` from 'react-router-dom' instead.
|
|
15
|
+
*/
|
|
10
16
|
declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
11
17
|
|
|
12
18
|
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,13 @@ import { LinkProps, NavLinkProps } from 'react-router-dom';
|
|
|
6
6
|
import 'beasties';
|
|
7
7
|
import 'react-helmet-async';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Please use `Link` from 'react-router-dom' instead.
|
|
11
|
+
*/
|
|
9
12
|
declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Please use `NavLink` from 'react-router-dom' instead.
|
|
15
|
+
*/
|
|
10
16
|
declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
11
17
|
|
|
12
18
|
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
package/dist/index.mjs
CHANGED
|
@@ -83,7 +83,7 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
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 ?? "/";
|
|
86
|
-
const { v7_startTransition, ...routerFeature } = routerOptions.future ?? {};
|
|
86
|
+
const { v7_startTransition = true, ...routerFeature } = routerOptions.future ?? {};
|
|
87
87
|
async function createRoot(client = false, routePath) {
|
|
88
88
|
const browserRouter = client ? createBrowserRouter(
|
|
89
89
|
convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute),
|
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.
|
|
6
|
+
const dev = require('../shared/vite-react-ssg.Dus0yLsZ.cjs');
|
|
7
7
|
const webFetch = require('@remix-run/web-fetch');
|
|
8
8
|
require('node:path');
|
|
9
9
|
require('node:module');
|
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.
|
|
4
|
+
import { b as build, d as dev } from '../shared/vite-react-ssg.CKcl-j8g.mjs';
|
|
5
5
|
import { Headers, Request, Response, fetch, FormData } from '@remix-run/web-fetch';
|
|
6
6
|
import 'node:path';
|
|
7
7
|
import 'node:module';
|
package/dist/node.cjs
CHANGED
package/dist/node.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { once } from 'node:events';
|
|
|
15
15
|
import { c as convertRoutesToDataRoutes } from './vite-react-ssg.C0y5wbxl.mjs';
|
|
16
16
|
import { M as META_CONTAINER_ID } from './vite-react-ssg.B-j07kW6.mjs';
|
|
17
17
|
|
|
18
|
-
const version = "0.8.
|
|
18
|
+
const version = "0.8.4";
|
|
19
19
|
|
|
20
20
|
function buildLog(text, count) {
|
|
21
21
|
console.log(`
|
|
@@ -752,9 +752,11 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
752
752
|
customLogger: clientLogger,
|
|
753
753
|
mode: config.mode
|
|
754
754
|
}));
|
|
755
|
+
let unmock = () => {
|
|
756
|
+
};
|
|
755
757
|
if (mock) {
|
|
756
758
|
const { jsdomGlobal } = await import('../chunks/jsdomGlobal.mjs');
|
|
757
|
-
jsdomGlobal();
|
|
759
|
+
unmock = jsdomGlobal();
|
|
758
760
|
}
|
|
759
761
|
buildLog("Build for server...");
|
|
760
762
|
process.env.VITE_SSG = "true";
|
|
@@ -861,6 +863,7 @@ ${err.stack}`);
|
|
|
861
863
|
`${dim(`${outDir}/`)}${cyan(`static-loader-data-manifest-${hash}.json`.padEnd(15, " "))} ${dim(getSize(staticLoaderDataManifestString))}`
|
|
862
864
|
);
|
|
863
865
|
await fs.remove(join(root, ".vite-react-ssg-temp"));
|
|
866
|
+
unmock();
|
|
864
867
|
const pwaPlugin = config.plugins.find((i) => i.name === "vite-plugin-pwa")?.api;
|
|
865
868
|
if (pwaPlugin && !pwaPlugin.disabled && pwaPlugin.generateSW) {
|
|
866
869
|
buildLog("Regenerate PWA...");
|
|
@@ -36,7 +36,7 @@ const PQueue__default = /*#__PURE__*/_interopDefaultCompat(PQueue);
|
|
|
36
36
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
37
37
|
const ReactDomServer__namespace = /*#__PURE__*/_interopNamespaceCompat(ReactDomServer);
|
|
38
38
|
|
|
39
|
-
const version = "0.8.
|
|
39
|
+
const version = "0.8.4";
|
|
40
40
|
|
|
41
41
|
function buildLog(text, count) {
|
|
42
42
|
console.log(`
|
|
@@ -773,9 +773,11 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
773
773
|
customLogger: clientLogger,
|
|
774
774
|
mode: config.mode
|
|
775
775
|
}));
|
|
776
|
+
let unmock = () => {
|
|
777
|
+
};
|
|
776
778
|
if (mock) {
|
|
777
779
|
const { jsdomGlobal } = await import('../chunks/jsdomGlobal.cjs');
|
|
778
|
-
jsdomGlobal();
|
|
780
|
+
unmock = jsdomGlobal();
|
|
779
781
|
}
|
|
780
782
|
buildLog("Build for server...");
|
|
781
783
|
process.env.VITE_SSG = "true";
|
|
@@ -809,7 +811,7 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
809
811
|
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
810
812
|
const serverEntry = node_path.join(prefix, ssgOut, node_path.parse(ssrEntry).name + ext);
|
|
811
813
|
const serverManifest = JSON.parse(await fs__default.readFile(node_path.join(ssgOut, ...dotVitedir, "manifest.json"), "utf-8"));
|
|
812
|
-
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.
|
|
814
|
+
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.Dus0yLsZ.cjs', document.baseURI).href)));
|
|
813
815
|
const { createRoot, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
|
|
814
816
|
const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes;
|
|
815
817
|
const { routes } = await createRoot(false);
|
|
@@ -882,6 +884,7 @@ ${err.stack}`);
|
|
|
882
884
|
`${kolorist.dim(`${outDir}/`)}${kolorist.cyan(`static-loader-data-manifest-${hash}.json`.padEnd(15, " "))} ${kolorist.dim(getSize(staticLoaderDataManifestString))}`
|
|
883
885
|
);
|
|
884
886
|
await fs__default.remove(node_path.join(root, ".vite-react-ssg-temp"));
|
|
887
|
+
unmock();
|
|
885
888
|
const pwaPlugin = config.plugins.find((i) => i.name === "vite-plugin-pwa")?.api;
|
|
886
889
|
if (pwaPlugin && !pwaPlugin.disabled && pwaPlugin.generateSW) {
|
|
887
890
|
buildLog("Regenerate PWA...");
|
package/package.json
CHANGED