@modern-js/runtime 2.17.0 → 2.18.0
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 +21 -0
- package/README.md +6 -0
- package/dist/cjs/ssr/cli/index.js +28 -13
- package/dist/cjs/ssr/cli/loadable-bundler-plugin.js +112 -0
- package/dist/esm/core/compatible.js +13 -13
- package/dist/esm/core/loader/loaderManager.js +7 -7
- package/dist/esm/core/loader/useLoader.js +2 -2
- package/dist/esm/core/plugin.js +6 -6
- package/dist/esm/document/Html.js +5 -5
- package/dist/esm/document/cli/index.js +6 -6
- package/dist/esm/document/constants.js +1 -1
- package/dist/esm/router/cli/index.js +6 -6
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +3 -3
- package/dist/esm/router/runtime/PrefetchLink.js +7 -7
- package/dist/esm/router/runtime/plugin.js +9 -9
- package/dist/esm/router/runtime/plugin.node.js +7 -7
- package/dist/esm/router/runtime/utils.js +6 -6
- package/dist/esm/router/runtime/withRouter.js +4 -4
- package/dist/esm/ssr/cli/index.js +35 -20
- package/dist/esm/ssr/cli/loadable-bundler-plugin.js +209 -0
- package/dist/esm/ssr/index.js +13 -13
- package/dist/esm/ssr/index.node.js +9 -9
- package/dist/esm/ssr/prefetch.js +3 -3
- package/dist/esm/ssr/react/prerender/index.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +3 -3
- package/dist/esm/ssr/serverRender/renderToStream/loadable.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/template.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/entry.js +3 -3
- package/dist/esm/ssr/serverRender/renderToString/index.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +1 -1
- package/dist/esm/ssr/serverRender/renderToString/template.js +1 -1
- package/dist/esm/ssr/utils.js +4 -4
- package/dist/esm/state/cli/index.js +4 -4
- package/dist/esm/state/runtime/plugin.js +7 -7
- package/dist/esm-node/ssr/cli/index.js +28 -13
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +103 -0
- package/dist/types/ssr/cli/loadable-bundler-plugin.d.ts +10 -0
- package/package.json +9 -9
package/dist/esm/ssr/utils.js
CHANGED
|
@@ -12,7 +12,7 @@ function _array_with_holes(arr) {
|
|
|
12
12
|
function _define_property(obj, key, value) {
|
|
13
13
|
if (key in obj) {
|
|
14
14
|
Object.defineProperty(obj, key, {
|
|
15
|
-
value,
|
|
15
|
+
value: value,
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true
|
|
@@ -91,10 +91,10 @@ export var isReact18 = function() {
|
|
|
91
91
|
export var formatServer = function(request) {
|
|
92
92
|
var _ref = request.headers || {}, _ref_cookie = _ref.cookie, cookie = _ref_cookie === void 0 ? "" : _ref_cookie, tmp = _ref["user-agent"], userAgent = tmp === void 0 ? "" : tmp, referer = _ref.referer;
|
|
93
93
|
return _object_spread({
|
|
94
|
-
cookie,
|
|
94
|
+
cookie: cookie,
|
|
95
95
|
cookieMap: cookieTool.parse(cookie || "") || {},
|
|
96
|
-
userAgent,
|
|
97
|
-
referer
|
|
96
|
+
userAgent: userAgent,
|
|
97
|
+
referer: referer
|
|
98
98
|
}, request);
|
|
99
99
|
};
|
|
100
100
|
var getQuery = function() {
|
|
@@ -40,8 +40,8 @@ export default function() {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
return {
|
|
43
|
-
entrypoint,
|
|
44
|
-
imports
|
|
43
|
+
entrypoint: entrypoint,
|
|
44
|
+
imports: imports
|
|
45
45
|
};
|
|
46
46
|
},
|
|
47
47
|
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
|
|
@@ -54,8 +54,8 @@ export default function() {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
return {
|
|
57
|
-
entrypoint,
|
|
58
|
-
plugins
|
|
57
|
+
entrypoint: entrypoint,
|
|
58
|
+
plugins: plugins
|
|
59
59
|
};
|
|
60
60
|
},
|
|
61
61
|
validateSchema: function validateSchema() {
|
|
@@ -12,7 +12,7 @@ function _array_with_holes(arr) {
|
|
|
12
12
|
function _define_property(obj, key, value) {
|
|
13
13
|
if (key in obj) {
|
|
14
14
|
Object.defineProperty(obj, key, {
|
|
15
|
-
value,
|
|
15
|
+
value: value,
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true
|
|
@@ -117,10 +117,10 @@ import { immer, effects, autoActions, devtools } from "../plugins";
|
|
|
117
117
|
import { RuntimeReactContext } from "../../core";
|
|
118
118
|
import { isBrowser } from "../../common";
|
|
119
119
|
var StatePluginHandleMap = {
|
|
120
|
-
immer,
|
|
121
|
-
effects,
|
|
122
|
-
autoActions,
|
|
123
|
-
devtools
|
|
120
|
+
immer: immer,
|
|
121
|
+
effects: effects,
|
|
122
|
+
autoActions: autoActions,
|
|
123
|
+
devtools: devtools
|
|
124
124
|
};
|
|
125
125
|
var getStoreConfig = function(config) {
|
|
126
126
|
var internalPlugins = [
|
|
@@ -189,13 +189,13 @@ var state = function(config) {
|
|
|
189
189
|
}
|
|
190
190
|
context.store = createStore(storeConfig);
|
|
191
191
|
return next({
|
|
192
|
-
context
|
|
192
|
+
context: context
|
|
193
193
|
});
|
|
194
194
|
},
|
|
195
195
|
pickContext: function pickContext(param, next) {
|
|
196
196
|
var context = param.context, pickedContext = param.pickedContext;
|
|
197
197
|
return next({
|
|
198
|
-
context,
|
|
198
|
+
context: context,
|
|
199
199
|
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
200
200
|
store: context.store
|
|
201
201
|
})
|
|
@@ -29,16 +29,31 @@ export default () => {
|
|
|
29
29
|
config() {
|
|
30
30
|
const appContext = api.useAppContext();
|
|
31
31
|
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
|
|
32
|
+
const userConfig = api.useResolvedConfigContext();
|
|
32
33
|
const { bundlerType = "webpack" } = api.useAppContext();
|
|
33
|
-
const babelConfig =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const babelConfig = (() => {
|
|
35
|
+
if (bundlerType === "webpack") {
|
|
36
|
+
return (config) => {
|
|
37
|
+
var _config_plugins;
|
|
38
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
39
|
+
if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
|
|
40
|
+
var _config_plugins1;
|
|
41
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
} else if (bundlerType === "rspack") {
|
|
45
|
+
if (isUseSSRBundle(userConfig)) {
|
|
46
|
+
return (config) => {
|
|
47
|
+
var _config_plugins;
|
|
48
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
49
|
+
if (hasStringSSREntry(userConfig)) {
|
|
50
|
+
var _config_plugins1;
|
|
51
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
40
55
|
}
|
|
41
|
-
}
|
|
56
|
+
})();
|
|
42
57
|
return {
|
|
43
58
|
source: {
|
|
44
59
|
alias: {
|
|
@@ -51,11 +66,11 @@ export default () => {
|
|
|
51
66
|
}
|
|
52
67
|
},
|
|
53
68
|
tools: {
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
if (isUseSSRBundle(
|
|
57
|
-
const
|
|
58
|
-
chain.plugin(CHAIN_ID.PLUGIN.LOADABLE).use(
|
|
69
|
+
bundlerChain(chain, { isServer, isServiceWorker, CHAIN_ID }) {
|
|
70
|
+
const userConfig2 = api.useResolvedConfigContext();
|
|
71
|
+
if (isUseSSRBundle(userConfig2) && !isServer && !isServiceWorker && hasStringSSREntry(userConfig2)) {
|
|
72
|
+
const LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
73
|
+
chain.plugin(CHAIN_ID.PLUGIN.LOADABLE).use(LoadableBundlerPlugin, [
|
|
59
74
|
{
|
|
60
75
|
filename: LOADABLE_STATS_FILE
|
|
61
76
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { fs } from "@modern-js/utils";
|
|
16
|
+
class LoadablePlugin {
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
this.compiler = compiler;
|
|
19
|
+
compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
|
|
20
|
+
if (this.opts.outputAsset || this.opts.writeToDisk) {
|
|
21
|
+
compiler.hooks.make.tap(LoadablePlugin.name, (compilation) => {
|
|
22
|
+
compilation.hooks.processAssets.tap({
|
|
23
|
+
name: LoadablePlugin.name,
|
|
24
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
25
|
+
}, () => {
|
|
26
|
+
const asset = this.handleEmit(compilation);
|
|
27
|
+
if (asset) {
|
|
28
|
+
compilation.emitAsset(this.opts.filename, asset);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
handleEmit(compilation) {
|
|
35
|
+
const stats = compilation.getStats().toJson({
|
|
36
|
+
all: false,
|
|
37
|
+
assets: true,
|
|
38
|
+
// rspack not support cachedAssets,
|
|
39
|
+
cachedAssets: true,
|
|
40
|
+
chunks: true,
|
|
41
|
+
chunkGroups: true,
|
|
42
|
+
entrypoints: true,
|
|
43
|
+
// rspack not support chunkGroupChildren.
|
|
44
|
+
chunkGroupChildren: true,
|
|
45
|
+
hash: true,
|
|
46
|
+
ids: true,
|
|
47
|
+
outputPath: true,
|
|
48
|
+
publicPath: true
|
|
49
|
+
});
|
|
50
|
+
const output = {
|
|
51
|
+
...stats,
|
|
52
|
+
generator: "loadable-components",
|
|
53
|
+
chunks: [
|
|
54
|
+
...stats.chunks || []
|
|
55
|
+
].map((chunk) => {
|
|
56
|
+
return {
|
|
57
|
+
id: chunk.id,
|
|
58
|
+
files: [
|
|
59
|
+
...chunk.files || []
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
})
|
|
63
|
+
};
|
|
64
|
+
const result = JSON.stringify(output, null, 2);
|
|
65
|
+
if (this.opts.writeToDisk) {
|
|
66
|
+
this.writeAssetsFile(result);
|
|
67
|
+
}
|
|
68
|
+
if (this.opts.outputAsset) {
|
|
69
|
+
return {
|
|
70
|
+
source() {
|
|
71
|
+
return result;
|
|
72
|
+
},
|
|
73
|
+
size() {
|
|
74
|
+
return result.length;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
writeAssetsFile(manifest) {
|
|
81
|
+
var _this_compiler;
|
|
82
|
+
const outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
|
|
83
|
+
const outputFile = path.resolve(outputFolder || "", this.opts.filename);
|
|
84
|
+
fs.outputFileSync(outputFile, manifest);
|
|
85
|
+
}
|
|
86
|
+
constructor({ filename = "loadable-stats.json", path: path2, writeToDisk, outputAsset = true, chunkLoadingGlobal = "__LOADABLE_LOADED_CHUNKS__" } = {
|
|
87
|
+
filename: "loadable-stats.json",
|
|
88
|
+
outputAsset: true,
|
|
89
|
+
chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
|
|
90
|
+
}) {
|
|
91
|
+
_define_property(this, "opts", void 0);
|
|
92
|
+
_define_property(this, "compiler", void 0);
|
|
93
|
+
this.opts = {
|
|
94
|
+
filename,
|
|
95
|
+
path: path2,
|
|
96
|
+
writeToDisk,
|
|
97
|
+
outputAsset,
|
|
98
|
+
chunkLoadingGlobal
|
|
99
|
+
};
|
|
100
|
+
this.compiler = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
module.exports = LoadablePlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/gregberge/loadable-components
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Greg Bergé
|
|
7
|
+
* Copyright 2019 Greg Bergé
|
|
8
|
+
* https://github.com/gregberge/loadable-components/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.18.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -162,9 +162,9 @@
|
|
|
162
162
|
"react-side-effect": "^2.1.1",
|
|
163
163
|
"redux-logger": "^3.0.6",
|
|
164
164
|
"styled-components": "^5.3.1",
|
|
165
|
-
"@modern-js/plugin": "2.
|
|
166
|
-
"@modern-js/types": "2.
|
|
167
|
-
"@modern-js/utils": "2.
|
|
165
|
+
"@modern-js/plugin": "2.18.0",
|
|
166
|
+
"@modern-js/types": "2.18.0",
|
|
167
|
+
"@modern-js/utils": "2.18.0"
|
|
168
168
|
},
|
|
169
169
|
"peerDependencies": {
|
|
170
170
|
"react": ">=17",
|
|
@@ -184,11 +184,11 @@
|
|
|
184
184
|
"react-dom": "^18",
|
|
185
185
|
"ts-jest": "^29.0.5",
|
|
186
186
|
"typescript": "^4",
|
|
187
|
-
"@modern-js/app-tools": "2.
|
|
188
|
-
"@modern-js/core": "2.
|
|
189
|
-
"@modern-js/server-core": "2.
|
|
190
|
-
"@scripts/build": "2.
|
|
191
|
-
"@scripts/jest-config": "2.
|
|
187
|
+
"@modern-js/app-tools": "2.18.0",
|
|
188
|
+
"@modern-js/core": "2.18.0",
|
|
189
|
+
"@modern-js/server-core": "2.18.0",
|
|
190
|
+
"@scripts/build": "2.18.0",
|
|
191
|
+
"@scripts/jest-config": "2.18.0"
|
|
192
192
|
},
|
|
193
193
|
"sideEffects": false,
|
|
194
194
|
"modernConfig": {},
|