@modern-js/runtime 1.20.1 → 1.21.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 +31 -0
- package/dist/js/modern/router/cli/index.js +1 -1
- package/dist/js/modern/router/index.js +1 -0
- package/dist/js/modern/ssr/cli/index.js +1 -1
- package/dist/js/modern/ssr/index.js +1 -3
- package/dist/js/modern/ssr/index.node.js +2 -4
- package/dist/js/modern/ssr/prefetch.js +5 -6
- package/dist/js/modern/ssr/serverRender/entry.js +4 -7
- package/dist/js/modern/ssr/serverRender/loadable.js +8 -5
- package/dist/js/modern/ssr/serverRender/template.js +4 -21
- package/dist/js/modern/state/cli/index.js +2 -27
- package/dist/js/modern/state/index.js +1 -0
- package/dist/js/modern/state/runtime/plugin.js +18 -2
- package/dist/js/node/router/cli/index.js +1 -1
- package/dist/js/node/router/index.js +9 -1
- package/dist/js/node/ssr/cli/index.js +1 -1
- package/dist/js/node/ssr/index.js +5 -2
- package/dist/js/node/ssr/index.node.js +7 -4
- package/dist/js/node/ssr/prefetch.js +5 -12
- package/dist/js/node/ssr/serverRender/entry.js +4 -9
- package/dist/js/node/ssr/serverRender/loadable.js +7 -7
- package/dist/js/node/ssr/serverRender/template.js +4 -23
- package/dist/js/node/state/cli/index.js +2 -27
- package/dist/js/node/state/index.js +9 -1
- package/dist/js/node/state/runtime/plugin.js +24 -8
- package/dist/js/treeshaking/router/cli/index.js +1 -1
- package/dist/js/treeshaking/router/index.js +1 -0
- package/dist/js/treeshaking/ssr/cli/index.js +1 -1
- package/dist/js/treeshaking/ssr/index.js +1 -3
- package/dist/js/treeshaking/ssr/index.node.js +2 -4
- package/dist/js/treeshaking/ssr/prefetch.js +5 -7
- package/dist/js/treeshaking/ssr/serverRender/entry.js +4 -7
- package/dist/js/treeshaking/ssr/serverRender/loadable.js +8 -5
- package/dist/js/treeshaking/ssr/serverRender/template.js +4 -21
- package/dist/js/treeshaking/state/cli/index.js +2 -23
- package/dist/js/treeshaking/state/index.js +1 -0
- package/dist/js/treeshaking/state/runtime/plugin.js +22 -2
- package/dist/types/router/index.d.ts +1 -0
- package/dist/types/ssr/index.d.ts +1 -1
- package/dist/types/ssr/index.node.d.ts +2 -2
- package/dist/types/ssr/serverRender/template.d.ts +1 -1
- package/dist/types/ssr/serverRender/type.d.ts +1 -1
- package/dist/types/state/index.d.ts +1 -0
- package/dist/types/state/runtime/plugin.d.ts +2 -2
- package/package.json +20 -44
- package/types/model.d.ts +1 -1
- package/dist/js/modern/exports/model.js +0 -2
- package/dist/js/modern/exports/router.js +0 -2
- package/dist/js/modern/exports/ssr.js +0 -2
- package/dist/js/node/exports/model.js +0 -32
- package/dist/js/node/exports/router.js +0 -32
- package/dist/js/node/exports/ssr.js +0 -32
- package/dist/js/treeshaking/exports/model.js +0 -2
- package/dist/js/treeshaking/exports/router.js +0 -2
- package/dist/js/treeshaking/exports/ssr.js +0 -2
- package/dist/types/exports/model.d.ts +0 -2
- package/dist/types/exports/router.d.ts +0 -2
- package/dist/types/exports/ssr.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 1.21.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @modern-js/webpack@1.21.1
|
|
8
|
+
- @modern-js/plugin@1.21.1
|
|
9
|
+
- @modern-js/utils@1.21.1
|
|
10
|
+
|
|
11
|
+
## 1.21.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- f51c59a: feat: remove node internal package like fs or path which import by ssr runtime
|
|
16
|
+
feat: 删除在 ssr runtime 中引用的 node 内部包
|
|
17
|
+
- 4c1f3a4: fix: runtime export field
|
|
18
|
+
|
|
19
|
+
fix: 修复 runtime 包导出字段
|
|
20
|
+
|
|
21
|
+
- 4c1f3a4: fix: state runtime plugin params
|
|
22
|
+
|
|
23
|
+
fix: state 插件参数格式
|
|
24
|
+
|
|
25
|
+
- c40fc4b: fix: add missing ssr exports from runtime ssr plugin
|
|
26
|
+
fix: 补充 runtime ssr 插件中丢失的 ssr 导出
|
|
27
|
+
- Updated dependencies [17d1672]
|
|
28
|
+
- Updated dependencies [28f0a4f]
|
|
29
|
+
- Updated dependencies [b0597e3]
|
|
30
|
+
- @modern-js/webpack@1.21.0
|
|
31
|
+
- @modern-js/plugin@1.21.0
|
|
32
|
+
- @modern-js/utils@1.21.0
|
|
33
|
+
|
|
3
34
|
## 1.20.1
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -96,7 +96,7 @@ export default (() => ({
|
|
|
96
96
|
},
|
|
97
97
|
|
|
98
98
|
addRuntimeExports() {
|
|
99
|
-
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/
|
|
99
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/router'`);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
};
|
|
@@ -55,7 +55,7 @@ export default (() => ({
|
|
|
55
55
|
packageName,
|
|
56
56
|
entrypoints
|
|
57
57
|
} = api.useAppContext();
|
|
58
|
-
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/
|
|
58
|
+
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`); // if use ssg then set ssr config to true
|
|
59
59
|
|
|
60
60
|
const ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
61
61
|
const ssgConfig = userConfig.output.ssg;
|
|
@@ -11,8 +11,7 @@ import { WithCallback } from "./react/withCallback";
|
|
|
11
11
|
import { formatClient, mockResponse } from "./utils";
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
|
14
|
-
|
|
15
|
-
const ssr = _ => ({
|
|
14
|
+
export const ssr = _ => ({
|
|
16
15
|
name: '@modern-js/plugin-ssr',
|
|
17
16
|
setup: () => {
|
|
18
17
|
const mockResp = mockResponse();
|
|
@@ -125,6 +124,5 @@ const ssr = _ => ({
|
|
|
125
124
|
};
|
|
126
125
|
}
|
|
127
126
|
});
|
|
128
|
-
|
|
129
127
|
export default ssr;
|
|
130
128
|
export * from "./react";
|
|
@@ -9,8 +9,7 @@ import { render } from "./serverRender";
|
|
|
9
9
|
import prefetch from "./prefetch";
|
|
10
10
|
import { formatServer } from "./utils";
|
|
11
11
|
const registeredApps = new WeakSet();
|
|
12
|
-
|
|
13
|
-
const plugin = (config = {}) => ({
|
|
12
|
+
export const ssr = (config = {}) => ({
|
|
14
13
|
name: '@modern-js/plugin-ssr',
|
|
15
14
|
setup: () => {
|
|
16
15
|
return {
|
|
@@ -63,6 +62,5 @@ const plugin = (config = {}) => ({
|
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
});
|
|
66
|
-
|
|
67
|
-
export default plugin;
|
|
65
|
+
export default ssr;
|
|
68
66
|
export * from "./react";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
1
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
2
|
import { run } from '@modern-js/utils/ssr';
|
|
5
|
-
import { LOADABLE_STATS_FILE } from '@modern-js/utils/constants';
|
|
6
3
|
import { ChunkExtractor } from '@loadable/server';
|
|
7
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
5
|
|
|
@@ -13,11 +10,13 @@ const prefetch = async (App, context) => run(context.ssrContext.request.headers,
|
|
|
13
10
|
const {
|
|
14
11
|
ssrContext
|
|
15
12
|
} = context;
|
|
16
|
-
const
|
|
13
|
+
const {
|
|
14
|
+
loadableStats
|
|
15
|
+
} = ssrContext;
|
|
17
16
|
|
|
18
|
-
if (
|
|
17
|
+
if (loadableStats) {
|
|
19
18
|
const extractor = new ChunkExtractor({
|
|
20
|
-
|
|
19
|
+
stats: loadableStats,
|
|
21
20
|
entrypoints: [ssrContext.entryName].filter(Boolean)
|
|
22
21
|
});
|
|
23
22
|
renderToStaticMarkup(extractor.collectChunks( /*#__PURE__*/_jsx(App, {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
2
|
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { LOADABLE_STATS_FILE } from '@modern-js/utils/constants';
|
|
5
3
|
import React from 'react';
|
|
6
4
|
import ReactDomServer from 'react-dom/server';
|
|
7
5
|
import serialize from 'serialize-javascript';
|
|
@@ -59,12 +57,12 @@ export default class Entry {
|
|
|
59
57
|
} = options;
|
|
60
58
|
const {
|
|
61
59
|
entryName,
|
|
62
|
-
template
|
|
60
|
+
template,
|
|
63
61
|
request: {
|
|
64
62
|
host
|
|
65
63
|
}
|
|
66
64
|
} = ctx;
|
|
67
|
-
this.fragments = toFragments(
|
|
65
|
+
this.fragments = toFragments(template, entryName);
|
|
68
66
|
this.entryName = entryName;
|
|
69
67
|
this.host = host;
|
|
70
68
|
this.App = options.App;
|
|
@@ -156,10 +154,9 @@ export default class Entry {
|
|
|
156
154
|
context: Object.assign(context, {
|
|
157
155
|
ssr: true
|
|
158
156
|
})
|
|
159
|
-
});
|
|
160
|
-
|
|
157
|
+
});
|
|
161
158
|
const renderContext = {
|
|
162
|
-
|
|
159
|
+
stats: ssrContext.loadableStats,
|
|
163
160
|
host: this.host,
|
|
164
161
|
result: this.result,
|
|
165
162
|
entryName: this.entryName,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { ChunkExtractor } from '@loadable/server';
|
|
3
2
|
import { isCrossOrigin } from "../utils";
|
|
4
3
|
|
|
4
|
+
const extname = uri => {
|
|
5
|
+
return uri.match(/\.[^.]+$/) || '';
|
|
6
|
+
};
|
|
7
|
+
|
|
5
8
|
function getLoadableScripts(extractor) {
|
|
6
9
|
const check = scripts => (scripts || '').includes('__LOADABLE_REQUIRED_CHUNKS___ext');
|
|
7
10
|
|
|
@@ -17,7 +20,7 @@ function getLoadableScripts(extractor) {
|
|
|
17
20
|
|
|
18
21
|
export const toHtml = (jsx, renderer, next) => {
|
|
19
22
|
const {
|
|
20
|
-
|
|
23
|
+
stats,
|
|
21
24
|
result: {
|
|
22
25
|
chunksMap
|
|
23
26
|
},
|
|
@@ -25,12 +28,12 @@ export const toHtml = (jsx, renderer, next) => {
|
|
|
25
28
|
config = {}
|
|
26
29
|
} = renderer;
|
|
27
30
|
|
|
28
|
-
if (!
|
|
31
|
+
if (!stats || chunksMap.js) {
|
|
29
32
|
return next(jsx);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
const extractor = new ChunkExtractor({
|
|
33
|
-
|
|
36
|
+
stats,
|
|
34
37
|
entrypoints: [renderer.entryName]
|
|
35
38
|
});
|
|
36
39
|
const html = next(extractor.collectChunks(jsx));
|
|
@@ -38,7 +41,7 @@ export const toHtml = (jsx, renderer, next) => {
|
|
|
38
41
|
chunksMap.js = (chunksMap.js || '') + getLoadableScripts(extractor);
|
|
39
42
|
|
|
40
43
|
for (const v of chunks) {
|
|
41
|
-
const fileType =
|
|
44
|
+
const fileType = extname(v.url).slice(1);
|
|
42
45
|
|
|
43
46
|
if (fileType === 'js') {
|
|
44
47
|
const props = [];
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
2
|
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
|
|
5
|
-
const readFile = filepath => {
|
|
6
|
-
if (fs.existsSync(filepath)) {
|
|
7
|
-
return fs.readFileSync(filepath, 'utf-8');
|
|
8
|
-
} else {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
3
|
const VARIABLE_REG_EXP = /<!--<\?([-=+])\s*(.*?)\s*\?>-->/;
|
|
14
4
|
const VARIABLE_SPLITTER = /(<!--<\?.*?\?>-->)/;
|
|
15
5
|
const ENCODE_HTML_RULES = {
|
|
@@ -72,19 +62,12 @@ _defineProperty(Fragment, "filterMap", {
|
|
|
72
62
|
});
|
|
73
63
|
|
|
74
64
|
const fragmentListMap = {};
|
|
75
|
-
export function toFragments(
|
|
76
|
-
if (fragmentListMap[
|
|
77
|
-
return fragmentListMap[
|
|
78
|
-
} // 未开启现代构建的项目无 -es6.html
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const template = readFile(filename);
|
|
82
|
-
|
|
83
|
-
if (!template) {
|
|
84
|
-
throw new Error(`Could not find template file: ${filename}`);
|
|
65
|
+
export function toFragments(template, entryName) {
|
|
66
|
+
if (fragmentListMap[entryName]) {
|
|
67
|
+
return fragmentListMap[entryName];
|
|
85
68
|
}
|
|
86
69
|
|
|
87
70
|
const fragmentList = template.split(VARIABLE_SPLITTER).filter(v => Boolean(v)).map(v => new Fragment(v));
|
|
88
|
-
fragmentListMap[
|
|
71
|
+
fragmentListMap[entryName] = fragmentList;
|
|
89
72
|
return fragmentList;
|
|
90
73
|
}
|
|
@@ -36,11 +36,6 @@ export default (() => ({
|
|
|
36
36
|
const stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
37
37
|
stateConfigMap.set(entryName, stateConfig);
|
|
38
38
|
|
|
39
|
-
const getEnabledPlugins = () => {
|
|
40
|
-
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
41
|
-
return internalPlugins.filter(name => stateConfig[name] !== false);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
39
|
if (stateConfig) {
|
|
45
40
|
imports.push({
|
|
46
41
|
value: '@modern-js/runtime/plugins',
|
|
@@ -48,23 +43,6 @@ export default (() => ({
|
|
|
48
43
|
imported: PLUGIN_IDENTIFIER
|
|
49
44
|
}]
|
|
50
45
|
});
|
|
51
|
-
imports.push({
|
|
52
|
-
value: '@modern-js/runtime/model',
|
|
53
|
-
specifiers: getEnabledPlugins().map(imported => ({
|
|
54
|
-
imported
|
|
55
|
-
})),
|
|
56
|
-
initialize: `
|
|
57
|
-
const createStatePlugins = (config) => {
|
|
58
|
-
const plugins = [];
|
|
59
|
-
|
|
60
|
-
${getEnabledPlugins().map(name => `
|
|
61
|
-
plugins.push(${name}(config['${name}']));
|
|
62
|
-
`).join('\n')}
|
|
63
|
-
|
|
64
|
-
return plugins;
|
|
65
|
-
}
|
|
66
|
-
`
|
|
67
|
-
});
|
|
68
46
|
}
|
|
69
47
|
|
|
70
48
|
return {
|
|
@@ -80,12 +58,9 @@ export default (() => ({
|
|
|
80
58
|
const stateOptions = stateConfigMap.get(entrypoint.entryName);
|
|
81
59
|
|
|
82
60
|
if (stateOptions) {
|
|
83
|
-
const isBoolean = typeof stateOptions === 'boolean';
|
|
84
|
-
let options = isBoolean ? '{}' : JSON.stringify(stateOptions);
|
|
85
|
-
options = `${options.substr(0, options.length - 1)}${isBoolean ? '' : ','}plugins: createStatePlugins(${JSON.stringify(stateConfigMap.get(entrypoint.entryName))})}`;
|
|
86
61
|
plugins.push({
|
|
87
62
|
name: PLUGIN_IDENTIFIER,
|
|
88
|
-
options
|
|
63
|
+
options: `${JSON.stringify(stateConfigMap.get(entrypoint.entryName))}`
|
|
89
64
|
});
|
|
90
65
|
}
|
|
91
66
|
|
|
@@ -100,7 +75,7 @@ export default (() => ({
|
|
|
100
75
|
},
|
|
101
76
|
|
|
102
77
|
addRuntimeExports() {
|
|
103
|
-
pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/
|
|
78
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/model'`);
|
|
104
79
|
}
|
|
105
80
|
|
|
106
81
|
};
|
|
@@ -8,9 +8,25 @@ import { useContext } from 'react';
|
|
|
8
8
|
import { createStore } from '@modern-js-reduck/store';
|
|
9
9
|
import { Provider } from '@modern-js-reduck/react';
|
|
10
10
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
11
|
+
import { immer, effects, autoActions, devtools } from "../plugins";
|
|
11
12
|
import { RuntimeReactContext } from "../../core";
|
|
12
13
|
import { isBrowser } from "../../common";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
const StatePluginHandleMap = {
|
|
16
|
+
immer,
|
|
17
|
+
effects,
|
|
18
|
+
autoActions,
|
|
19
|
+
devtools
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getStoreConfig = config => {
|
|
23
|
+
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
24
|
+
const plugins = [];
|
|
25
|
+
internalPlugins.filter(plugin => config[plugin] !== false).forEach(plugin => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
|
|
26
|
+
return {
|
|
27
|
+
plugins
|
|
28
|
+
};
|
|
29
|
+
};
|
|
14
30
|
|
|
15
31
|
const state = config => ({
|
|
16
32
|
name: '@modern-js/plugin-state',
|
|
@@ -24,7 +40,7 @@ const state = config => ({
|
|
|
24
40
|
const context = useContext(RuntimeReactContext);
|
|
25
41
|
return /*#__PURE__*/_jsx(Provider, {
|
|
26
42
|
store: context.store,
|
|
27
|
-
config: config,
|
|
43
|
+
config: getStoreConfig(config),
|
|
28
44
|
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
|
29
45
|
});
|
|
30
46
|
};
|
|
@@ -37,7 +53,7 @@ const state = config => ({
|
|
|
37
53
|
init({
|
|
38
54
|
context
|
|
39
55
|
}, next) {
|
|
40
|
-
const storeConfig = config || {};
|
|
56
|
+
const storeConfig = getStoreConfig(config || {});
|
|
41
57
|
|
|
42
58
|
if (isBrowser()) {
|
|
43
59
|
var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
|
|
@@ -105,7 +105,7 @@ var _default = () => ({
|
|
|
105
105
|
},
|
|
106
106
|
|
|
107
107
|
addRuntimeExports() {
|
|
108
|
-
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/
|
|
108
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/router'`);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
};
|
|
@@ -3,13 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
router: true
|
|
8
|
+
};
|
|
7
9
|
Object.defineProperty(exports, "default", {
|
|
8
10
|
enumerable: true,
|
|
9
11
|
get: function () {
|
|
10
12
|
return _runtime.default;
|
|
11
13
|
}
|
|
12
14
|
});
|
|
15
|
+
Object.defineProperty(exports, "router", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () {
|
|
18
|
+
return _runtime.default;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
13
21
|
|
|
14
22
|
var _runtime = _interopRequireWildcard(require("./runtime"));
|
|
15
23
|
|
|
@@ -64,7 +64,7 @@ var _default = () => ({
|
|
|
64
64
|
packageName,
|
|
65
65
|
entrypoints
|
|
66
66
|
} = api.useAppContext();
|
|
67
|
-
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/
|
|
67
|
+
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`); // if use ssg then set ssr config to true
|
|
68
68
|
|
|
69
69
|
const ssrConfig = (0, _utils.getEntryOptions)(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
70
70
|
const ssgConfig = userConfig.output.ssg;
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
ssr: true
|
|
8
|
+
};
|
|
9
|
+
exports.ssr = exports.default = void 0;
|
|
8
10
|
|
|
9
11
|
var _component = require("@loadable/component");
|
|
10
12
|
|
|
@@ -156,5 +158,6 @@ const ssr = _ => ({
|
|
|
156
158
|
}
|
|
157
159
|
});
|
|
158
160
|
|
|
161
|
+
exports.ssr = ssr;
|
|
159
162
|
var _default = ssr;
|
|
160
163
|
exports.default = _default;
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
ssr: true
|
|
8
|
+
};
|
|
9
|
+
exports.ssr = exports.default = void 0;
|
|
8
10
|
|
|
9
11
|
var _core = require("../core");
|
|
10
12
|
|
|
@@ -38,7 +40,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
38
40
|
|
|
39
41
|
const registeredApps = new WeakSet();
|
|
40
42
|
|
|
41
|
-
const
|
|
43
|
+
const ssr = (config = {}) => ({
|
|
42
44
|
name: '@modern-js/plugin-ssr',
|
|
43
45
|
setup: () => {
|
|
44
46
|
return {
|
|
@@ -92,5 +94,6 @@ const plugin = (config = {}) => ({
|
|
|
92
94
|
}
|
|
93
95
|
});
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
exports.ssr = ssr;
|
|
98
|
+
var _default = ssr;
|
|
96
99
|
exports.default = _default;
|
|
@@ -5,22 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
|
|
12
8
|
var _server = require("react-dom/server");
|
|
13
9
|
|
|
14
10
|
var _ssr = require("@modern-js/utils/ssr");
|
|
15
11
|
|
|
16
|
-
var _constants = require("@modern-js/utils/constants");
|
|
17
|
-
|
|
18
12
|
var _server2 = require("@loadable/server");
|
|
19
13
|
|
|
20
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
15
|
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
16
|
// todo: SSRContext
|
|
25
17
|
const prefetch = async (App, context) => (0, _ssr.run)(context.ssrContext.request.headers, async () => {
|
|
26
18
|
var _context$store;
|
|
@@ -28,12 +20,13 @@ const prefetch = async (App, context) => (0, _ssr.run)(context.ssrContext.reques
|
|
|
28
20
|
const {
|
|
29
21
|
ssrContext
|
|
30
22
|
} = context;
|
|
23
|
+
const {
|
|
24
|
+
loadableStats
|
|
25
|
+
} = ssrContext;
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (_fs.default.existsSync(loadablefile)) {
|
|
27
|
+
if (loadableStats) {
|
|
35
28
|
const extractor = new _server2.ChunkExtractor({
|
|
36
|
-
|
|
29
|
+
stats: loadableStats,
|
|
37
30
|
entrypoints: [ssrContext.entryName].filter(Boolean)
|
|
38
31
|
});
|
|
39
32
|
(0, _server.renderToStaticMarkup)(extractor.collectChunks( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, {
|
|
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _constants = require("@modern-js/utils/constants");
|
|
11
|
-
|
|
12
8
|
var _react = _interopRequireDefault(require("react"));
|
|
13
9
|
|
|
14
10
|
var _server = _interopRequireDefault(require("react-dom/server"));
|
|
@@ -84,12 +80,12 @@ class Entry {
|
|
|
84
80
|
} = options;
|
|
85
81
|
const {
|
|
86
82
|
entryName,
|
|
87
|
-
template
|
|
83
|
+
template,
|
|
88
84
|
request: {
|
|
89
85
|
host
|
|
90
86
|
}
|
|
91
87
|
} = ctx;
|
|
92
|
-
this.fragments = (0, _template.toFragments)(
|
|
88
|
+
this.fragments = (0, _template.toFragments)(template, entryName);
|
|
93
89
|
this.entryName = entryName;
|
|
94
90
|
this.host = host;
|
|
95
91
|
this.App = options.App;
|
|
@@ -182,11 +178,10 @@ class Entry {
|
|
|
182
178
|
context: Object.assign(context, {
|
|
183
179
|
ssr: true
|
|
184
180
|
})
|
|
185
|
-
});
|
|
186
|
-
|
|
181
|
+
});
|
|
187
182
|
|
|
188
183
|
const renderContext = {
|
|
189
|
-
|
|
184
|
+
stats: ssrContext.loadableStats,
|
|
190
185
|
host: this.host,
|
|
191
186
|
result: this.result,
|
|
192
187
|
entryName: this.entryName,
|
|
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.toHtml = void 0;
|
|
7
7
|
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _server = require("@loadable/server");
|
|
11
9
|
|
|
12
10
|
var _utils = require("../utils");
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
const extname = uri => {
|
|
13
|
+
return uri.match(/\.[^.]+$/) || '';
|
|
14
|
+
};
|
|
15
15
|
|
|
16
16
|
function getLoadableScripts(extractor) {
|
|
17
17
|
const check = scripts => (scripts || '').includes('__LOADABLE_REQUIRED_CHUNKS___ext');
|
|
@@ -28,7 +28,7 @@ function getLoadableScripts(extractor) {
|
|
|
28
28
|
|
|
29
29
|
const toHtml = (jsx, renderer, next) => {
|
|
30
30
|
const {
|
|
31
|
-
|
|
31
|
+
stats,
|
|
32
32
|
result: {
|
|
33
33
|
chunksMap
|
|
34
34
|
},
|
|
@@ -36,12 +36,12 @@ const toHtml = (jsx, renderer, next) => {
|
|
|
36
36
|
config = {}
|
|
37
37
|
} = renderer;
|
|
38
38
|
|
|
39
|
-
if (!
|
|
39
|
+
if (!stats || chunksMap.js) {
|
|
40
40
|
return next(jsx);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const extractor = new _server.ChunkExtractor({
|
|
44
|
-
|
|
44
|
+
stats,
|
|
45
45
|
entrypoints: [renderer.entryName]
|
|
46
46
|
});
|
|
47
47
|
const html = next(extractor.collectChunks(jsx));
|
|
@@ -49,7 +49,7 @@ const toHtml = (jsx, renderer, next) => {
|
|
|
49
49
|
chunksMap.js = (chunksMap.js || '') + getLoadableScripts(extractor);
|
|
50
50
|
|
|
51
51
|
for (const v of chunks) {
|
|
52
|
-
const fileType =
|
|
52
|
+
const fileType = extname(v.url).slice(1);
|
|
53
53
|
|
|
54
54
|
if (fileType === 'js') {
|
|
55
55
|
const props = [];
|
|
@@ -6,20 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Fragment = void 0;
|
|
7
7
|
exports.toFragments = toFragments;
|
|
8
8
|
|
|
9
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
9
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
10
|
|
|
15
|
-
const readFile = filepath => {
|
|
16
|
-
if (_fs.default.existsSync(filepath)) {
|
|
17
|
-
return _fs.default.readFileSync(filepath, 'utf-8');
|
|
18
|
-
} else {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
11
|
const VARIABLE_REG_EXP = /<!--<\?([-=+])\s*(.*?)\s*\?>-->/;
|
|
24
12
|
const VARIABLE_SPLITTER = /(<!--<\?.*?\?>-->)/;
|
|
25
13
|
const ENCODE_HTML_RULES = {
|
|
@@ -85,19 +73,12 @@ _defineProperty(Fragment, "filterMap", {
|
|
|
85
73
|
|
|
86
74
|
const fragmentListMap = {};
|
|
87
75
|
|
|
88
|
-
function toFragments(
|
|
89
|
-
if (fragmentListMap[
|
|
90
|
-
return fragmentListMap[
|
|
91
|
-
} // 未开启现代构建的项目无 -es6.html
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const template = readFile(filename);
|
|
95
|
-
|
|
96
|
-
if (!template) {
|
|
97
|
-
throw new Error(`Could not find template file: ${filename}`);
|
|
76
|
+
function toFragments(template, entryName) {
|
|
77
|
+
if (fragmentListMap[entryName]) {
|
|
78
|
+
return fragmentListMap[entryName];
|
|
98
79
|
}
|
|
99
80
|
|
|
100
81
|
const fragmentList = template.split(VARIABLE_SPLITTER).filter(v => Boolean(v)).map(v => new Fragment(v));
|
|
101
|
-
fragmentListMap[
|
|
82
|
+
fragmentListMap[entryName] = fragmentList;
|
|
102
83
|
return fragmentList;
|
|
103
84
|
}
|