@modern-js/runtime 2.0.0-beta.1 → 2.0.0-beta.3
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 +181 -0
- package/dist/js/modern/cli/index.js +3 -1
- package/dist/js/modern/core/compatible.js +4 -3
- package/dist/js/modern/document/cli/index.js +10 -8
- package/dist/js/modern/document/constants.js +1 -1
- package/dist/js/modern/router/runtime/plugin.js +8 -7
- package/dist/js/modern/router/runtime/plugin.node.js +10 -6
- package/dist/js/modern/router/runtime/server.js +1 -0
- package/dist/js/modern/router/runtime/utils.js +2 -4
- package/dist/js/modern/ssr/cli/index.js +14 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/js/modern/state/cli/index.js +0 -1
- package/dist/js/modern/state/runtime/plugin.js +10 -3
- package/dist/js/node/cli/index.js +3 -1
- package/dist/js/node/core/compatible.js +4 -3
- package/dist/js/node/document/cli/index.js +10 -8
- package/dist/js/node/document/constants.js +1 -1
- package/dist/js/node/router/runtime/plugin.js +7 -6
- package/dist/js/node/router/runtime/plugin.node.js +9 -5
- package/dist/js/node/router/runtime/server.js +16 -0
- package/dist/js/node/router/runtime/utils.js +2 -4
- package/dist/js/node/ssr/cli/index.js +14 -0
- package/dist/js/node/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/js/node/state/cli/index.js +0 -1
- package/dist/js/node/state/runtime/plugin.js +10 -3
- package/dist/js/treeshaking/cli/index.js +3 -1
- package/dist/js/treeshaking/core/compatible.js +31 -41
- package/dist/js/treeshaking/document/cli/index.js +14 -9
- package/dist/js/treeshaking/document/constants.js +1 -1
- package/dist/js/treeshaking/router/runtime/plugin.js +9 -7
- package/dist/js/treeshaking/router/runtime/plugin.node.js +18 -13
- package/dist/js/treeshaking/router/runtime/server.js +1 -0
- package/dist/js/treeshaking/router/runtime/utils.js +2 -4
- package/dist/js/treeshaking/ssr/cli/index.js +15 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/js/treeshaking/state/cli/index.js +0 -1
- package/dist/js/treeshaking/state/runtime/plugin.js +14 -3
- package/dist/types/cli/index.d.ts +2 -2
- package/dist/types/core/compatible.d.ts +6 -8
- package/dist/types/core/plugin.d.ts +15 -15
- package/dist/types/document/cli/index.d.ts +2 -2
- package/dist/types/document/constants.d.ts +1 -1
- package/dist/types/router/cli/index.d.ts +2 -2
- package/dist/types/router/runtime/plugin.d.ts +1 -0
- package/dist/types/router/runtime/plugin.node.d.ts +1 -0
- package/dist/types/router/runtime/server.d.ts +1 -0
- package/dist/types/router/runtime/types.d.ts +1 -0
- package/dist/types/ssr/cli/index.d.ts +2 -2
- package/dist/types/ssr/serverRender/types.d.ts +2 -2
- package/dist/types/state/cli/index.d.ts +2 -2
- package/dist/types/state/runtime/plugin.d.ts +7 -2
- package/package.json +28 -27
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _server = require("react-router-dom/server");
|
|
7
|
+
Object.keys(_server).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _server[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _server[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -61,12 +61,10 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
if (!parent) {
|
|
64
|
+
if (!parent && element) {
|
|
65
65
|
element = /*#__PURE__*/(0, _jsxRuntime.jsx)(_root.RootLayout, {
|
|
66
66
|
routes: [nestedRoute],
|
|
67
|
-
children:
|
|
68
|
-
children: element
|
|
69
|
-
})
|
|
67
|
+
children: element
|
|
70
68
|
});
|
|
71
69
|
}
|
|
72
70
|
routeProps.element = element;
|
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _utils = require("@modern-js/utils");
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
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; }
|
|
8
11
|
const PLUGIN_IDENTIFIER = 'ssr';
|
|
9
12
|
const hasStringSSREntry = userConfig => {
|
|
10
13
|
const isStreaming = ssr => ssr && typeof ssr === 'object' && ssr.mode === 'stream';
|
|
@@ -42,6 +45,7 @@ var _default = () => ({
|
|
|
42
45
|
tools: {
|
|
43
46
|
webpackChain: (chain, {
|
|
44
47
|
name,
|
|
48
|
+
isServer,
|
|
45
49
|
CHAIN_ID
|
|
46
50
|
}) => {
|
|
47
51
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -52,6 +56,16 @@ var _default = () => ({
|
|
|
52
56
|
filename: _utils.LOADABLE_STATS_FILE
|
|
53
57
|
}]);
|
|
54
58
|
}
|
|
59
|
+
|
|
60
|
+
// add environment variables to determine the node/browser
|
|
61
|
+
const prefix = `${appContext.metaName.split(/[-_]/)[0]}_`.toUpperCase();
|
|
62
|
+
const modernVars = {
|
|
63
|
+
[`process.env.${prefix}TARGET`]: JSON.stringify(isServer ? 'node' : 'browser')
|
|
64
|
+
};
|
|
65
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(args => {
|
|
66
|
+
const [vars, ...rest] = args;
|
|
67
|
+
return [_objectSpread(_objectSpread({}, vars), modernVars), ...rest];
|
|
68
|
+
});
|
|
55
69
|
},
|
|
56
70
|
babel: config => {
|
|
57
71
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -40,7 +40,11 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
40
40
|
} = routeManifest;
|
|
41
41
|
const cssChunks = [];
|
|
42
42
|
const matches = (0, _reactRouterDom.matchRoutes)(routes, routerContext.location);
|
|
43
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(match => {
|
|
43
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
|
|
44
|
+
// root layout css chunks should't be loaded
|
|
45
|
+
if (!index) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
44
48
|
const routeId = match.route.id;
|
|
45
49
|
if (routeId) {
|
|
46
50
|
const {
|
|
@@ -38,9 +38,16 @@ const getStoreConfig = config => {
|
|
|
38
38
|
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
39
39
|
const plugins = [];
|
|
40
40
|
internalPlugins.filter(plugin => config[plugin] !== false).forEach(plugin => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const storeConfig = {};
|
|
42
|
+
for (const [key, value] of Object.entries(config)) {
|
|
43
|
+
if (internalPlugins.includes(key)) {
|
|
44
|
+
plugins.push(StatePluginHandleMap[key](value));
|
|
45
|
+
} else {
|
|
46
|
+
storeConfig[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
storeConfig.plugins = plugins;
|
|
50
|
+
return storeConfig;
|
|
44
51
|
};
|
|
45
52
|
const state = config => ({
|
|
46
53
|
name: '@modern-js/plugin-state',
|
|
@@ -5,7 +5,6 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
6
6
|
var _excluded = ["context"];
|
|
7
7
|
import React, { useContext, useMemo } from 'react';
|
|
8
|
-
import defaultReactDOM from 'react-dom';
|
|
9
8
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
10
9
|
import { RuntimeReactContext } from "../runtime-context";
|
|
11
10
|
import { runtime } from "./plugin";
|
|
@@ -94,30 +93,14 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
94
93
|
/**
|
|
95
94
|
* root.render need use root to run function
|
|
96
95
|
*/
|
|
97
|
-
root
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
context,
|
|
102
|
-
runInit,
|
|
103
|
-
isBrowser,
|
|
104
|
-
_ssrData$data,
|
|
105
|
-
_ssrData$data2,
|
|
106
|
-
ssrData,
|
|
107
|
-
loadersData,
|
|
108
|
-
initialLoadersState,
|
|
109
|
-
initialData,
|
|
110
|
-
_rootElement,
|
|
111
|
-
ModernRender,
|
|
112
|
-
ModernHydrate,
|
|
113
|
-
isRedirectResponse,
|
|
114
|
-
_initialData,
|
|
115
|
-
_args = arguments;
|
|
96
|
+
root, ReactDOM
|
|
97
|
+
// eslint-disable-next-line consistent-return
|
|
98
|
+
) {
|
|
99
|
+
var App, runner, context, runInit, isBrowser, _ssrData$data, _ssrData$data2, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate, isRedirectResponse, _initialData;
|
|
116
100
|
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
117
101
|
while (1) {
|
|
118
102
|
switch (_context2.prev = _context2.next) {
|
|
119
103
|
case 0:
|
|
120
|
-
ReactDOM = _args.length > 3 && _args[3] !== undefined ? _args[3] : defaultReactDOM;
|
|
121
104
|
App = BootApp;
|
|
122
105
|
runner = runnerMap.get(App); // ensure Component used is created by `createApp`
|
|
123
106
|
if (!runner) {
|
|
@@ -139,20 +122,20 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
139
122
|
});
|
|
140
123
|
}; // don't mount the App, let user in charge of it.
|
|
141
124
|
if (id) {
|
|
142
|
-
_context2.next =
|
|
125
|
+
_context2.next = 7;
|
|
143
126
|
break;
|
|
144
127
|
}
|
|
145
128
|
return _context2.abrupt("return", /*#__PURE__*/React.createElement(App, {
|
|
146
129
|
context: context
|
|
147
130
|
}));
|
|
148
|
-
case
|
|
131
|
+
case 7:
|
|
149
132
|
isBrowser = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
150
133
|
if (!isBrowser) {
|
|
151
|
-
_context2.next =
|
|
134
|
+
_context2.next = 30;
|
|
152
135
|
break;
|
|
153
136
|
}
|
|
154
137
|
if (!isClientArgs(id)) {
|
|
155
|
-
_context2.next =
|
|
138
|
+
_context2.next = 27;
|
|
156
139
|
break;
|
|
157
140
|
}
|
|
158
141
|
ssrData = window._SSR_DATA;
|
|
@@ -173,20 +156,27 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
173
156
|
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
174
157
|
} : {}));
|
|
175
158
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data2 = ssrData.data) === null || _ssrData$data2 === void 0 ? void 0 : _ssrData$data2.initialData;
|
|
176
|
-
_context2.next =
|
|
159
|
+
_context2.next = 17;
|
|
177
160
|
return runInit(context);
|
|
178
|
-
case
|
|
161
|
+
case 17:
|
|
179
162
|
initialData = _context2.sent;
|
|
180
163
|
if (initialData) {
|
|
181
164
|
context.initialData = initialData;
|
|
182
165
|
}
|
|
183
|
-
|
|
166
|
+
rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root');
|
|
167
|
+
if (ReactDOM) {
|
|
168
|
+
_context2.next = 22;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
throw Error('The `bootstrap` need provide `ReactDOM` parameter');
|
|
172
|
+
case 22:
|
|
173
|
+
// https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
|
|
184
174
|
ModernRender = function ModernRender(App) {
|
|
185
175
|
if (IS_REACT18) {
|
|
186
176
|
if (root) {
|
|
187
177
|
root.render(App);
|
|
188
178
|
} else if (ReactDOM.createRoot) {
|
|
189
|
-
ReactDOM.createRoot(
|
|
179
|
+
ReactDOM.createRoot(rootElement).render(App);
|
|
190
180
|
} else {
|
|
191
181
|
throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `createRoot` method');
|
|
192
182
|
}
|
|
@@ -194,7 +184,7 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
194
184
|
if (!ReactDOM.render) {
|
|
195
185
|
throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `render` method');
|
|
196
186
|
}
|
|
197
|
-
ReactDOM.render(App,
|
|
187
|
+
ReactDOM.render(App, rootElement);
|
|
198
188
|
}
|
|
199
189
|
};
|
|
200
190
|
ModernHydrate = function ModernHydrate(App, callback) {
|
|
@@ -202,12 +192,12 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
202
192
|
if (!ReactDOM.hydrateRoot) {
|
|
203
193
|
throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `hydrateRoot` method');
|
|
204
194
|
}
|
|
205
|
-
ReactDOM.hydrateRoot(
|
|
195
|
+
ReactDOM.hydrateRoot(rootElement, App);
|
|
206
196
|
} else {
|
|
207
197
|
if (!ReactDOM.hydrate) {
|
|
208
198
|
throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `hydrate` method');
|
|
209
199
|
}
|
|
210
|
-
ReactDOM.hydrate(App,
|
|
200
|
+
ReactDOM.hydrate(App, rootElement, callback);
|
|
211
201
|
}
|
|
212
202
|
};
|
|
213
203
|
return _context2.abrupt("return", runner.client({
|
|
@@ -223,12 +213,12 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
223
213
|
}));
|
|
224
214
|
}
|
|
225
215
|
}));
|
|
226
|
-
case 26:
|
|
227
|
-
throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
|
|
228
216
|
case 27:
|
|
229
|
-
|
|
217
|
+
throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
|
|
218
|
+
case 28:
|
|
219
|
+
_context2.next = 38;
|
|
230
220
|
break;
|
|
231
|
-
case
|
|
221
|
+
case 30:
|
|
232
222
|
Object.assign(context, {
|
|
233
223
|
ssrContext: id,
|
|
234
224
|
isBrowser: false,
|
|
@@ -257,12 +247,12 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
257
247
|
}
|
|
258
248
|
return false;
|
|
259
249
|
};
|
|
260
|
-
_context2.next =
|
|
250
|
+
_context2.next = 34;
|
|
261
251
|
return runInit(context);
|
|
262
|
-
case
|
|
252
|
+
case 34:
|
|
263
253
|
_initialData = _context2.sent;
|
|
264
254
|
if (isRedirectResponse(_initialData)) {
|
|
265
|
-
_context2.next =
|
|
255
|
+
_context2.next = 38;
|
|
266
256
|
break;
|
|
267
257
|
}
|
|
268
258
|
context.initialData = _initialData;
|
|
@@ -270,14 +260,14 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
270
260
|
App: App,
|
|
271
261
|
context: context
|
|
272
262
|
}));
|
|
273
|
-
case
|
|
263
|
+
case 38:
|
|
274
264
|
case "end":
|
|
275
265
|
return _context2.stop();
|
|
276
266
|
}
|
|
277
267
|
}
|
|
278
268
|
}, _callee);
|
|
279
269
|
}));
|
|
280
|
-
return function bootstrap(_x, _x2, _x3) {
|
|
270
|
+
return function bootstrap(_x, _x2, _x3, _x4) {
|
|
281
271
|
return _ref6.apply(this, arguments);
|
|
282
272
|
};
|
|
283
273
|
}();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
3
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
import ReactDomServer from 'react-dom/server';
|
|
@@ -9,14 +10,21 @@ import { createDebugger, findExists } from '@modern-js/utils';
|
|
|
9
10
|
import { DocumentContext } from "../DocumentContext";
|
|
10
11
|
import { DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_FILE_NAME, DOCUMENT_META_PLACEHOLDER, PLACEHOLDER_REPLACER_MAP, DOC_EXT, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, HTML_SEPARATOR } from "../constants";
|
|
11
12
|
var debug = createDebugger('html_genarate');
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
// get the entry document file,
|
|
15
|
+
// if not exist, fallback to src/
|
|
16
|
+
var getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
|
|
13
17
|
var _entrypoints$find;
|
|
14
18
|
var entryDir = (_entrypoints$find = entrypoints.find(function (item) {
|
|
15
19
|
return item.entryName === entryName;
|
|
16
20
|
})) === null || _entrypoints$find === void 0 ? void 0 : _entrypoints$find.absoluteEntryDir;
|
|
17
|
-
var
|
|
21
|
+
var entryDirs = DOC_EXT.map(function (item) {
|
|
18
22
|
return "".concat(entryDir).concat(path.sep).concat(DOCUMENT_FILE_NAME, ".").concat(item);
|
|
19
|
-
})
|
|
23
|
+
});
|
|
24
|
+
var fallbackDirs = fallbackDir ? DOC_EXT.map(function (item) {
|
|
25
|
+
return [fallbackDir, 'src', "".concat(DOCUMENT_FILE_NAME, ".").concat(item)].join(path.sep);
|
|
26
|
+
}) : [];
|
|
27
|
+
var docFile = findExists([].concat(_toConsumableArray(entryDirs), _toConsumableArray(fallbackDirs)));
|
|
20
28
|
return docFile || undefined;
|
|
21
29
|
};
|
|
22
30
|
export default (function () {
|
|
@@ -47,13 +55,10 @@ export default (function () {
|
|
|
47
55
|
documentEntry = function documentEntry(entryName, templateParameters) {
|
|
48
56
|
var _api$useAppContext = api.useAppContext(),
|
|
49
57
|
entrypoints = _api$useAppContext.entrypoints,
|
|
50
|
-
internalDirectory = _api$useAppContext.internalDirectory
|
|
58
|
+
internalDirectory = _api$useAppContext.internalDirectory,
|
|
59
|
+
appDirectory = _api$useAppContext.appDirectory;
|
|
51
60
|
// search the document.[tsx|jsx|js|ts] under entry
|
|
52
|
-
|
|
53
|
-
var documentFilePath = getDocumenByEntryName(entrypoints, entryName);
|
|
54
|
-
if (!documentFilePath) {
|
|
55
|
-
documentFilePath = getDocumenByEntryName(entrypoints, 'main');
|
|
56
|
-
}
|
|
61
|
+
var documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
|
|
57
62
|
// if no document file, do nothing as default
|
|
58
63
|
if (!documentFilePath) {
|
|
59
64
|
return null;
|
|
@@ -10,7 +10,7 @@ export var HTML_SSRDATASCRIPT_SEPARATOR = '<!--<?- SSRDataScript ?>-->';
|
|
|
10
10
|
export var DOCUMENT_SSR_PLACEHOLDER = encodeURIComponent(HTML_SEPARATOR);
|
|
11
11
|
export var DOCUMENT_CHUNKSMAP_PLACEHOLDER = encodeURIComponent(HTML_CHUNKSMAP_SEPARATOR);
|
|
12
12
|
export var DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = encodeURIComponent(HTML_SSRDATASCRIPT_SEPARATOR);
|
|
13
|
-
export var DOCUMENT_FILE_NAME = '
|
|
13
|
+
export var DOCUMENT_FILE_NAME = 'Document';
|
|
14
14
|
export var DOCUMENT_SCRIPTS_PLACEHOLDER = encodeURIComponent('<!-- chunk scripts placeholder -->');
|
|
15
15
|
export var DOCUMENT_NO_SCRIPTE_PLACEHOLDER = encodeURIComponent('<!-- no-script -->');
|
|
16
16
|
export var PLACEHOLDER_REPLACER_MAP = (_PLACEHOLDER_REPLACER = {}, _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_NO_SCRIPTE_PLACEHOLDER, "We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue."), _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_SSR_PLACEHOLDER, HTML_SEPARATOR), _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, HTML_CHUNKSMAP_SEPARATOR), _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, HTML_SSRDATASCRIPT_SEPARATOR), _PLACEHOLDER_REPLACER);
|
|
@@ -2,13 +2,15 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements } from 'react-router-dom';
|
|
4
4
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
5
|
-
import { renderRoutes } from "./utils";
|
|
5
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
export var routerPlugin = function routerPlugin(_ref) {
|
|
8
8
|
var _ref$serverBase = _ref.serverBase,
|
|
9
9
|
serverBase = _ref$serverBase === void 0 ? [] : _ref$serverBase,
|
|
10
10
|
_ref$supportHtml5Hist = _ref.supportHtml5History,
|
|
11
11
|
supportHtml5History = _ref$supportHtml5Hist === void 0 ? true : _ref$supportHtml5Hist,
|
|
12
|
+
_ref$basename = _ref.basename,
|
|
13
|
+
basename = _ref$basename === void 0 ? '' : _ref$basename,
|
|
12
14
|
routesConfig = _ref.routesConfig,
|
|
13
15
|
createRoutes = _ref.createRoutes;
|
|
14
16
|
var select = function select(pathname) {
|
|
@@ -24,7 +26,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
24
26
|
var App = _ref2.App;
|
|
25
27
|
// can not get routes config, skip wrapping React Router.
|
|
26
28
|
// e.g. App.tsx as the entrypoint
|
|
27
|
-
if (!routesConfig) {
|
|
29
|
+
if (!routesConfig && !createRoutes) {
|
|
28
30
|
return next({
|
|
29
31
|
App: App
|
|
30
32
|
});
|
|
@@ -32,13 +34,13 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
32
34
|
var getRouteApp = function getRouteApp() {
|
|
33
35
|
return function (props) {
|
|
34
36
|
var _window$_SERVER_DATA;
|
|
35
|
-
var
|
|
36
|
-
var routes = createRoutes ? createRoutes() : createRoutesFromElements(routeElements);
|
|
37
|
+
var routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(routesConfig));
|
|
37
38
|
var baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
39
|
+
var _basename = baseUrl === '/' ? urlJoin(baseUrl, basename) : baseUrl;
|
|
38
40
|
var router = supportHtml5History ? createBrowserRouter(routes, {
|
|
39
|
-
basename:
|
|
41
|
+
basename: _basename
|
|
40
42
|
}) : createHashRouter(routes, {
|
|
41
|
-
basename:
|
|
43
|
+
basename: _basename
|
|
42
44
|
});
|
|
43
45
|
return /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, props), {}, {
|
|
44
46
|
children: /*#__PURE__*/_jsx(RouterProvider, {
|
|
@@ -48,7 +50,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
48
50
|
};
|
|
49
51
|
};
|
|
50
52
|
var RouteApp = getRouteApp();
|
|
51
|
-
if (routesConfig.globalApp) {
|
|
53
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
52
54
|
return next({
|
|
53
55
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
54
56
|
});
|
|
@@ -10,7 +10,7 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
10
10
|
import { installGlobals } from '@remix-run/node';
|
|
11
11
|
import { createRoutesFromElements } from 'react-router-dom';
|
|
12
12
|
import { RuntimeReactContext } from "../../core";
|
|
13
|
-
import { renderRoutes } from "./utils";
|
|
13
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
14
14
|
|
|
15
15
|
// Polyfill Web Fetch API
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -68,7 +68,9 @@ export function createFetchHeaders(requestHeaders) {
|
|
|
68
68
|
return headers;
|
|
69
69
|
}
|
|
70
70
|
export var routerPlugin = function routerPlugin(_ref) {
|
|
71
|
-
var
|
|
71
|
+
var _ref$basename = _ref.basename,
|
|
72
|
+
basename = _ref$basename === void 0 ? '' : _ref$basename,
|
|
73
|
+
routesConfig = _ref.routesConfig,
|
|
72
74
|
createRoutes = _ref.createRoutes;
|
|
73
75
|
return {
|
|
74
76
|
name: '@modern-js/plugin-router',
|
|
@@ -76,13 +78,13 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
76
78
|
return {
|
|
77
79
|
init: function init(_ref2, next) {
|
|
78
80
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
79
|
-
var context, _ref3, request,
|
|
81
|
+
var context, _ref3, request, baseUrl, _basename, routes, _createStaticHandler, query, remixRequest, routerContext, router;
|
|
80
82
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
81
83
|
while (1) {
|
|
82
84
|
switch (_context.prev = _context.next) {
|
|
83
85
|
case 0:
|
|
84
86
|
context = _ref2.context;
|
|
85
|
-
if (routesConfig) {
|
|
87
|
+
if (!(!routesConfig && !createRoutes)) {
|
|
86
88
|
_context.next = 3;
|
|
87
89
|
break;
|
|
88
90
|
}
|
|
@@ -91,20 +93,23 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
91
93
|
}));
|
|
92
94
|
case 3:
|
|
93
95
|
_ref3 = context.ssrContext, request = _ref3.request;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
baseUrl = request.baseUrl;
|
|
97
|
+
_basename = baseUrl === '/' ? urlJoin(baseUrl, basename) : baseUrl;
|
|
98
|
+
routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(routesConfig));
|
|
99
|
+
_createStaticHandler = createStaticHandler(routes, {
|
|
100
|
+
basename: _basename
|
|
101
|
+
}), query = _createStaticHandler.query;
|
|
97
102
|
remixRequest = createFetchRequest(request);
|
|
98
|
-
_context.next =
|
|
103
|
+
_context.next = 11;
|
|
99
104
|
return query(remixRequest);
|
|
100
|
-
case
|
|
105
|
+
case 11:
|
|
101
106
|
routerContext = _context.sent;
|
|
102
107
|
if (!(routerContext instanceof Response)) {
|
|
103
|
-
_context.next =
|
|
108
|
+
_context.next = 14;
|
|
104
109
|
break;
|
|
105
110
|
}
|
|
106
111
|
return _context.abrupt("return", routerContext);
|
|
107
|
-
case
|
|
112
|
+
case 14:
|
|
108
113
|
router = createStaticRouter(routes, routerContext);
|
|
109
114
|
context.router = router;
|
|
110
115
|
context.routerContext = routerContext;
|
|
@@ -114,7 +119,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
114
119
|
return _context.abrupt("return", next({
|
|
115
120
|
context: context
|
|
116
121
|
}));
|
|
117
|
-
case
|
|
122
|
+
case 20:
|
|
118
123
|
case "end":
|
|
119
124
|
return _context.stop();
|
|
120
125
|
}
|
|
@@ -146,7 +151,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
146
151
|
};
|
|
147
152
|
};
|
|
148
153
|
var RouteApp = getRouteApp();
|
|
149
|
-
if (routesConfig.globalApp) {
|
|
154
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
150
155
|
return next({
|
|
151
156
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
152
157
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom/server';
|
|
@@ -45,12 +45,10 @@ var renderNestedRoute = function renderNestedRoute(nestedRoute, parent) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
if (!parent) {
|
|
48
|
+
if (!parent && element) {
|
|
49
49
|
element = /*#__PURE__*/_jsx(RootLayout, {
|
|
50
50
|
routes: [nestedRoute],
|
|
51
|
-
children:
|
|
52
|
-
children: element
|
|
53
|
-
})
|
|
51
|
+
children: element
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
routeProps.element = element;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
5
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
6
|
import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSingleEntry } from '@modern-js/utils';
|
|
3
7
|
var PLUGIN_IDENTIFIER = 'ssr';
|
|
@@ -39,6 +43,7 @@ export default (function () {
|
|
|
39
43
|
tools: {
|
|
40
44
|
webpackChain: function webpackChain(chain, _ref) {
|
|
41
45
|
var name = _ref.name,
|
|
46
|
+
isServer = _ref.isServer,
|
|
42
47
|
CHAIN_ID = _ref.CHAIN_ID;
|
|
43
48
|
var userConfig = api.useResolvedConfigContext();
|
|
44
49
|
if (isUseSSRBundle(userConfig) && name !== 'server' && hasStringSSREntry(userConfig)) {
|
|
@@ -48,6 +53,16 @@ export default (function () {
|
|
|
48
53
|
filename: LOADABLE_STATS_FILE
|
|
49
54
|
}]);
|
|
50
55
|
}
|
|
56
|
+
|
|
57
|
+
// add environment variables to determine the node/browser
|
|
58
|
+
var prefix = "".concat(appContext.metaName.split(/[-_]/)[0], "_").toUpperCase();
|
|
59
|
+
var modernVars = _defineProperty({}, "process.env.".concat(prefix, "TARGET"), JSON.stringify(isServer ? 'node' : 'browser'));
|
|
60
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(function (args) {
|
|
61
|
+
var _args = _toArray(args),
|
|
62
|
+
vars = _args[0],
|
|
63
|
+
rest = _args.slice(1);
|
|
64
|
+
return [_objectSpread(_objectSpread({}, vars), modernVars)].concat(_toConsumableArray(rest));
|
|
65
|
+
});
|
|
51
66
|
},
|
|
52
67
|
babel: function babel(config) {
|
|
53
68
|
var userConfig = api.useResolvedConfigContext();
|
|
@@ -34,7 +34,11 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
34
34
|
var routeAssets = routeManifest.routeAssets;
|
|
35
35
|
var cssChunks = [];
|
|
36
36
|
var matches = matchRoutes(routes, routerContext.location);
|
|
37
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(function (match) {
|
|
37
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach(function (match, index) {
|
|
38
|
+
// root layout css chunks should't be loaded
|
|
39
|
+
if (!index) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
38
42
|
var routeId = match.route.id;
|
|
39
43
|
if (routeId) {
|
|
40
44
|
var _routeAssets$routeId$ = routeAssets[routeId].assets,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import { useContext } from 'react';
|
|
3
4
|
import { createStore } from '@modern-js-reduck/store';
|
|
4
5
|
import { Provider } from '@modern-js-reduck/react';
|
|
@@ -21,9 +22,19 @@ var getStoreConfig = function getStoreConfig(config) {
|
|
|
21
22
|
}).forEach(function (plugin) {
|
|
22
23
|
return plugins.push(StatePluginHandleMap[plugin](config[plugin]));
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
var storeConfig = {};
|
|
26
|
+
for (var _i = 0, _Object$entries = Object.entries(config); _i < _Object$entries.length; _i++) {
|
|
27
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
28
|
+
key = _Object$entries$_i[0],
|
|
29
|
+
value = _Object$entries$_i[1];
|
|
30
|
+
if (internalPlugins.includes(key)) {
|
|
31
|
+
plugins.push(StatePluginHandleMap[key](value));
|
|
32
|
+
} else {
|
|
33
|
+
storeConfig[key] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
storeConfig.plugins = plugins;
|
|
37
|
+
return storeConfig;
|
|
27
38
|
};
|
|
28
39
|
var state = function state(config) {
|
|
29
40
|
return {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CliPlugin } from '@modern-js/
|
|
2
|
-
declare const _default: () => CliPlugin
|
|
1
|
+
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
|
2
|
+
declare const _default: () => CliPlugin<AppTools>;
|
|
3
3
|
export default _default;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { Renderer } from 'react-dom';
|
|
3
|
+
import type { hydrateRoot, createRoot } from 'react-dom/client';
|
|
2
4
|
import { RuntimeContext, TRuntimeContext } from '../runtime-context';
|
|
3
5
|
import { Plugin } from './plugin';
|
|
4
6
|
export declare type CreateAppOptions = {
|
|
@@ -7,15 +9,11 @@ export declare type CreateAppOptions = {
|
|
|
7
9
|
export declare const createApp: ({
|
|
8
10
|
plugins
|
|
9
11
|
}: CreateAppOptions) => (App?: React.ComponentType<any>) => React.ComponentType<any>;
|
|
10
|
-
interface HydrateFunc {
|
|
11
|
-
(container: Element | Document, initialChildren: React.ReactNode): void;
|
|
12
|
-
(initialChildren: React.ReactNode, container: Element | Document, callback?: () => void): void;
|
|
13
|
-
}
|
|
14
12
|
declare type BootStrap<T = unknown> = (App: React.ComponentType, id: string | HTMLElement | RuntimeContext, root?: any, ReactDOM?: {
|
|
15
|
-
render?:
|
|
16
|
-
hydrate?:
|
|
17
|
-
createRoot?:
|
|
18
|
-
hydrateRoot?:
|
|
13
|
+
render?: Renderer;
|
|
14
|
+
hydrate?: Renderer;
|
|
15
|
+
createRoot?: typeof createRoot;
|
|
16
|
+
hydrateRoot?: typeof hydrateRoot;
|
|
19
17
|
}) => Promise<T>;
|
|
20
18
|
export declare const bootstrap: BootStrap;
|
|
21
19
|
export declare const useRuntimeContext: () => TRuntimeContext;
|