@modern-js/runtime 2.23.1 → 2.24.1
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 +26 -0
- package/dist/cjs/router/cli/index.js +2 -2
- package/dist/cjs/ssr/cli/index.js +8 -4
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +21 -13
- package/dist/cjs/ssr/utils.js +0 -12
- package/dist/cjs/state/cli/index.js +2 -2
- package/dist/esm/router/cli/index.js +2 -2
- package/dist/esm/ssr/cli/index.js +9 -5
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +18 -10
- package/dist/esm/ssr/utils.js +0 -10
- package/dist/esm/state/cli/index.js +2 -2
- package/dist/esm-node/router/cli/index.js +2 -2
- package/dist/esm-node/ssr/cli/index.js +8 -4
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +18 -10
- package/dist/esm-node/ssr/utils.js +0 -9
- package/dist/esm-node/state/cli/index.js +2 -2
- package/dist/types/ssr/serverRender/types.d.ts +1 -0
- package/dist/types/ssr/utils.d.ts +1 -2
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 2.24.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 13354d3356: fix(runtime): ssr link tag add attrs error
|
|
8
|
+
fix(runtime): ssr link 标签添加错误的属性
|
|
9
|
+
- @modern-js/plugin@2.24.1
|
|
10
|
+
- @modern-js/types@2.24.1
|
|
11
|
+
- @modern-js/utils@2.24.1
|
|
12
|
+
|
|
13
|
+
## 2.24.0
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- c882fbd: feat: support config main entry name
|
|
18
|
+
|
|
19
|
+
feat: 支持配置主入口名称
|
|
20
|
+
|
|
21
|
+
- 56693a3: fix(plugin-ssr): ssr script、link should add some attrs, like ["defer", "crossorigin"]
|
|
22
|
+
fix(plugin-ssr): ssr script,link 标签应该添加像 ["defer", "crossorigin"] 属性
|
|
23
|
+
- Updated dependencies [c882fbd]
|
|
24
|
+
- Updated dependencies [4a82c3b]
|
|
25
|
+
- @modern-js/types@2.24.0
|
|
26
|
+
- @modern-js/utils@2.24.0
|
|
27
|
+
- @modern-js/plugin@2.24.0
|
|
28
|
+
|
|
3
29
|
## 2.23.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -54,10 +54,10 @@ const _default = () => {
|
|
|
54
54
|
];
|
|
55
55
|
},
|
|
56
56
|
modifyEntryImports({ entrypoint, imports }) {
|
|
57
|
-
const { entryName, fileSystemRoutes } = entrypoint;
|
|
57
|
+
const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
|
|
58
58
|
const userConfig = api.useResolvedConfigContext();
|
|
59
59
|
const { packageName } = api.useAppContext();
|
|
60
|
-
const runtimeConfig = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
60
|
+
const runtimeConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
61
61
|
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
62
62
|
if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
|
|
63
63
|
if (!(0, _utils.isRouterV5)(userConfig)) {
|
|
@@ -93,14 +93,14 @@ const _default = () => {
|
|
|
93
93
|
};
|
|
94
94
|
},
|
|
95
95
|
modifyEntryImports({ entrypoint, imports }) {
|
|
96
|
-
const { entryName, fileSystemRoutes } = entrypoint;
|
|
96
|
+
const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
|
|
97
97
|
const userConfig = api.useResolvedConfigContext();
|
|
98
98
|
const { packageName, entrypoints } = api.useAppContext();
|
|
99
99
|
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
|
|
100
|
-
const ssrConfig = (0, _utils.getEntryOptions)(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
100
|
+
const ssrConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
101
101
|
if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
|
|
102
102
|
var _ref;
|
|
103
|
-
const runtimeConfig = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
103
|
+
const runtimeConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
104
104
|
if (((_ref = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _ref === void 0 ? void 0 : _ref.mode) === "react-router-5") {
|
|
105
105
|
throw new Error(`router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'`);
|
|
106
106
|
}
|
|
@@ -128,11 +128,15 @@ const _default = () => {
|
|
|
128
128
|
modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
|
|
129
129
|
if (ssrConfigMap.get(entrypoint.entryName)) {
|
|
130
130
|
var _bundlerConfigs_find, _bundlerConfigs_find_output;
|
|
131
|
-
const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((
|
|
131
|
+
const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
|
|
132
|
+
const config = api.useResolvedConfigContext();
|
|
133
|
+
const { crossorigin, scriptLoading } = config.html;
|
|
132
134
|
plugins.push({
|
|
133
135
|
name: PLUGIN_IDENTIFIER,
|
|
134
136
|
options: JSON.stringify({
|
|
135
137
|
...ssrConfigMap.get(entrypoint.entryName) || {},
|
|
138
|
+
crossorigin,
|
|
139
|
+
scriptLoading,
|
|
136
140
|
chunkLoadingGlobal
|
|
137
141
|
})
|
|
138
142
|
});
|
|
@@ -9,8 +9,7 @@ Object.defineProperty(exports, "toHtml", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _server = require("@loadable/server");
|
|
12
|
-
const _utils = require("
|
|
13
|
-
const _utils1 = require("../utils");
|
|
12
|
+
const _utils = require("../utils");
|
|
14
13
|
const extname = (uri) => {
|
|
15
14
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
16
15
|
return "";
|
|
@@ -18,7 +17,7 @@ const extname = (uri) => {
|
|
|
18
17
|
return `.${uri === null || uri === void 0 ? void 0 : uri.split(".").pop()}` || "";
|
|
19
18
|
};
|
|
20
19
|
const toHtml = (jsx, renderer, next) => {
|
|
21
|
-
const { stats, result: { chunksMap },
|
|
20
|
+
const { stats, result: { chunksMap }, config = {}, nonce } = renderer;
|
|
22
21
|
if (!stats || chunksMap.js) {
|
|
23
22
|
return next(jsx);
|
|
24
23
|
}
|
|
@@ -30,21 +29,30 @@ const toHtml = (jsx, renderer, next) => {
|
|
|
30
29
|
});
|
|
31
30
|
const html = next(extractor.collectChunks(jsx));
|
|
32
31
|
const chunks = extractor.getChunkAssets(extractor.chunks);
|
|
33
|
-
chunksMap.js = (chunksMap.js || "") + (0,
|
|
32
|
+
chunksMap.js = (chunksMap.js || "") + (0, _utils.getLoadableScripts)(extractor);
|
|
34
33
|
for (const v of chunks) {
|
|
35
34
|
const fileType = extname(v.url).slice(1);
|
|
35
|
+
const attributes = {};
|
|
36
|
+
const { crossorigin, scriptLoading = "defer" } = config;
|
|
37
|
+
if (crossorigin) {
|
|
38
|
+
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
39
|
+
}
|
|
40
|
+
switch (scriptLoading) {
|
|
41
|
+
case "defer":
|
|
42
|
+
attributes.defer = true;
|
|
43
|
+
break;
|
|
44
|
+
case "module":
|
|
45
|
+
attributes.type = "module";
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
}
|
|
36
49
|
if (fileType === "js") {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
const { crossorigin } = config;
|
|
41
|
-
if (crossorigin && (0, _utils.isCrossOrigin)(v.url, host)) {
|
|
42
|
-
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
43
|
-
}
|
|
44
|
-
const attrsStr = (0, _utils1.attributesToString)(attributes);
|
|
50
|
+
attributes.nonce = nonce;
|
|
51
|
+
const attrsStr = (0, _utils.attributesToString)(attributes);
|
|
45
52
|
chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
|
|
46
53
|
} else if (fileType === "css") {
|
|
47
|
-
|
|
54
|
+
const attrsStr = (0, _utils.attributesToString)(attributes);
|
|
55
|
+
chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
return html;
|
package/dist/cjs/ssr/utils.js
CHANGED
|
@@ -21,9 +21,6 @@ _export(exports, {
|
|
|
21
21
|
},
|
|
22
22
|
mockResponse: function() {
|
|
23
23
|
return mockResponse;
|
|
24
|
-
},
|
|
25
|
-
isCrossOrigin: function() {
|
|
26
|
-
return isCrossOrigin;
|
|
27
24
|
}
|
|
28
25
|
});
|
|
29
26
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
@@ -75,12 +72,3 @@ const mockResponse = () => {
|
|
|
75
72
|
}
|
|
76
73
|
};
|
|
77
74
|
};
|
|
78
|
-
const isCrossOrigin = (url = "", base) => {
|
|
79
|
-
if (url.startsWith("/") || url.startsWith("./")) {
|
|
80
|
-
return false;
|
|
81
|
-
} else if (!url.includes(base)) {
|
|
82
|
-
return true;
|
|
83
|
-
} else {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
@@ -33,10 +33,10 @@ const _default = () => {
|
|
|
33
33
|
},
|
|
34
34
|
modifyEntryImports({ entrypoint, imports }) {
|
|
35
35
|
var _getEntryOptions;
|
|
36
|
-
const { entryName } = entrypoint;
|
|
36
|
+
const { entryName, isMainEntry } = entrypoint;
|
|
37
37
|
const userConfig = api.useResolvedConfigContext();
|
|
38
38
|
const { packageName } = api.useAppContext();
|
|
39
|
-
const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
39
|
+
const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
40
40
|
stateConfigMap.set(entryName, stateConfig);
|
|
41
41
|
if (stateConfig) {
|
|
42
42
|
imports.push({
|
|
@@ -47,10 +47,10 @@ export default function() {
|
|
|
47
47
|
},
|
|
48
48
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
49
49
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
50
|
-
var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
50
|
+
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
51
51
|
var userConfig = api.useResolvedConfigContext();
|
|
52
52
|
var packageName = api.useAppContext().packageName;
|
|
53
|
-
var runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
53
|
+
var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
54
54
|
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
55
55
|
if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
|
|
56
56
|
if (!isV5(userConfig)) {
|
|
@@ -106,14 +106,14 @@ export default function() {
|
|
|
106
106
|
},
|
|
107
107
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
108
108
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
109
|
-
var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
109
|
+
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
110
110
|
var userConfig = api.useResolvedConfigContext();
|
|
111
111
|
var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, entrypoints = _api_useAppContext.entrypoints;
|
|
112
112
|
pluginsExportsUtils.addExport("export { default as ssr } from '@modern-js/runtime/ssr'");
|
|
113
|
-
var ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
113
|
+
var ssrConfig = getEntryOptions(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
114
114
|
if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
|
|
115
115
|
var _ref;
|
|
116
|
-
var runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
116
|
+
var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
117
117
|
if (((_ref = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _ref === void 0 ? void 0 : _ref.mode) === "react-router-5") {
|
|
118
118
|
throw new Error("router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'");
|
|
119
119
|
}
|
|
@@ -142,12 +142,16 @@ export default function() {
|
|
|
142
142
|
var entrypoint = param.entrypoint, plugins = param.plugins, bundlerConfigs = param.bundlerConfigs;
|
|
143
143
|
if (ssrConfigMap.get(entrypoint.entryName)) {
|
|
144
144
|
var _bundlerConfigs_find, _bundlerConfigs_find_output;
|
|
145
|
-
var chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find(function(
|
|
146
|
-
return
|
|
145
|
+
var chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find(function(config2) {
|
|
146
|
+
return config2.name === "client";
|
|
147
147
|
})) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
|
|
148
|
+
var config = api.useResolvedConfigContext();
|
|
149
|
+
var _config_html = config.html, crossorigin = _config_html.crossorigin, scriptLoading = _config_html.scriptLoading;
|
|
148
150
|
plugins.push({
|
|
149
151
|
name: PLUGIN_IDENTIFIER,
|
|
150
152
|
options: JSON.stringify(_object_spread_props(_object_spread({}, ssrConfigMap.get(entrypoint.entryName) || {}), {
|
|
153
|
+
crossorigin: crossorigin,
|
|
154
|
+
scriptLoading: scriptLoading,
|
|
151
155
|
chunkLoadingGlobal: chunkLoadingGlobal
|
|
152
156
|
}))
|
|
153
157
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ChunkExtractor } from "@loadable/server";
|
|
2
|
-
import { isCrossOrigin } from "../../utils";
|
|
3
2
|
import { attributesToString, getLoadableScripts } from "../utils";
|
|
4
3
|
var extname = function(uri) {
|
|
5
4
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
@@ -8,7 +7,7 @@ var extname = function(uri) {
|
|
|
8
7
|
return ".".concat(uri === null || uri === void 0 ? void 0 : uri.split(".").pop()) || "";
|
|
9
8
|
};
|
|
10
9
|
export var toHtml = function(jsx, renderer, next) {
|
|
11
|
-
var stats = renderer.stats, chunksMap = renderer.result.chunksMap,
|
|
10
|
+
var stats = renderer.stats, chunksMap = renderer.result.chunksMap, _renderer_config = renderer.config, config = _renderer_config === void 0 ? {} : _renderer_config, nonce = renderer.nonce;
|
|
12
11
|
if (!stats || chunksMap.js) {
|
|
13
12
|
return next(jsx);
|
|
14
13
|
}
|
|
@@ -26,18 +25,27 @@ export var toHtml = function(jsx, renderer, next) {
|
|
|
26
25
|
for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
27
26
|
var v = _step.value;
|
|
28
27
|
var fileType = extname(v.url).slice(1);
|
|
28
|
+
var attributes = {};
|
|
29
|
+
var crossorigin = config.crossorigin, _config_scriptLoading = config.scriptLoading, scriptLoading = _config_scriptLoading === void 0 ? "defer" : _config_scriptLoading;
|
|
30
|
+
if (crossorigin) {
|
|
31
|
+
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
32
|
+
}
|
|
33
|
+
switch (scriptLoading) {
|
|
34
|
+
case "defer":
|
|
35
|
+
attributes.defer = true;
|
|
36
|
+
break;
|
|
37
|
+
case "module":
|
|
38
|
+
attributes.type = "module";
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
}
|
|
29
42
|
if (fileType === "js") {
|
|
30
|
-
|
|
31
|
-
nonce: nonce
|
|
32
|
-
};
|
|
33
|
-
var crossorigin = config.crossorigin;
|
|
34
|
-
if (crossorigin && isCrossOrigin(v.url, host)) {
|
|
35
|
-
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
36
|
-
}
|
|
43
|
+
attributes.nonce = nonce;
|
|
37
44
|
var attrsStr = attributesToString(attributes);
|
|
38
45
|
chunksMap[fileType] += "<script".concat(attrsStr, ' src="').concat(v.url, '"></script>');
|
|
39
46
|
} else if (fileType === "css") {
|
|
40
|
-
|
|
47
|
+
var attrsStr1 = attributesToString(attributes);
|
|
48
|
+
chunksMap[fileType] += "<link".concat(attrsStr1, ' href="').concat(v.url, '" rel="stylesheet" />');
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
} catch (err) {
|
package/dist/esm/ssr/utils.js
CHANGED
|
@@ -51,13 +51,3 @@ export var mockResponse = function() {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
|
-
export var isCrossOrigin = function() {
|
|
55
|
-
var url = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", base = arguments.length > 1 ? arguments[1] : void 0;
|
|
56
|
-
if (url.startsWith("/") || url.startsWith("./")) {
|
|
57
|
-
return false;
|
|
58
|
-
} else if (!url.includes(base)) {
|
|
59
|
-
return true;
|
|
60
|
-
} else {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
@@ -24,10 +24,10 @@ export default function() {
|
|
|
24
24
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
25
25
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
26
26
|
var _getEntryOptions;
|
|
27
|
-
var entryName = entrypoint.entryName;
|
|
27
|
+
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
|
|
28
28
|
var userConfig = api.useResolvedConfigContext();
|
|
29
29
|
var packageName = api.useAppContext().packageName;
|
|
30
|
-
var stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
30
|
+
var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
31
31
|
stateConfigMap.set(entryName, stateConfig);
|
|
32
32
|
if (stateConfig) {
|
|
33
33
|
imports.push({
|
|
@@ -44,10 +44,10 @@ export default () => {
|
|
|
44
44
|
];
|
|
45
45
|
},
|
|
46
46
|
modifyEntryImports({ entrypoint, imports }) {
|
|
47
|
-
const { entryName, fileSystemRoutes } = entrypoint;
|
|
47
|
+
const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
|
|
48
48
|
const userConfig = api.useResolvedConfigContext();
|
|
49
49
|
const { packageName } = api.useAppContext();
|
|
50
|
-
const runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
50
|
+
const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
51
51
|
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
52
52
|
if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
|
|
53
53
|
if (!isV5(userConfig)) {
|
|
@@ -82,14 +82,14 @@ export default () => {
|
|
|
82
82
|
};
|
|
83
83
|
},
|
|
84
84
|
modifyEntryImports({ entrypoint, imports }) {
|
|
85
|
-
const { entryName, fileSystemRoutes } = entrypoint;
|
|
85
|
+
const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
|
|
86
86
|
const userConfig = api.useResolvedConfigContext();
|
|
87
87
|
const { packageName, entrypoints } = api.useAppContext();
|
|
88
88
|
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
|
|
89
|
-
const ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
89
|
+
const ssrConfig = getEntryOptions(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
90
90
|
if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
|
|
91
91
|
var _ref;
|
|
92
|
-
const runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
92
|
+
const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
93
93
|
if (((_ref = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _ref === void 0 ? void 0 : _ref.mode) === "react-router-5") {
|
|
94
94
|
throw new Error(`router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'`);
|
|
95
95
|
}
|
|
@@ -117,11 +117,15 @@ export default () => {
|
|
|
117
117
|
modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
|
|
118
118
|
if (ssrConfigMap.get(entrypoint.entryName)) {
|
|
119
119
|
var _bundlerConfigs_find, _bundlerConfigs_find_output;
|
|
120
|
-
const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((
|
|
120
|
+
const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
|
|
121
|
+
const config = api.useResolvedConfigContext();
|
|
122
|
+
const { crossorigin, scriptLoading } = config.html;
|
|
121
123
|
plugins.push({
|
|
122
124
|
name: PLUGIN_IDENTIFIER,
|
|
123
125
|
options: JSON.stringify({
|
|
124
126
|
...ssrConfigMap.get(entrypoint.entryName) || {},
|
|
127
|
+
crossorigin,
|
|
128
|
+
scriptLoading,
|
|
125
129
|
chunkLoadingGlobal
|
|
126
130
|
})
|
|
127
131
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ChunkExtractor } from "@loadable/server";
|
|
2
|
-
import { isCrossOrigin } from "../../utils";
|
|
3
2
|
import { attributesToString, getLoadableScripts } from "../utils";
|
|
4
3
|
const extname = (uri) => {
|
|
5
4
|
if (typeof uri !== "string" || !uri.includes(".")) {
|
|
@@ -8,7 +7,7 @@ const extname = (uri) => {
|
|
|
8
7
|
return `.${uri === null || uri === void 0 ? void 0 : uri.split(".").pop()}` || "";
|
|
9
8
|
};
|
|
10
9
|
export const toHtml = (jsx, renderer, next) => {
|
|
11
|
-
const { stats, result: { chunksMap },
|
|
10
|
+
const { stats, result: { chunksMap }, config = {}, nonce } = renderer;
|
|
12
11
|
if (!stats || chunksMap.js) {
|
|
13
12
|
return next(jsx);
|
|
14
13
|
}
|
|
@@ -23,18 +22,27 @@ export const toHtml = (jsx, renderer, next) => {
|
|
|
23
22
|
chunksMap.js = (chunksMap.js || "") + getLoadableScripts(extractor);
|
|
24
23
|
for (const v of chunks) {
|
|
25
24
|
const fileType = extname(v.url).slice(1);
|
|
25
|
+
const attributes = {};
|
|
26
|
+
const { crossorigin, scriptLoading = "defer" } = config;
|
|
27
|
+
if (crossorigin) {
|
|
28
|
+
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
29
|
+
}
|
|
30
|
+
switch (scriptLoading) {
|
|
31
|
+
case "defer":
|
|
32
|
+
attributes.defer = true;
|
|
33
|
+
break;
|
|
34
|
+
case "module":
|
|
35
|
+
attributes.type = "module";
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
}
|
|
26
39
|
if (fileType === "js") {
|
|
27
|
-
|
|
28
|
-
nonce
|
|
29
|
-
};
|
|
30
|
-
const { crossorigin } = config;
|
|
31
|
-
if (crossorigin && isCrossOrigin(v.url, host)) {
|
|
32
|
-
attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
33
|
-
}
|
|
40
|
+
attributes.nonce = nonce;
|
|
34
41
|
const attrsStr = attributesToString(attributes);
|
|
35
42
|
chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
|
|
36
43
|
} else if (fileType === "css") {
|
|
37
|
-
|
|
44
|
+
const attrsStr = attributesToString(attributes);
|
|
45
|
+
chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
48
|
return html;
|
|
@@ -46,12 +46,3 @@ export const mockResponse = () => {
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
export const isCrossOrigin = (url = "", base) => {
|
|
50
|
-
if (url.startsWith("/") || url.startsWith("./")) {
|
|
51
|
-
return false;
|
|
52
|
-
} else if (!url.includes(base)) {
|
|
53
|
-
return true;
|
|
54
|
-
} else {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
@@ -23,10 +23,10 @@ export default () => {
|
|
|
23
23
|
},
|
|
24
24
|
modifyEntryImports({ entrypoint, imports }) {
|
|
25
25
|
var _getEntryOptions;
|
|
26
|
-
const { entryName } = entrypoint;
|
|
26
|
+
const { entryName, isMainEntry } = entrypoint;
|
|
27
27
|
const userConfig = api.useResolvedConfigContext();
|
|
28
28
|
const { packageName } = api.useAppContext();
|
|
29
|
-
const stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
29
|
+
const stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
30
30
|
stateConfigMap.set(entryName, stateConfig);
|
|
31
31
|
if (stateConfig) {
|
|
32
32
|
imports.push({
|
|
@@ -7,6 +7,7 @@ export type ModernSSRReactComponent = React.ComponentType<any>;
|
|
|
7
7
|
export { RuntimeContext, RenderLevel };
|
|
8
8
|
export type SSRPluginConfig = {
|
|
9
9
|
crossorigin?: boolean | 'anonymous' | 'use-credentials';
|
|
10
|
+
scriptLoading?: 'defer' | 'blocking' | 'module';
|
|
10
11
|
chunkLoadingGlobal?: string;
|
|
11
12
|
} & Exclude<ServerUserConfig['ssr'], boolean>;
|
|
12
13
|
export type ServerRenderOptions = {
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.24.1",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -169,9 +169,9 @@
|
|
|
169
169
|
"redux-logger": "^3.0.6",
|
|
170
170
|
"styled-components": "^5.3.1",
|
|
171
171
|
"@swc/helpers": "0.5.1",
|
|
172
|
-
"@modern-js/
|
|
173
|
-
"@modern-js/
|
|
174
|
-
"@modern-js/
|
|
172
|
+
"@modern-js/types": "2.24.1",
|
|
173
|
+
"@modern-js/utils": "2.24.1",
|
|
174
|
+
"@modern-js/plugin": "2.24.1"
|
|
175
175
|
},
|
|
176
176
|
"peerDependencies": {
|
|
177
177
|
"react": ">=17",
|
|
@@ -192,11 +192,11 @@
|
|
|
192
192
|
"ts-jest": "^29.1.0",
|
|
193
193
|
"typescript": "^5",
|
|
194
194
|
"webpack": "^5.82.1",
|
|
195
|
-
"@modern-js/
|
|
196
|
-
"@modern-js/core": "2.
|
|
197
|
-
"@modern-js/
|
|
198
|
-
"@scripts/build": "2.
|
|
199
|
-
"@scripts/jest-config": "2.
|
|
195
|
+
"@modern-js/core": "2.24.1",
|
|
196
|
+
"@modern-js/server-core": "2.24.1",
|
|
197
|
+
"@modern-js/app-tools": "2.24.1",
|
|
198
|
+
"@scripts/build": "2.24.1",
|
|
199
|
+
"@scripts/jest-config": "2.24.1"
|
|
200
200
|
},
|
|
201
201
|
"sideEffects": false,
|
|
202
202
|
"modernConfig": {},
|