@modern-js/runtime 2.63.2 → 2.63.4
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/dist/cjs/cli/code.js +2 -2
- package/dist/cjs/cli/index.js +102 -108
- package/dist/cjs/cli/ssr/index.js +49 -52
- package/dist/cjs/core/server/string/loadable.js +13 -3
- package/dist/cjs/document/cli/index.js +32 -34
- package/dist/cjs/router/cli/code/index.js +5 -5
- package/dist/cjs/router/cli/handler.js +6 -6
- package/dist/cjs/router/cli/index.js +76 -78
- package/dist/cjs/router/runtime/plugin.js +1 -4
- package/dist/cjs/state/cli/index.js +22 -24
- package/dist/esm/cli/code.js +3 -3
- package/dist/esm/cli/index.js +120 -130
- package/dist/esm/cli/ssr/index.js +50 -53
- package/dist/esm/core/server/string/loadable.js +17 -5
- package/dist/esm/document/cli/index.js +28 -30
- package/dist/esm/router/cli/code/index.js +8 -8
- package/dist/esm/router/cli/handler.js +6 -6
- package/dist/esm/router/cli/index.js +161 -157
- package/dist/esm/router/runtime/plugin.js +1 -4
- package/dist/esm/state/cli/index.js +23 -25
- package/dist/esm-node/cli/code.js +2 -2
- package/dist/esm-node/cli/index.js +102 -108
- package/dist/esm-node/cli/ssr/index.js +49 -52
- package/dist/esm-node/core/server/string/loadable.js +13 -3
- package/dist/esm-node/document/cli/index.js +32 -34
- package/dist/esm-node/router/cli/code/index.js +5 -5
- package/dist/esm-node/router/cli/handler.js +6 -6
- package/dist/esm-node/router/cli/index.js +76 -78
- package/dist/esm-node/router/runtime/plugin.js +1 -4
- package/dist/esm-node/state/cli/index.js +22 -24
- package/dist/types/cli/code.d.ts +2 -9
- package/dist/types/cli/index.d.ts +3 -3
- package/dist/types/cli/ssr/index.d.ts +2 -2
- package/dist/types/core/server/string/loadable.d.ts +3 -2
- package/dist/types/document/cli/index.d.ts +2 -2
- package/dist/types/router/cli/code/index.d.ts +3 -3
- package/dist/types/router/cli/code/templates.d.ts +2 -2
- package/dist/types/router/cli/handler.d.ts +4 -4
- package/dist/types/router/cli/index.d.ts +2 -2
- package/dist/types/router/runtime/types.d.ts +0 -10
- package/dist/types/state/cli/index.d.ts +2 -2
- package/package.json +11 -11
|
@@ -18,167 +18,171 @@ var routerPlugin = function() {
|
|
|
18
18
|
setup: function(api) {
|
|
19
19
|
var nestedRoutes = {};
|
|
20
20
|
var nestedRoutesForServer = {};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
api._internalRuntimePlugins(function(param) {
|
|
22
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
23
|
+
var _getEntryOptions;
|
|
24
|
+
var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, serverRoutes = _api_getAppContext.serverRoutes, metaName = _api_getAppContext.metaName;
|
|
25
|
+
var serverBase = serverRoutes.filter(function(route) {
|
|
26
|
+
return route.entryName === entrypoint.entryName;
|
|
27
|
+
}).map(function(route) {
|
|
28
|
+
return route.urlPath;
|
|
29
|
+
}).sort(function(a, b) {
|
|
30
|
+
return a.length - b.length > 0 ? -1 : 1;
|
|
31
|
+
});
|
|
32
|
+
var userConfig = api.getNormalizedConfig();
|
|
33
|
+
var routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
|
|
34
|
+
if (routerConfig && !isV5(userConfig)) {
|
|
35
|
+
plugins.push({
|
|
36
|
+
name: "router",
|
|
37
|
+
path: "@".concat(metaName, "/runtime/router"),
|
|
38
|
+
config: typeof routerConfig === "boolean" ? {
|
|
39
|
+
serverBase
|
|
40
|
+
} : _object_spread_props(_object_spread({}, routerConfig), {
|
|
41
|
+
serverBase
|
|
42
|
+
})
|
|
32
43
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
entrypoint,
|
|
47
|
+
plugins
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
api.checkEntryPoint(function(param) {
|
|
51
|
+
var path2 = param.path, entry = param.entry;
|
|
52
|
+
return {
|
|
53
|
+
path: path2,
|
|
54
|
+
entry: entry || isRouteEntry(path2)
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
api.config(function() {
|
|
58
|
+
return {
|
|
59
|
+
source: {
|
|
60
|
+
include: [
|
|
61
|
+
// react-router v6 is no longer support ie 11
|
|
62
|
+
// so we need to compile these packages to ensure the compatibility
|
|
63
|
+
// https://github.com/remix-run/react-router/commit/f6df0697e1b2064a2b3a12e8b39577326fdd945b
|
|
64
|
+
/node_modules\/react-router/,
|
|
65
|
+
/node_modules\/react-router-dom/,
|
|
66
|
+
/node_modules\/@remix-run\/router/
|
|
67
|
+
]
|
|
45
68
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/node_modules\/@remix-run\/router/
|
|
68
|
-
]
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
api.modifyEntrypoints(function() {
|
|
72
|
+
var _ref = _async_to_generator(function(param) {
|
|
73
|
+
var entrypoints, newEntryPoints;
|
|
74
|
+
return _ts_generator(this, function(_state) {
|
|
75
|
+
switch (_state.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
entrypoints = param.entrypoints;
|
|
78
|
+
return [
|
|
79
|
+
4,
|
|
80
|
+
handleModifyEntrypoints(api, entrypoints)
|
|
81
|
+
];
|
|
82
|
+
case 1:
|
|
83
|
+
newEntryPoints = _state.sent();
|
|
84
|
+
return [
|
|
85
|
+
2,
|
|
86
|
+
{
|
|
87
|
+
entrypoints: newEntryPoints
|
|
88
|
+
}
|
|
89
|
+
];
|
|
69
90
|
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
case 1:
|
|
106
|
-
_state.sent();
|
|
107
|
-
return [
|
|
108
|
-
2
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
})();
|
|
113
|
-
},
|
|
114
|
-
addRuntimeExports: function addRuntimeExports() {
|
|
115
|
-
var userConfig = api.useResolvedConfigContext();
|
|
116
|
-
var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
|
|
117
|
-
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
118
|
-
if (!isV5(userConfig)) {
|
|
119
|
-
pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName, "/runtime/router'"));
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
fileChange: function fileChange(e) {
|
|
123
|
-
return _async_to_generator(function() {
|
|
124
|
-
return _ts_generator(this, function(_state) {
|
|
125
|
-
switch (_state.label) {
|
|
126
|
-
case 0:
|
|
127
|
-
return [
|
|
128
|
-
4,
|
|
129
|
-
handleFileChange(api, e)
|
|
130
|
-
];
|
|
131
|
-
case 1:
|
|
132
|
-
_state.sent();
|
|
133
|
-
return [
|
|
134
|
-
2
|
|
135
|
-
];
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
})();
|
|
139
|
-
},
|
|
140
|
-
modifyFileSystemRoutes: function modifyFileSystemRoutes(param) {
|
|
141
|
-
var entrypoint = param.entrypoint, routes = param.routes;
|
|
142
|
-
return _async_to_generator(function() {
|
|
143
|
-
return _ts_generator(this, function(_state) {
|
|
144
|
-
nestedRoutes[entrypoint.entryName] = routes;
|
|
145
|
-
nestedRoutesForServer[entrypoint.entryName] = filterRoutesForServer(routes);
|
|
146
|
-
return [
|
|
147
|
-
2,
|
|
148
|
-
{
|
|
149
|
-
entrypoint,
|
|
150
|
-
routes
|
|
151
|
-
}
|
|
152
|
-
];
|
|
153
|
-
});
|
|
154
|
-
})();
|
|
155
|
-
},
|
|
156
|
-
beforeGenerateRoutes: function beforeGenerateRoutes(param) {
|
|
157
|
-
var entrypoint = param.entrypoint, code = param.code;
|
|
158
|
-
return _async_to_generator(function() {
|
|
159
|
-
var distDirectory;
|
|
160
|
-
return _ts_generator(this, function(_state) {
|
|
161
|
-
switch (_state.label) {
|
|
162
|
-
case 0:
|
|
163
|
-
distDirectory = api.useAppContext().distDirectory;
|
|
164
|
-
return [
|
|
165
|
-
4,
|
|
166
|
-
fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutesForServer)
|
|
167
|
-
];
|
|
168
|
-
case 1:
|
|
169
|
-
_state.sent();
|
|
170
|
-
return [
|
|
171
|
-
2,
|
|
172
|
-
{
|
|
173
|
-
entrypoint,
|
|
174
|
-
code
|
|
175
|
-
}
|
|
176
|
-
];
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
})();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return function(_) {
|
|
94
|
+
return _ref.apply(this, arguments);
|
|
95
|
+
};
|
|
96
|
+
}());
|
|
97
|
+
api.generateEntryCode(function() {
|
|
98
|
+
var _ref = _async_to_generator(function(param) {
|
|
99
|
+
var entrypoints;
|
|
100
|
+
return _ts_generator(this, function(_state) {
|
|
101
|
+
switch (_state.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
entrypoints = param.entrypoints;
|
|
104
|
+
return [
|
|
105
|
+
4,
|
|
106
|
+
handleGeneratorEntryCode(api, entrypoints)
|
|
107
|
+
];
|
|
108
|
+
case 1:
|
|
109
|
+
_state.sent();
|
|
110
|
+
return [
|
|
111
|
+
2
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return function(_) {
|
|
117
|
+
return _ref.apply(this, arguments);
|
|
118
|
+
};
|
|
119
|
+
}());
|
|
120
|
+
api.addRuntimeExports(function() {
|
|
121
|
+
var userConfig = api.useResolvedConfigContext();
|
|
122
|
+
var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
|
|
123
|
+
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
124
|
+
if (!isV5(userConfig)) {
|
|
125
|
+
pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName, "/runtime/router'"));
|
|
180
126
|
}
|
|
181
|
-
};
|
|
127
|
+
});
|
|
128
|
+
api.onFileChanged(function() {
|
|
129
|
+
var _ref = _async_to_generator(function(e) {
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
switch (_state.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
return [
|
|
134
|
+
4,
|
|
135
|
+
handleFileChange(api, e)
|
|
136
|
+
];
|
|
137
|
+
case 1:
|
|
138
|
+
_state.sent();
|
|
139
|
+
return [
|
|
140
|
+
2
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
return function(e) {
|
|
146
|
+
return _ref.apply(this, arguments);
|
|
147
|
+
};
|
|
148
|
+
}());
|
|
149
|
+
api.modifyFileSystemRoutes(function(param) {
|
|
150
|
+
var entrypoint = param.entrypoint, routes = param.routes;
|
|
151
|
+
nestedRoutes[entrypoint.entryName] = routes;
|
|
152
|
+
nestedRoutesForServer[entrypoint.entryName] = filterRoutesForServer(routes);
|
|
153
|
+
return {
|
|
154
|
+
entrypoint,
|
|
155
|
+
routes
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
api.onBeforeGenerateRoutes(function() {
|
|
159
|
+
var _ref = _async_to_generator(function(param) {
|
|
160
|
+
var entrypoint, code, distDirectory;
|
|
161
|
+
return _ts_generator(this, function(_state) {
|
|
162
|
+
switch (_state.label) {
|
|
163
|
+
case 0:
|
|
164
|
+
entrypoint = param.entrypoint, code = param.code;
|
|
165
|
+
distDirectory = api.getAppContext().distDirectory;
|
|
166
|
+
return [
|
|
167
|
+
4,
|
|
168
|
+
fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutesForServer)
|
|
169
|
+
];
|
|
170
|
+
case 1:
|
|
171
|
+
_state.sent();
|
|
172
|
+
return [
|
|
173
|
+
2,
|
|
174
|
+
{
|
|
175
|
+
entrypoint,
|
|
176
|
+
code
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
return function(_) {
|
|
183
|
+
return _ref.apply(this, arguments);
|
|
184
|
+
};
|
|
185
|
+
}());
|
|
182
186
|
}
|
|
183
187
|
};
|
|
184
188
|
};
|
|
@@ -3,7 +3,6 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
6
|
-
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
7
6
|
import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
|
|
8
7
|
import { useContext, useMemo } from "react";
|
|
9
8
|
import { RuntimeReactContext } from "../../core";
|
|
@@ -32,7 +31,6 @@ var routerPlugin = function() {
|
|
|
32
31
|
},
|
|
33
32
|
setup: function(api) {
|
|
34
33
|
var routes = [];
|
|
35
|
-
window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
|
|
36
34
|
return {
|
|
37
35
|
beforeRender: function beforeRender(context) {
|
|
38
36
|
context.router = {
|
|
@@ -63,9 +61,8 @@ var routerPlugin = function() {
|
|
|
63
61
|
}
|
|
64
62
|
var getRouteApp = function() {
|
|
65
63
|
var useCreateRouter = function(props) {
|
|
66
|
-
var _window__SERVER_DATA;
|
|
67
64
|
var runtimeContext = useContext(RuntimeReactContext);
|
|
68
|
-
var baseUrl =
|
|
65
|
+
var baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
|
69
66
|
var _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
|
|
70
67
|
var hydrationData = window._ROUTER_DATA;
|
|
71
68
|
var getBlockNavState = runtimeContext.unstable_getBlockNavState;
|
|
@@ -7,32 +7,30 @@ var statePlugin = function() {
|
|
|
7
7
|
"@modern-js/runtime"
|
|
8
8
|
],
|
|
9
9
|
setup: function(api) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
entrypoint,
|
|
27
|
-
plugins
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
addRuntimeExports: function addRuntimeExports() {
|
|
31
|
-
var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
|
|
32
|
-
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
33
|
-
pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/runtime/model'"));
|
|
10
|
+
api._internalRuntimePlugins(function(param) {
|
|
11
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
12
|
+
var _getEntryOptions;
|
|
13
|
+
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
|
|
14
|
+
var userConfig = api.useResolvedConfigContext();
|
|
15
|
+
var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, metaName = _api_useAppContext.metaName;
|
|
16
|
+
var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
17
|
+
if (stateConfig) {
|
|
18
|
+
plugins.push({
|
|
19
|
+
name: PLUGIN_IDENTIFIER,
|
|
20
|
+
path: "@".concat(metaName, "/runtime/model"),
|
|
21
|
+
config: typeof stateConfig === "boolean" ? {} : stateConfig
|
|
22
|
+
});
|
|
34
23
|
}
|
|
35
|
-
|
|
24
|
+
return {
|
|
25
|
+
entrypoint,
|
|
26
|
+
plugins
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
api.addRuntimeExports(function() {
|
|
30
|
+
var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
|
|
31
|
+
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
32
|
+
pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/runtime/model'"));
|
|
33
|
+
});
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
36
|
};
|
|
@@ -19,13 +19,13 @@ function getSSRMode(entry, config) {
|
|
|
19
19
|
return ssr2.mode === "stream" ? "stream" : "string";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
const generateCode = async (entrypoints, appContext, config,
|
|
22
|
+
const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
23
23
|
const { mountId } = config.html;
|
|
24
24
|
const { enableAsyncEntry } = config.source;
|
|
25
25
|
const { runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory } = appContext;
|
|
26
26
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
27
27
|
const { entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry } = entrypoint;
|
|
28
|
-
const { plugins: runtimePlugins } = await
|
|
28
|
+
const { plugins: runtimePlugins } = await hooks._internalRuntimePlugins.call({
|
|
29
29
|
entrypoint,
|
|
30
30
|
plugins: []
|
|
31
31
|
});
|
|
@@ -26,119 +26,113 @@ const runtimePlugin = (params) => ({
|
|
|
26
26
|
documentPlugin()
|
|
27
27
|
],
|
|
28
28
|
setup: (api) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
api.checkEntryPoint(({ path: path2, entry }) => {
|
|
30
|
+
return {
|
|
31
|
+
path: path2,
|
|
32
|
+
entry: entry || isRuntimeEntry(path2)
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
api.modifyEntrypoints(({ entrypoints }) => {
|
|
36
|
+
const { internalDirectory } = api.getAppContext();
|
|
37
|
+
const { source: { enableAsyncEntry } } = api.getNormalizedConfig();
|
|
38
|
+
const newEntryPoints = entrypoints.map((entrypoint) => {
|
|
39
|
+
if (entrypoint.isAutoMount) {
|
|
40
|
+
entrypoint.internalEntry = path.resolve(internalDirectory, `./${entrypoint.entryName}/${enableAsyncEntry ? ENTRY_BOOTSTRAP_FILE_NAME : ENTRY_POINT_FILE_NAME}`);
|
|
41
|
+
}
|
|
42
|
+
return entrypoint;
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
entrypoints: newEntryPoints
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
api.generateEntryCode(async ({ entrypoints }) => {
|
|
49
|
+
const appContext = api.getAppContext();
|
|
50
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
51
|
+
const hooks = api.getHooks();
|
|
52
|
+
await generateCode(entrypoints, appContext, resolvedConfig, hooks);
|
|
53
|
+
});
|
|
54
|
+
api.onPrepare(() => {
|
|
55
|
+
const { builder, entrypoints, internalDirectory, metaName } = api.getAppContext();
|
|
56
|
+
builder === null || builder === void 0 ? void 0 : builder.addPlugins([
|
|
57
|
+
builderPluginAlias({
|
|
58
|
+
entrypoints,
|
|
59
|
+
internalDirectory,
|
|
60
|
+
metaName
|
|
61
|
+
})
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
api.config(() => {
|
|
65
|
+
const { appDirectory, metaName, internalDirectory } = api.getAppContext();
|
|
66
|
+
const isReact18 = checkIsReact18(appDirectory);
|
|
67
|
+
process.env.IS_REACT18 = isReact18.toString();
|
|
68
|
+
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
69
|
+
return {
|
|
70
|
+
runtime: {},
|
|
71
|
+
runtimeByEntries: {},
|
|
72
|
+
source: {
|
|
73
|
+
alias: {
|
|
74
|
+
/**
|
|
75
|
+
* twin.macro inserts styled-components into the code during the compilation process
|
|
76
|
+
* But it will not be installed under the user project.
|
|
77
|
+
* So need to add alias
|
|
78
|
+
*/
|
|
79
|
+
"styled-components": require.resolve("styled-components"),
|
|
80
|
+
/**
|
|
81
|
+
* Compatible with the reference path of the old version of the plugin.
|
|
82
|
+
*/
|
|
83
|
+
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
|
|
84
|
+
"@meta/runtime/browser$": require.resolve("@modern-js/runtime/browser"),
|
|
85
|
+
"@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
|
|
86
|
+
"@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
|
|
87
|
+
"@meta/runtime$": require.resolve("@modern-js/runtime")
|
|
88
|
+
},
|
|
89
|
+
globalVars: {
|
|
90
|
+
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
42
91
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
metaName
|
|
66
|
-
})
|
|
67
|
-
]);
|
|
68
|
-
},
|
|
69
|
-
config() {
|
|
70
|
-
const { appDirectory, metaName, internalDirectory } = api.useAppContext();
|
|
71
|
-
const isReact18 = checkIsReact18(appDirectory);
|
|
72
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
73
|
-
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
74
|
-
return {
|
|
75
|
-
runtime: {},
|
|
76
|
-
runtimeByEntries: {},
|
|
77
|
-
source: {
|
|
78
|
-
alias: {
|
|
79
|
-
/**
|
|
80
|
-
* twin.macro inserts styled-components into the code during the compilation process
|
|
81
|
-
* But it will not be installed under the user project.
|
|
82
|
-
* So need to add alias
|
|
83
|
-
*/
|
|
84
|
-
"styled-components": require.resolve("styled-components"),
|
|
85
|
-
/**
|
|
86
|
-
* Compatible with the reference path of the old version of the plugin.
|
|
87
|
-
*/
|
|
88
|
-
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
|
|
89
|
-
"@meta/runtime/browser$": require.resolve("@modern-js/runtime/browser"),
|
|
90
|
-
"@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
|
|
91
|
-
"@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
|
|
92
|
-
"@meta/runtime$": require.resolve("@modern-js/runtime")
|
|
93
|
-
},
|
|
94
|
-
globalVars: {
|
|
95
|
-
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
92
|
+
},
|
|
93
|
+
tools: {
|
|
94
|
+
styledComponents: {
|
|
95
|
+
// https://github.com/styled-components/babel-plugin-styled-components/issues/287
|
|
96
|
+
topLevelImportPaths: [
|
|
97
|
+
"@modern-js/runtime/styled"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
bundlerChain: (chain) => {
|
|
101
|
+
chain.module.rule("modern-entry").test(/\.jsx?$/).include.add(path.resolve(appDirectory, "node_modules", `.${metaName}`)).end().sideEffects(true);
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Add IgnorePlugin to fix react-dom/client import error when use react17
|
|
105
|
+
*/
|
|
106
|
+
webpackChain: (chain, { webpack }) => {
|
|
107
|
+
if (!isReact18) {
|
|
108
|
+
chain.plugin("ignore-plugin").use(webpack.IgnorePlugin, [
|
|
109
|
+
{
|
|
110
|
+
resourceRegExp: /^react-dom\/client$/,
|
|
111
|
+
contextRegExp: /./
|
|
112
|
+
}
|
|
113
|
+
]);
|
|
96
114
|
}
|
|
97
115
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
chain.module.rule("modern-entry").test(/\.jsx?$/).include.add(path.resolve(appDirectory, "node_modules", `.${metaName}`)).end().sideEffects(true);
|
|
107
|
-
},
|
|
108
|
-
/**
|
|
109
|
-
* Add IgnorePlugin to fix react-dom/client import error when use react17
|
|
110
|
-
*/
|
|
111
|
-
webpackChain: (chain, { webpack }) => {
|
|
112
|
-
if (!isReact18) {
|
|
113
|
-
chain.plugin("ignore-plugin").use(webpack.IgnorePlugin, [
|
|
114
|
-
{
|
|
115
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
116
|
-
contextRegExp: /./
|
|
117
|
-
}
|
|
118
|
-
]);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
rspack: (_config, { appendPlugins, rspack }) => {
|
|
122
|
-
if (!isReact18) {
|
|
123
|
-
appendPlugins([
|
|
124
|
-
new rspack.IgnorePlugin({
|
|
125
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
126
|
-
contextRegExp: /./
|
|
127
|
-
})
|
|
128
|
-
]);
|
|
129
|
-
}
|
|
116
|
+
rspack: (_config, { appendPlugins, rspack }) => {
|
|
117
|
+
if (!isReact18) {
|
|
118
|
+
appendPlugins([
|
|
119
|
+
new rspack.IgnorePlugin({
|
|
120
|
+
resourceRegExp: /^react-dom\/client$/,
|
|
121
|
+
contextRegExp: /./
|
|
122
|
+
})
|
|
123
|
+
]);
|
|
130
124
|
}
|
|
131
125
|
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
api.onBeforeRestart(() => {
|
|
130
|
+
cleanRequireCache([
|
|
131
|
+
require.resolve("../state/cli"),
|
|
132
|
+
require.resolve("../router/cli"),
|
|
133
|
+
require.resolve("./ssr")
|
|
134
|
+
]);
|
|
135
|
+
});
|
|
142
136
|
}
|
|
143
137
|
});
|
|
144
138
|
var cli_default = runtimePlugin;
|