ssr-plugin-react 5.6.27 → 5.6.28
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
|
@@ -256,7 +256,7 @@ $ npm run start:vite # 以 vite 模式启动,等价于 npx ssr start --vite
|
|
|
256
256
|
|
|
257
257
|
<div style="display:flex">
|
|
258
258
|
<img src="https://res.wx.qq.com/op_res/7F1t4Z8yCHWilehbcFGjAj0yVn0URMiWBGVJa-TVu_eqw5IwUXA2kPYBnfX6YRHy0FVBB-yC6l0IEL02QTJkLg" width="300">
|
|
259
|
-
<img src="https://res.wx.qq.com/op_res/
|
|
259
|
+
<img src="https://res.wx.qq.com/op_res/e7Z2b52xu-o9gaw-FgTmM8w-ohj_vFoDwC9JFl7N3o4c5oThkJ1plMT4D2GrC0rheo5mu5pkgHSw6s-Z8UZhvg" width="300">
|
|
260
260
|
</div>
|
|
261
261
|
|
|
262
262
|
## 前端开发手册
|
|
@@ -9,15 +9,16 @@ const ssr_hoc_react_1 = require("ssr-hoc-react");
|
|
|
9
9
|
// @ts-expect-error
|
|
10
10
|
const Routes = require("_build/ssr-temporary-routes");
|
|
11
11
|
const context_1 = require("./context");
|
|
12
|
-
const { FeRoutes, layoutFetch, App,
|
|
12
|
+
const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes;
|
|
13
13
|
const clientRender = async () => {
|
|
14
|
-
var _a, _b;
|
|
14
|
+
var _a, _b, _c;
|
|
15
15
|
const IApp = App !== null && App !== void 0 ? App : function (props) {
|
|
16
16
|
return props.children;
|
|
17
17
|
};
|
|
18
18
|
// 客户端渲染||hydrate
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const baseName = (_a = window.prefix) !== null && _a !== void 0 ? _a : PrefixRouterBase;
|
|
20
|
+
const routes = await (0, ssr_client_utils_1.preloadComponent)(FeRoutes, baseName);
|
|
21
|
+
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(react_router_dom_1.BrowserRouter, { basename: baseName },
|
|
21
22
|
React.createElement(context_1.AppContext, null,
|
|
22
23
|
React.createElement(react_router_dom_1.Switch, null,
|
|
23
24
|
React.createElement(IApp, null,
|
|
@@ -31,7 +32,7 @@ const clientRender = async () => {
|
|
|
31
32
|
return (React.createElement(react_router_dom_1.Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
|
|
32
33
|
})))))), document.getElementById('app'));
|
|
33
34
|
if (!window.__USE_VITE__) {
|
|
34
|
-
(
|
|
35
|
+
(_c = (_b = module === null || module === void 0 ? void 0 : module.hot) === null || _b === void 0 ? void 0 : _b.accept) === null || _c === void 0 ? void 0 : _c.call(_b); // webpack 场景下的 hmr
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
exports.clientRender = clientRender;
|
|
@@ -10,14 +10,15 @@ const Routes = require("_build/ssr-temporary-routes");
|
|
|
10
10
|
const create_context_1 = require("./create-context");
|
|
11
11
|
// @ts-expect-error
|
|
12
12
|
const index_tsx_1 = require("@/components/layout/index.tsx");
|
|
13
|
-
const { FeRoutes, layoutFetch,
|
|
13
|
+
const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes;
|
|
14
14
|
const serverRender = async (ctx, config) => {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender } = config;
|
|
16
|
+
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender, prefix } = config;
|
|
17
17
|
global.window = (_a = global.window) !== null && _a !== void 0 ? _a : {}; // 防止覆盖上层应用自己定义的 window 对象
|
|
18
18
|
let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
|
|
20
|
+
if (base) {
|
|
21
|
+
path = (0, ssr_server_utils_1.normalizePath)(path, base);
|
|
21
22
|
}
|
|
22
23
|
const { window } = global;
|
|
23
24
|
const routeItem = (0, ssr_server_utils_1.findRoute)(FeRoutes, path);
|
|
@@ -6,15 +6,16 @@ import { wrapComponent } from 'ssr-hoc-react';
|
|
|
6
6
|
// @ts-expect-error
|
|
7
7
|
import * as Routes from '_build/ssr-temporary-routes';
|
|
8
8
|
import { AppContext } from './context';
|
|
9
|
-
const { FeRoutes, layoutFetch, App,
|
|
9
|
+
const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes;
|
|
10
10
|
const clientRender = async () => {
|
|
11
|
-
var _a, _b;
|
|
11
|
+
var _a, _b, _c;
|
|
12
12
|
const IApp = App !== null && App !== void 0 ? App : function (props) {
|
|
13
13
|
return props.children;
|
|
14
14
|
};
|
|
15
15
|
// 客户端渲染||hydrate
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const baseName = (_a = window.prefix) !== null && _a !== void 0 ? _a : PrefixRouterBase;
|
|
17
|
+
const routes = await preloadComponent(FeRoutes, baseName);
|
|
18
|
+
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(BrowserRouter, { basename: baseName },
|
|
18
19
|
React.createElement(AppContext, null,
|
|
19
20
|
React.createElement(Switch, null,
|
|
20
21
|
React.createElement(IApp, null,
|
|
@@ -28,7 +29,7 @@ const clientRender = async () => {
|
|
|
28
29
|
return (React.createElement(Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
|
|
29
30
|
})))))), document.getElementById('app'));
|
|
30
31
|
if (!window.__USE_VITE__) {
|
|
31
|
-
(
|
|
32
|
+
(_c = (_b = module === null || module === void 0 ? void 0 : module.hot) === null || _b === void 0 ? void 0 : _b.accept) === null || _c === void 0 ? void 0 : _c.call(_b); // webpack 场景下的 hmr
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
if (!window.__disableClientRender__) {
|
|
@@ -7,14 +7,15 @@ import * as Routes from '_build/ssr-temporary-routes';
|
|
|
7
7
|
import { serverContext } from './create-context';
|
|
8
8
|
// @ts-expect-error
|
|
9
9
|
import Layout from '@/components/layout/index.tsx';
|
|
10
|
-
const { FeRoutes, layoutFetch,
|
|
10
|
+
const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes;
|
|
11
11
|
const serverRender = async (ctx, config) => {
|
|
12
12
|
var _a, _b;
|
|
13
|
-
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender } = config;
|
|
13
|
+
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender, prefix } = config;
|
|
14
14
|
global.window = (_a = global.window) !== null && _a !== void 0 ? _a : {}; // 防止覆盖上层应用自己定义的 window 对象
|
|
15
15
|
let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
|
|
17
|
+
if (base) {
|
|
18
|
+
path = normalizePath(path, base);
|
|
18
19
|
}
|
|
19
20
|
const { window } = global;
|
|
20
21
|
const routeItem = findRoute(FeRoutes, path);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssr-plugin-react",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.28",
|
|
4
4
|
"description": "plugin-react for ssr",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"postcss-safe-parser": "4.0.1",
|
|
54
54
|
"react-dev-utils": "^11.0.4",
|
|
55
55
|
"serialize-javascript": "^3.0.0",
|
|
56
|
-
"ssr-client-utils": "^5.6.
|
|
57
|
-
"ssr-hoc-react": "^5.6.
|
|
58
|
-
"ssr-server-utils": "^5.6.
|
|
59
|
-
"ssr-webpack": "^5.6.
|
|
56
|
+
"ssr-client-utils": "^5.6.28",
|
|
57
|
+
"ssr-hoc-react": "^5.6.28",
|
|
58
|
+
"ssr-server-utils": "^5.6.28",
|
|
59
|
+
"ssr-webpack": "^5.6.28",
|
|
60
60
|
"terser-webpack-plugin": "^2.3.5",
|
|
61
61
|
"url-loader": "1.1.1",
|
|
62
62
|
"webpack-bundle-analyzer": "^3.6.1",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@types/react-router-dom": "^5.1.3",
|
|
71
71
|
"@types/serialize-javascript": "^1.5.0",
|
|
72
72
|
"@types/webpack": "^4.41.10",
|
|
73
|
-
"ssr-types-react": "^5.6.
|
|
73
|
+
"ssr-types-react": "^5.6.28"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "dbbee89416cebaeb74aab767a185e5826bd082c4"
|
|
76
76
|
}
|
|
@@ -8,7 +8,7 @@ import { IWindow, LayoutProps, ReactClientESMFeRouteItem, ReactClientRoutesType
|
|
|
8
8
|
import * as Routes from '_build/ssr-temporary-routes'
|
|
9
9
|
import { AppContext } from './context'
|
|
10
10
|
|
|
11
|
-
const { FeRoutes, layoutFetch, App,
|
|
11
|
+
const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes as ReactClientRoutesType
|
|
12
12
|
|
|
13
13
|
declare const module: any
|
|
14
14
|
declare const window: IWindow
|
|
@@ -18,9 +18,10 @@ const clientRender = async (): Promise<void> => {
|
|
|
18
18
|
return props.children!
|
|
19
19
|
}
|
|
20
20
|
// 客户端渲染||hydrate
|
|
21
|
-
const
|
|
21
|
+
const baseName = window.prefix ?? PrefixRouterBase
|
|
22
|
+
const routes = await preloadComponent(FeRoutes, baseName)
|
|
22
23
|
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](
|
|
23
|
-
<BrowserRouter basename={
|
|
24
|
+
<BrowserRouter basename={baseName}>
|
|
24
25
|
<AppContext>
|
|
25
26
|
<Switch>
|
|
26
27
|
<IApp>
|
|
@@ -9,16 +9,17 @@ import { serverContext } from './create-context'
|
|
|
9
9
|
// @ts-expect-error
|
|
10
10
|
import Layout from '@/components/layout/index.tsx'
|
|
11
11
|
|
|
12
|
-
const { FeRoutes, layoutFetch,
|
|
12
|
+
const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes as ReactRoutesType
|
|
13
13
|
|
|
14
14
|
declare const global: IGlobal
|
|
15
15
|
|
|
16
16
|
const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.ReactElement> => {
|
|
17
|
-
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender } = config
|
|
17
|
+
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender, prefix } = config
|
|
18
18
|
global.window = global.window ?? {} // 防止覆盖上层应用自己定义的 window 对象
|
|
19
19
|
let path = ctx.request.path // 这里取 pathname 不能够包含 queryString
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const base = prefix ?? PrefixRouterBase // 以开发者实际传入的为最高优先级
|
|
21
|
+
if (base) {
|
|
22
|
+
path = normalizePath(path, base)
|
|
22
23
|
}
|
|
23
24
|
const { window } = global
|
|
24
25
|
const routeItem = findRoute<ReactServerESMFeRouteItem>(FeRoutes, path)
|