ssr-plugin-react 6.1.15 → 6.1.19
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 +47 -0
- package/README.md +5 -2
- package/cjs/entry/server-entry.js +3 -2
- package/cjs/tools/vite.js +19 -5
- package/esm/entry/server-entry.js +3 -2
- package/esm/tools/vite.js +19 -5
- package/package.json +7 -7
- package/src/config/server.ts +1 -1
- package/src/entry/server-entry.tsx +2 -2
- package/src/tools/vite.ts +18 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,53 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.1.19](https://github.com/zhangyuang/ssr/compare/v6.1.18...v6.1.19) (2021-12-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package ssr-plugin-react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [6.1.18](https://github.com/zhangyuang/ssr/compare/v6.1.17...v6.1.18) (2021-12-07)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* add viteConfig ([ee86006](https://github.com/zhangyuang/ssr/commit/ee8600688b832b36089128e18f63a4cc8d630a25))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [6.1.17](https://github.com/zhangyuang/ssr/compare/v6.1.15...v6.1.17) (2021-12-07)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* add keepNames when esbuild compile plugin-react jsxRuntime use classic ([8502e6c](https://github.com/zhangyuang/ssr/commit/8502e6ca898fd99e936e60af2093fb6b174f6aab))
|
|
31
|
+
* component evaluating in csr mode ([#138](https://github.com/zhangyuang/ssr/issues/138)) ([66f5f09](https://github.com/zhangyuang/ssr/commit/66f5f09963502588bd59a09ff839d1dae8947817))
|
|
32
|
+
* plugin-react csr ([572c6c0](https://github.com/zhangyuang/ssr/commit/572c6c092c63c915da15883e1d34ad26a5a6cadd))
|
|
33
|
+
* plugin-react csr ([ab51062](https://github.com/zhangyuang/ssr/commit/ab510626946234de436a55184937d018c8c0e514))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## [6.1.16](https://github.com/zhangyuang/ssr/compare/v6.1.15...v6.1.16) (2021-12-06)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* add keepNames when esbuild compile plugin-react jsxRuntime use classic ([8502e6c](https://github.com/zhangyuang/ssr/commit/8502e6ca898fd99e936e60af2093fb6b174f6aab))
|
|
45
|
+
* component evaluating in csr mode ([#138](https://github.com/zhangyuang/ssr/issues/138)) ([66f5f09](https://github.com/zhangyuang/ssr/commit/66f5f09963502588bd59a09ff839d1dae8947817))
|
|
46
|
+
* plugin-react csr ([572c6c0](https://github.com/zhangyuang/ssr/commit/572c6c092c63c915da15883e1d34ad26a5a6cadd))
|
|
47
|
+
* plugin-react csr ([ab51062](https://github.com/zhangyuang/ssr/commit/ab510626946234de436a55184937d018c8c0e514))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
6
53
|
## [6.1.15](https://github.com/zhangyuang/ssr/compare/v6.1.14...v6.1.15) (2021-12-05)
|
|
7
54
|
|
|
8
55
|
**Note:** Version bump only for package ssr-plugin-react
|
package/README.md
CHANGED
|
@@ -107,13 +107,16 @@
|
|
|
107
107
|
<a href="https://jiawu.dewu.com" target="_bvlank"><b>得物
|
|
108
108
|
</b></a></td>
|
|
109
109
|
<td align="center" style="height: 100px"><a href="https://www.habisummercamp.com/" target="_blank"><img src="https://res.wx.qq.com/op_res/XXUpF56bDue53vZadoCSPSnqKF3bZqPOQnqsPa_ngEARa0OUIW22pX7eKsftPb6pc5ny62cR_wXM4g5xJ7G3DQ
|
|
110
|
-
" width="200px;margin: 20px 0" alt="
|
|
110
|
+
" width="200px;margin: 20px 0" alt="Happy"/><br />
|
|
111
111
|
<a href="https://www.habisummercamp.com/" target="_bvlank"><b>HappyPC
|
|
112
112
|
</b></a></td>
|
|
113
113
|
<td align="center" style="height: 100px"><a href="https://m.habisummercamp.com/" target="_blank"><img src="https://res.wx.qq.com/op_res/XXUpF56bDue53vZadoCSPSnqKF3bZqPOQnqsPa_ngEARa0OUIW22pX7eKsftPb6pc5ny62cR_wXM4g5xJ7G3DQ
|
|
114
|
-
" width="200px;margin: 20px 0" alt="
|
|
114
|
+
" width="200px;margin: 20px 0" alt="Happy"/><br />
|
|
115
115
|
<a href="https://m.habisummercamp.com/" target="_bvlank"><b>HappyMobile
|
|
116
116
|
</b></a></td>
|
|
117
|
+
<td align="center" style="height: 100px"><a href="https://www.paixin.com/" target="_blank"><img src="https://www.paixin.com/favicon.ico" width="200px;margin: 20px 0" alt="Happy"/><br />
|
|
118
|
+
<a href="https://www.paixin.com/" target="_bvlank"><b>拍信创意
|
|
119
|
+
</b></a></td>
|
|
117
120
|
</tr>
|
|
118
121
|
</table>
|
|
119
122
|
|
|
@@ -74,7 +74,7 @@ const serverRender = async (ctx, config) => {
|
|
|
74
74
|
};
|
|
75
75
|
const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
|
|
76
76
|
const { component, fetch } = routeItem;
|
|
77
|
-
const Component = (await component()).default;
|
|
77
|
+
const Component = isCsr ? React.Fragment : (await component()).default;
|
|
78
78
|
if (isCsr) {
|
|
79
79
|
(0, ssr_server_utils_1.logGreen)(`Current path ${path} use csr render mode`);
|
|
80
80
|
}
|
|
@@ -100,6 +100,7 @@ const serverRender = async (ctx, config) => {
|
|
|
100
100
|
} });
|
|
101
101
|
return (React.createElement(react_router_dom_1.StaticRouter, { location: ctx.request.url },
|
|
102
102
|
React.createElement(create_context_1.STORE_CONTEXT.Provider, { value: { state: combineData } },
|
|
103
|
-
React.createElement(index_tsx_1.default, { ctx: ctx, config: config, staticList: staticList, injectState: injectState },
|
|
103
|
+
React.createElement(index_tsx_1.default, { ctx: ctx, config: config, staticList: staticList, injectState: injectState },
|
|
104
|
+
React.createElement(Component, null)))));
|
|
104
105
|
};
|
|
105
106
|
exports.serverRender = serverRender;
|
package/cjs/tools/vite.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.clientConfig = exports.serverConfig = exports.viteStart = exports.viteBuild = void 0;
|
|
4
5
|
const ssr_server_utils_1 = require("ssr-server-utils");
|
|
5
6
|
const plugin_react_1 = require("@vitejs/plugin-react");
|
|
6
7
|
const build = require('vite').build;
|
|
7
|
-
const { getOutput, reactServerEntry, reactClientEntry } = (0, ssr_server_utils_1.loadConfig)();
|
|
8
|
+
const { getOutput, reactServerEntry, reactClientEntry, viteConfig } = (0, ssr_server_utils_1.loadConfig)();
|
|
8
9
|
const { clientOutPut, serverOutPut } = getOutput();
|
|
9
10
|
const serverConfig = {
|
|
10
11
|
...(0, ssr_server_utils_1.commonConfig)(),
|
|
11
12
|
plugins: [
|
|
12
|
-
(0, plugin_react_1.default)(
|
|
13
|
+
(0, plugin_react_1.default)({
|
|
14
|
+
...(_b = (_a = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.defaultPluginOptions,
|
|
15
|
+
jsxRuntime: 'classic'
|
|
16
|
+
}),
|
|
17
|
+
(_d = (_c = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.extraPlugin
|
|
13
18
|
],
|
|
14
19
|
build: {
|
|
15
20
|
ssr: reactServerEntry,
|
|
@@ -21,14 +26,22 @@ const serverConfig = {
|
|
|
21
26
|
}
|
|
22
27
|
},
|
|
23
28
|
define: {
|
|
24
|
-
__isBrowser__: false
|
|
29
|
+
__isBrowser__: false,
|
|
30
|
+
...(_f = (_e = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _e === void 0 ? void 0 : _e.server) === null || _f === void 0 ? void 0 : _f.define
|
|
25
31
|
}
|
|
26
32
|
};
|
|
27
33
|
exports.serverConfig = serverConfig;
|
|
28
34
|
const clientConfig = {
|
|
29
35
|
...(0, ssr_server_utils_1.commonConfig)(),
|
|
36
|
+
esbuild: {
|
|
37
|
+
keepNames: true
|
|
38
|
+
},
|
|
30
39
|
plugins: [
|
|
31
|
-
(0, plugin_react_1.default)(
|
|
40
|
+
(0, plugin_react_1.default)({
|
|
41
|
+
...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.client) === null || _h === void 0 ? void 0 : _h.defaultPluginOptions,
|
|
42
|
+
jsxRuntime: 'classic'
|
|
43
|
+
}),
|
|
44
|
+
(_k = (_j = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _j === void 0 ? void 0 : _j.client) === null || _k === void 0 ? void 0 : _k.extraPlugin
|
|
32
45
|
],
|
|
33
46
|
build: {
|
|
34
47
|
ssrManifest: true,
|
|
@@ -40,7 +53,8 @@ const clientConfig = {
|
|
|
40
53
|
}
|
|
41
54
|
},
|
|
42
55
|
define: {
|
|
43
|
-
__isBrowser__: true
|
|
56
|
+
__isBrowser__: true,
|
|
57
|
+
...(_m = (_l = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _l === void 0 ? void 0 : _l.client) === null || _m === void 0 ? void 0 : _m.define
|
|
44
58
|
}
|
|
45
59
|
};
|
|
46
60
|
exports.clientConfig = clientConfig;
|
|
@@ -71,7 +71,7 @@ const serverRender = async (ctx, config) => {
|
|
|
71
71
|
};
|
|
72
72
|
const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
|
|
73
73
|
const { component, fetch } = routeItem;
|
|
74
|
-
const Component = (await component()).default;
|
|
74
|
+
const Component = isCsr ? React.Fragment : (await component()).default;
|
|
75
75
|
if (isCsr) {
|
|
76
76
|
logGreen(`Current path ${path} use csr render mode`);
|
|
77
77
|
}
|
|
@@ -97,6 +97,7 @@ const serverRender = async (ctx, config) => {
|
|
|
97
97
|
} });
|
|
98
98
|
return (React.createElement(StaticRouter, { location: ctx.request.url },
|
|
99
99
|
React.createElement(Context.Provider, { value: { state: combineData } },
|
|
100
|
-
React.createElement(Layout, { ctx: ctx, config: config, staticList: staticList, injectState: injectState },
|
|
100
|
+
React.createElement(Layout, { ctx: ctx, config: config, staticList: staticList, injectState: injectState },
|
|
101
|
+
React.createElement(Component, null)))));
|
|
101
102
|
};
|
|
102
103
|
export { serverRender };
|
package/esm/tools/vite.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1
2
|
import { loadConfig, chunkNamePlugin, output, manifestPlugin, commonConfig } from 'ssr-server-utils';
|
|
2
3
|
import react from '@vitejs/plugin-react';
|
|
3
4
|
const build = require('vite').build;
|
|
4
|
-
const { getOutput, reactServerEntry, reactClientEntry } = loadConfig();
|
|
5
|
+
const { getOutput, reactServerEntry, reactClientEntry, viteConfig } = loadConfig();
|
|
5
6
|
const { clientOutPut, serverOutPut } = getOutput();
|
|
6
7
|
const serverConfig = {
|
|
7
8
|
...commonConfig(),
|
|
8
9
|
plugins: [
|
|
9
|
-
react(
|
|
10
|
+
react({
|
|
11
|
+
...(_b = (_a = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.defaultPluginOptions,
|
|
12
|
+
jsxRuntime: 'classic'
|
|
13
|
+
}),
|
|
14
|
+
(_d = (_c = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.extraPlugin
|
|
10
15
|
],
|
|
11
16
|
build: {
|
|
12
17
|
ssr: reactServerEntry,
|
|
@@ -18,13 +23,21 @@ const serverConfig = {
|
|
|
18
23
|
}
|
|
19
24
|
},
|
|
20
25
|
define: {
|
|
21
|
-
__isBrowser__: false
|
|
26
|
+
__isBrowser__: false,
|
|
27
|
+
...(_f = (_e = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _e === void 0 ? void 0 : _e.server) === null || _f === void 0 ? void 0 : _f.define
|
|
22
28
|
}
|
|
23
29
|
};
|
|
24
30
|
const clientConfig = {
|
|
25
31
|
...commonConfig(),
|
|
32
|
+
esbuild: {
|
|
33
|
+
keepNames: true
|
|
34
|
+
},
|
|
26
35
|
plugins: [
|
|
27
|
-
react(
|
|
36
|
+
react({
|
|
37
|
+
...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.client) === null || _h === void 0 ? void 0 : _h.defaultPluginOptions,
|
|
38
|
+
jsxRuntime: 'classic'
|
|
39
|
+
}),
|
|
40
|
+
(_k = (_j = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _j === void 0 ? void 0 : _j.client) === null || _k === void 0 ? void 0 : _k.extraPlugin
|
|
28
41
|
],
|
|
29
42
|
build: {
|
|
30
43
|
ssrManifest: true,
|
|
@@ -36,7 +49,8 @@ const clientConfig = {
|
|
|
36
49
|
}
|
|
37
50
|
},
|
|
38
51
|
define: {
|
|
39
|
-
__isBrowser__: true
|
|
52
|
+
__isBrowser__: true,
|
|
53
|
+
...(_m = (_l = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _l === void 0 ? void 0 : _l.client) === null || _m === void 0 ? void 0 : _m.define
|
|
40
54
|
}
|
|
41
55
|
};
|
|
42
56
|
const viteStart = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssr-plugin-react",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.19",
|
|
4
4
|
"description": "plugin-react for ssr",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"postcss-safe-parser": "4.0.1",
|
|
55
55
|
"react-dev-utils": "^11.0.4",
|
|
56
56
|
"serialize-javascript": "^6.0.0",
|
|
57
|
-
"ssr-client-utils": "^6.1.
|
|
58
|
-
"ssr-hoc-react": "^6.1.
|
|
59
|
-
"ssr-server-utils": "^6.1.
|
|
60
|
-
"ssr-webpack": "^6.1.
|
|
57
|
+
"ssr-client-utils": "^6.1.18",
|
|
58
|
+
"ssr-hoc-react": "^6.1.18",
|
|
59
|
+
"ssr-server-utils": "^6.1.19",
|
|
60
|
+
"ssr-webpack": "^6.1.19",
|
|
61
61
|
"terser-webpack-plugin": "^2.3.5",
|
|
62
62
|
"url-loader": "^4.1.1",
|
|
63
63
|
"vite": "^2.7.0-beta.10",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/react-dom": "^17.0.0",
|
|
72
72
|
"@types/react-router-dom": "^5.1.3",
|
|
73
73
|
"@types/webpack": "^4.41.10",
|
|
74
|
-
"ssr-types-react": "^6.1.
|
|
74
|
+
"ssr-types-react": "^6.1.18"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "698a18c1ed0ebd7d449cde88aaff86b17036ee3c"
|
|
77
77
|
}
|
package/src/config/server.ts
CHANGED
|
@@ -23,7 +23,7 @@ const getServerWebpack = (chain: WebpackChain) => {
|
|
|
23
23
|
const modulesDir = [join(cwd, './node_modules')]
|
|
24
24
|
modulesDir.push(getLocalNodeModules())
|
|
25
25
|
chain.externals(nodeExternals({
|
|
26
|
-
whitelist: [/\.(css|less|sass|scss)$/, /antd.*?(style)/].concat(whiteList || []),
|
|
26
|
+
whitelist: [/\.(css|less|sass|scss)$/, /antd.*?(style)/].concat(whiteList as RegExp[] || []),
|
|
27
27
|
// externals Dir contains example/xxx/node_modules ssr/node_modules
|
|
28
28
|
modulesDir
|
|
29
29
|
}))
|
|
@@ -80,7 +80,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
|
|
|
80
80
|
|
|
81
81
|
const isCsr = !!(mode === 'csr' || ctx.request.query?.csr)
|
|
82
82
|
const { component, fetch } = routeItem
|
|
83
|
-
const Component = (await component()).default
|
|
83
|
+
const Component = isCsr ? React.Fragment : (await component()).default
|
|
84
84
|
|
|
85
85
|
if (isCsr) {
|
|
86
86
|
logGreen(`Current path ${path} use csr render mode`)
|
|
@@ -111,7 +111,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
|
|
|
111
111
|
<StaticRouter location={ctx.request.url}>
|
|
112
112
|
<Context.Provider value={{ state: combineData }}>
|
|
113
113
|
<Layout ctx={ctx} config={config} staticList={staticList} injectState={injectState}>
|
|
114
|
-
|
|
114
|
+
<Component />
|
|
115
115
|
</Layout>
|
|
116
116
|
</Context.Provider>
|
|
117
117
|
</StaticRouter>
|
package/src/tools/vite.ts
CHANGED
|
@@ -2,13 +2,17 @@ import type { build as BuildType, UserConfig } from 'vite'
|
|
|
2
2
|
import { loadConfig, chunkNamePlugin, output, manifestPlugin, commonConfig } from 'ssr-server-utils'
|
|
3
3
|
import react from '@vitejs/plugin-react'
|
|
4
4
|
const build: typeof BuildType = require('vite').build
|
|
5
|
-
const { getOutput, reactServerEntry, reactClientEntry } = loadConfig()
|
|
5
|
+
const { getOutput, reactServerEntry, reactClientEntry, viteConfig } = loadConfig()
|
|
6
6
|
const { clientOutPut, serverOutPut } = getOutput()
|
|
7
7
|
|
|
8
8
|
const serverConfig: UserConfig = {
|
|
9
9
|
...commonConfig(),
|
|
10
10
|
plugins: [
|
|
11
|
-
react(
|
|
11
|
+
react({
|
|
12
|
+
...viteConfig?.()?.server?.defaultPluginOptions,
|
|
13
|
+
jsxRuntime: 'classic'
|
|
14
|
+
}),
|
|
15
|
+
viteConfig?.()?.server?.extraPlugin
|
|
12
16
|
],
|
|
13
17
|
build: {
|
|
14
18
|
ssr: reactServerEntry,
|
|
@@ -20,14 +24,22 @@ const serverConfig: UserConfig = {
|
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
define: {
|
|
23
|
-
__isBrowser__: false
|
|
27
|
+
__isBrowser__: false,
|
|
28
|
+
...viteConfig?.()?.server?.define
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
const clientConfig: UserConfig = {
|
|
28
33
|
...commonConfig(),
|
|
34
|
+
esbuild: {
|
|
35
|
+
keepNames: true
|
|
36
|
+
},
|
|
29
37
|
plugins: [
|
|
30
|
-
react(
|
|
38
|
+
react({
|
|
39
|
+
...viteConfig?.()?.client?.defaultPluginOptions,
|
|
40
|
+
jsxRuntime: 'classic'
|
|
41
|
+
}),
|
|
42
|
+
viteConfig?.()?.client?.extraPlugin
|
|
31
43
|
],
|
|
32
44
|
build: {
|
|
33
45
|
ssrManifest: true,
|
|
@@ -39,7 +51,8 @@ const clientConfig: UserConfig = {
|
|
|
39
51
|
}
|
|
40
52
|
},
|
|
41
53
|
define: {
|
|
42
|
-
__isBrowser__: true
|
|
54
|
+
__isBrowser__: true,
|
|
55
|
+
...viteConfig?.()?.client?.define
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
const viteStart = async () => {
|