ssr-plugin-react 7.0.5 → 7.0.7
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/CHANGELOG.md +317 -432
- package/README.md +105 -105
- package/cjs/entry/context.d.ts +1 -1
- package/cjs/entry/context.d.ts.map +1 -1
- package/cjs/entry/context.js +5 -5
- package/cjs/entry/context.js.map +1 -1
- package/cjs/entry/create.d.ts +2 -3
- package/cjs/entry/create.d.ts.map +1 -1
- package/cjs/entry/create.js +10 -5
- package/cjs/entry/create.js.map +1 -1
- package/cjs/entry/react17-client-entry.d.ts.map +1 -1
- package/cjs/entry/react17-client-entry.js +7 -8
- package/cjs/entry/react17-client-entry.js.map +1 -1
- package/cjs/entry/react18-client-entry.d.ts.map +1 -1
- package/cjs/entry/react18-client-entry.js +6 -8
- package/cjs/entry/react18-client-entry.js.map +1 -1
- package/cjs/entry/server-entry.d.ts +2 -2
- package/cjs/entry/server-entry.d.ts.map +1 -1
- package/cjs/entry/server-entry.js +42 -28
- package/cjs/entry/server-entry.js.map +1 -1
- package/cjs/index.js +9 -9
- package/cjs/index.js.map +1 -1
- package/esm/entry/context.d.ts +1 -1
- package/esm/entry/context.d.ts.map +1 -1
- package/esm/entry/context.js +7 -7
- package/esm/entry/context.js.map +1 -1
- package/esm/entry/create.d.ts +2 -3
- package/esm/entry/create.d.ts.map +1 -1
- package/esm/entry/create.js +16 -11
- package/esm/entry/create.js.map +1 -1
- package/esm/entry/react17-client-entry.d.ts.map +1 -1
- package/esm/entry/react17-client-entry.js +14 -15
- package/esm/entry/react17-client-entry.js.map +1 -1
- package/esm/entry/react18-client-entry.d.ts.map +1 -1
- package/esm/entry/react18-client-entry.js +13 -15
- package/esm/entry/react18-client-entry.js.map +1 -1
- package/esm/entry/server-entry.d.ts +2 -2
- package/esm/entry/server-entry.d.ts.map +1 -1
- package/esm/entry/server-entry.js +51 -37
- package/esm/entry/server-entry.js.map +1 -1
- package/esm/index.js +11 -11
- package/esm/index.js.map +1 -1
- package/package.json +31 -32
- package/src/entry/context.tsx +33 -29
- package/src/entry/create.ts +27 -24
- package/src/entry/react17-client-entry.tsx +66 -66
- package/src/entry/react18-client-entry.tsx +72 -72
- package/src/entry/server-entry.tsx +192 -141
- package/src/index.ts +38 -38
- package/tsconfig.cjs.json +2 -4
- package/tsconfig.esm.json +2 -4
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import type { hydrateRoot as HydrateRoot, createRoot as CreateRoot } from
|
|
2
|
-
import type { LayoutProps } from
|
|
1
|
+
import type { hydrateRoot as HydrateRoot, createRoot as CreateRoot } from "react-dom18/client";
|
|
2
|
+
import type { LayoutProps } from "ssr-types";
|
|
3
3
|
|
|
4
4
|
//@ts-ignore
|
|
5
|
-
import { hydrateRoot, createRoot } from
|
|
6
|
-
import { createElement } from
|
|
7
|
-
import { BrowserRouter, Route, Switch } from
|
|
8
|
-
import { preloadComponent, isMicro, setStoreContext, setStore } from
|
|
9
|
-
import { wrapComponent } from
|
|
10
|
-
import { ssrCreateContext, Routes, createStore } from
|
|
11
|
-
import { AppContext } from
|
|
12
|
-
const { FeRoutes, layoutFetch, App } = Routes
|
|
5
|
+
import { hydrateRoot, createRoot } from "react-dom/client";
|
|
6
|
+
import { createElement } from "react";
|
|
7
|
+
import { BrowserRouter, Route, Switch } from "react-router-dom";
|
|
8
|
+
import { preloadComponent, isMicro, setStoreContext, setStore } from "ssr-common-utils";
|
|
9
|
+
import { wrapComponent } from "ssr-hoc-react";
|
|
10
|
+
import { ssrCreateContext, Routes, createStore } from "./create";
|
|
11
|
+
import { AppContext } from "./context";
|
|
12
|
+
const { FeRoutes, layoutFetch, App } = Routes;
|
|
13
13
|
const clientRender = async (): Promise<void> => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
14
|
+
const IApp =
|
|
15
|
+
App ??
|
|
16
|
+
function (props: LayoutProps) {
|
|
17
|
+
return props.children!;
|
|
18
|
+
};
|
|
19
|
+
const context = ssrCreateContext() as any;
|
|
20
|
+
setStoreContext(context);
|
|
21
|
+
const store = createStore();
|
|
22
|
+
setStore(store ?? {});
|
|
23
|
+
const baseName = isMicro() ? window.clientPrefix : window.prefix;
|
|
24
|
+
const routes = await preloadComponent(FeRoutes, baseName);
|
|
25
|
+
const container = document.querySelector(window.ssrDevInfo.rootId ?? "#app")!;
|
|
26
|
+
const ele = createElement(
|
|
27
|
+
//@ts-ignore
|
|
28
|
+
BrowserRouter,
|
|
29
|
+
{
|
|
30
|
+
basename: baseName,
|
|
31
|
+
},
|
|
32
|
+
createElement(AppContext, {
|
|
33
|
+
context,
|
|
34
|
+
children: createElement(
|
|
35
|
+
Switch,
|
|
36
|
+
null,
|
|
37
|
+
createElement(
|
|
38
|
+
IApp as any,
|
|
39
|
+
null,
|
|
40
|
+
createElement(
|
|
41
|
+
Switch,
|
|
42
|
+
null,
|
|
43
|
+
routes.map((item) => {
|
|
44
|
+
const { fetch, component, path } = item;
|
|
45
|
+
component.fetch = fetch;
|
|
46
|
+
component.layoutFetch = layoutFetch;
|
|
47
|
+
const WrappedComponent = wrapComponent(component);
|
|
48
|
+
return createElement(Route, {
|
|
49
|
+
exact: true,
|
|
50
|
+
key: path,
|
|
51
|
+
path: path,
|
|
52
|
+
render: (props) =>
|
|
53
|
+
createElement(WrappedComponent, {
|
|
54
|
+
...props,
|
|
55
|
+
key: props.history.location.key,
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
if (window.__USE_SSR__) {
|
|
65
|
+
(hydrateRoot as typeof HydrateRoot)(container, ele);
|
|
66
|
+
} else {
|
|
67
|
+
const root = (createRoot as typeof CreateRoot)(container);
|
|
68
|
+
root.render(ele);
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
71
|
+
if (!window.__USE_VITE__) {
|
|
72
|
+
(module as any)?.hot?.accept?.();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
75
|
|
|
76
|
-
clientRender()
|
|
76
|
+
clientRender();
|
|
77
77
|
|
|
78
|
-
export { clientRender }
|
|
78
|
+
export { clientRender };
|
|
@@ -1,154 +1,205 @@
|
|
|
1
|
-
import type { renderToPipeableStream } from
|
|
2
|
-
import { PassThrough } from
|
|
3
|
-
import * as React from
|
|
4
|
-
import { createElement } from
|
|
5
|
-
import * as ReactDOMServer from
|
|
6
|
-
import { StaticRouter } from
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import type { renderToPipeableStream } from "react-dom18/server";
|
|
2
|
+
import { PassThrough } from "stream";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { createElement } from "react";
|
|
5
|
+
import * as ReactDOMServer from "react-dom/server";
|
|
6
|
+
import { StaticRouter } from "react-router-dom";
|
|
7
|
+
import {
|
|
8
|
+
findRoute,
|
|
9
|
+
getManifest,
|
|
10
|
+
logGreen,
|
|
11
|
+
normalizePath,
|
|
12
|
+
getAsyncCssChunk,
|
|
13
|
+
getAsyncJsChunk,
|
|
14
|
+
splitPageInfo,
|
|
15
|
+
reactRefreshFragment,
|
|
16
|
+
localStorageWrapper,
|
|
17
|
+
checkRoute,
|
|
18
|
+
useStore,
|
|
19
|
+
isReact18,
|
|
20
|
+
getClientEntry,
|
|
21
|
+
} from "ssr-common-utils";
|
|
22
|
+
import { ISSRContext, IConfig, ReactESMPreloadFeRouteItem, DynamicFC, StaticFC } from "ssr-types";
|
|
23
|
+
import { serialize } from "ssr-serialize-javascript";
|
|
24
|
+
import { AppContext } from "./context";
|
|
25
|
+
import { Routes, ssrCreateContext, createStore } from "./create";
|
|
12
26
|
|
|
13
|
-
const { FeRoutes, layoutFetch, state, Layout } = Routes
|
|
27
|
+
const { FeRoutes, layoutFetch, state, Layout } = Routes;
|
|
14
28
|
|
|
15
29
|
type ReactDOMServerType = typeof ReactDOMServer & {
|
|
16
|
-
|
|
17
|
-
}
|
|
30
|
+
renderToPipeableStream: typeof renderToPipeableStream;
|
|
31
|
+
};
|
|
18
32
|
const serverRender = async (ctx: ISSRContext, config: IConfig) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
const context = ssrCreateContext();
|
|
34
|
+
const {
|
|
35
|
+
mode,
|
|
36
|
+
parallelFetch,
|
|
37
|
+
prefix,
|
|
38
|
+
isVite,
|
|
39
|
+
isDev,
|
|
40
|
+
clientPrefix,
|
|
41
|
+
onReady,
|
|
42
|
+
onError,
|
|
43
|
+
stream,
|
|
44
|
+
rootId,
|
|
45
|
+
hashRouter,
|
|
46
|
+
streamHighWaterMark,
|
|
47
|
+
} = config;
|
|
48
|
+
const rawPath = ctx.request.path ?? ctx.request.url;
|
|
49
|
+
const path = normalizePath(rawPath, prefix);
|
|
50
|
+
const routeItem = findRoute<ReactESMPreloadFeRouteItem>(FeRoutes, path);
|
|
51
|
+
checkRoute({ routeItem, path });
|
|
52
|
+
const { fetch, webpackChunkName, component } = routeItem;
|
|
26
53
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
const fn = async () => {
|
|
55
|
+
const dynamicCssOrder = await getAsyncCssChunk(ctx, webpackChunkName, config);
|
|
56
|
+
const dynamicJsOrder = await getAsyncJsChunk(ctx, webpackChunkName, config);
|
|
57
|
+
const manifest = await getManifest(config);
|
|
58
|
+
const injectCss = (
|
|
59
|
+
isVite && isDev
|
|
60
|
+
? [
|
|
61
|
+
<script src="/@vite/client" type="module" key="vite-client" />,
|
|
62
|
+
<script
|
|
63
|
+
key="vite-react-refresh"
|
|
64
|
+
type="module"
|
|
65
|
+
dangerouslySetInnerHTML={{
|
|
66
|
+
__html: reactRefreshFragment,
|
|
67
|
+
}}
|
|
68
|
+
/>,
|
|
69
|
+
]
|
|
70
|
+
: dynamicCssOrder
|
|
71
|
+
.map((css) => manifest[css])
|
|
72
|
+
.filter(Boolean)
|
|
73
|
+
.map((css) => <link rel="stylesheet" key={css} href={css} />)
|
|
74
|
+
).concat(
|
|
75
|
+
isVite && isDev
|
|
76
|
+
? []
|
|
77
|
+
: dynamicJsOrder
|
|
78
|
+
.map((js) => manifest[js])
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.map((js) => (
|
|
81
|
+
<link href={js} as="script" rel={isVite ? "modulepreload" : "preload"} key={js} />
|
|
82
|
+
)),
|
|
83
|
+
);
|
|
55
84
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
const injectScript = [
|
|
86
|
+
...(isVite
|
|
87
|
+
? [
|
|
88
|
+
<script
|
|
89
|
+
key="viteWindowInit"
|
|
90
|
+
dangerouslySetInnerHTML={{
|
|
91
|
+
__html: "window.__USE_VITE__=true",
|
|
92
|
+
}}
|
|
93
|
+
/>,
|
|
94
|
+
]
|
|
95
|
+
: []),
|
|
96
|
+
...(isVite && isDev
|
|
97
|
+
? [
|
|
98
|
+
<script
|
|
99
|
+
type="module"
|
|
100
|
+
src={`/node_modules/ssr-plugin-react/esm/entry/${getClientEntry()}.js`}
|
|
101
|
+
key="vite-react-entry"
|
|
102
|
+
/>,
|
|
103
|
+
]
|
|
104
|
+
: []),
|
|
105
|
+
...dynamicJsOrder
|
|
106
|
+
.map((js) => manifest[js])
|
|
107
|
+
.filter(Boolean)
|
|
108
|
+
.map((item) => (
|
|
109
|
+
<script key={item} src={item} type={isVite ? "module" : "text/javascript"} />
|
|
110
|
+
)),
|
|
111
|
+
];
|
|
112
|
+
const staticList = {
|
|
113
|
+
injectCss,
|
|
114
|
+
injectScript,
|
|
115
|
+
};
|
|
77
116
|
|
|
78
|
-
|
|
79
|
-
|
|
117
|
+
const isCsr = !!(mode === "csr" || ctx.request.query?.csr);
|
|
118
|
+
const Component = isCsr
|
|
119
|
+
? React.Fragment
|
|
120
|
+
: component.name === "dynamicComponent"
|
|
121
|
+
? (await (component as DynamicFC)()).default
|
|
122
|
+
: (component as StaticFC);
|
|
80
123
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
124
|
+
if (isCsr) {
|
|
125
|
+
logGreen(`Current path ${path} use csr render mode`);
|
|
126
|
+
}
|
|
84
127
|
|
|
85
|
-
|
|
128
|
+
let [layoutFetchData, fetchData] = [{}, {}];
|
|
86
129
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
130
|
+
if (!isCsr) {
|
|
131
|
+
const currentFetch = fetch ? (await fetch()).default : null;
|
|
132
|
+
const lF = layoutFetch ? layoutFetch({ ctx }) : Promise.resolve({});
|
|
133
|
+
const CF = currentFetch ? currentFetch({ ctx }) : Promise.resolve({});
|
|
134
|
+
[layoutFetchData, fetchData] = parallelFetch
|
|
135
|
+
? await Promise.all([lF, CF])
|
|
136
|
+
: [await lF, await CF];
|
|
137
|
+
}
|
|
93
138
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
const combineData = isCsr
|
|
140
|
+
? null
|
|
141
|
+
: Object.assign({}, state ?? {}, layoutFetchData ?? {}, fetchData ?? {});
|
|
142
|
+
const ssrDevInfo = { manifest: isDev ? manifest : "", rootId };
|
|
143
|
+
const innerHTML = splitPageInfo({
|
|
144
|
+
"window.__USE_SSR__": !isCsr,
|
|
145
|
+
"window.__INITIAL_DATA__": isCsr ? {} : serialize(combineData),
|
|
146
|
+
"window.__USE_VITE__": isVite,
|
|
147
|
+
"window.prefix": `"${prefix}"`,
|
|
148
|
+
"window.clientPrefix": `"${clientPrefix ?? ""}"`,
|
|
149
|
+
"window.ssrDevInfo": JSON.stringify(ssrDevInfo),
|
|
150
|
+
"window.hashRouter": Boolean(hashRouter),
|
|
151
|
+
"window.__VALTIO_DATA__": isCsr ? {} : serialize(useStore()),
|
|
152
|
+
});
|
|
153
|
+
const injectState = <script dangerouslySetInnerHTML={{ __html: innerHTML }} />;
|
|
154
|
+
// with jsx type error, use createElement here
|
|
155
|
+
const ele = createElement(
|
|
156
|
+
StaticRouter,
|
|
157
|
+
{
|
|
158
|
+
location: ctx.request.url,
|
|
159
|
+
basename: prefix === "/" ? undefined : prefix,
|
|
160
|
+
},
|
|
161
|
+
createElement(AppContext, {
|
|
162
|
+
context: context as any,
|
|
163
|
+
initialState: combineData,
|
|
164
|
+
children: createElement(
|
|
165
|
+
Layout,
|
|
166
|
+
{
|
|
167
|
+
ctx: ctx,
|
|
168
|
+
config: config,
|
|
169
|
+
staticList: staticList,
|
|
170
|
+
injectState: injectState,
|
|
171
|
+
},
|
|
172
|
+
createElement(Component, null),
|
|
173
|
+
),
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
// for ctx.body will loose asynclocalstorage context, consume stream in advance like vue2/3
|
|
177
|
+
if (isReact18()) {
|
|
178
|
+
return stream
|
|
179
|
+
? (ReactDOMServer as ReactDOMServerType)
|
|
180
|
+
.renderToPipeableStream(ele, {
|
|
181
|
+
onAllReady: onReady,
|
|
182
|
+
onError: onError as any,
|
|
183
|
+
})
|
|
184
|
+
.pipe(new PassThrough({ highWaterMark: streamHighWaterMark }))
|
|
185
|
+
: ReactDOMServer.renderToString(ele);
|
|
186
|
+
} else {
|
|
187
|
+
return stream
|
|
188
|
+
? ReactDOMServer.renderToNodeStream(ele).pipe(
|
|
189
|
+
new PassThrough({ highWaterMark: streamHighWaterMark }),
|
|
190
|
+
)
|
|
191
|
+
: ReactDOMServer.renderToString(ele);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
143
194
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
195
|
+
return await localStorageWrapper.run(
|
|
196
|
+
{
|
|
197
|
+
context: context as any,
|
|
198
|
+
ctx,
|
|
199
|
+
store: createStore(),
|
|
200
|
+
},
|
|
201
|
+
fn,
|
|
202
|
+
);
|
|
203
|
+
};
|
|
153
204
|
|
|
154
|
-
export { serverRender, Routes }
|
|
205
|
+
export { serverRender, Routes };
|
package/src/index.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { resolve } from
|
|
2
|
-
import { loadConfig, getCwd } from
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { loadConfig, getCwd } from "ssr-common-utils";
|
|
3
3
|
|
|
4
|
-
const { tool } = loadConfig()
|
|
4
|
+
const { tool } = loadConfig();
|
|
5
5
|
|
|
6
6
|
export function clientPlugin() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
7
|
+
const cwd = getCwd();
|
|
8
|
+
const webpackPath = resolve(cwd, "./node_modules/ssr-webpack");
|
|
9
|
+
const vitePath = resolve(cwd, "./node_modules/ssr-vite");
|
|
10
|
+
const rspackPath = resolve(cwd, "./node_modules/ssr-rspack");
|
|
11
|
+
return {
|
|
12
|
+
name: "plugin-react",
|
|
13
|
+
start: async () => {
|
|
14
|
+
if (tool === "vite") {
|
|
15
|
+
const { start } = await import(vitePath);
|
|
16
|
+
await start();
|
|
17
|
+
} else {
|
|
18
|
+
if (tool === "rspack") {
|
|
19
|
+
const { start } = await import(rspackPath);
|
|
20
|
+
await start();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const { start } = await import(webpackPath);
|
|
24
|
+
await start();
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
build: async () => {
|
|
28
|
+
if (tool === "vite") {
|
|
29
|
+
const { build } = await import(vitePath);
|
|
30
|
+
await build();
|
|
31
|
+
} else {
|
|
32
|
+
if (tool === "rspack") {
|
|
33
|
+
const { build } = await import(rspackPath);
|
|
34
|
+
await build();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { build } = await import(webpackPath);
|
|
38
|
+
await build();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
42
|
}
|
package/tsconfig.cjs.json
CHANGED