@modern-js/app-tools 2.7.1-alpha.0 → 2.8.1-alpha.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 +53 -2
- package/dist/cjs/analyze/generateCode.js +13 -0
- package/dist/cjs/analyze/index.js +0 -37
- package/dist/cjs/analyze/templates.js +56 -15
- package/dist/cjs/analyze/utils.js +14 -1
- package/dist/cjs/builder/index.js +1 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +25 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm/analyze/generateCode.js +30 -16
- package/dist/esm/analyze/index.js +2 -26
- package/dist/esm/analyze/templates.js +44 -17
- package/dist/esm/analyze/utils.js +9 -2
- package/dist/esm/builder/index.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +241 -22
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/esm-node/analyze/generateCode.js +18 -1
- package/dist/esm-node/analyze/index.js +2 -46
- package/dist/esm-node/analyze/templates.js +55 -15
- package/dist/esm-node/analyze/utils.js +13 -1
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +25 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
- package/dist/types/analyze/templates.d.ts +3 -2
- package/dist/types/analyze/utils.d.ts +2 -1
- package/package.json +26 -26
|
@@ -221,8 +221,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import path from "path";
|
|
224
|
-
import { fs, slash } from "@modern-js/utils";
|
|
224
|
+
import { fs, getEntryOptions, isSSGEntry, slash } from "@modern-js/utils";
|
|
225
225
|
import { APP_CONFIG_NAME, TEMP_LOADERS_DIR } from "./constants";
|
|
226
|
+
import { getServerLoadersFile } from "./utils";
|
|
226
227
|
var index = function(param) {
|
|
227
228
|
var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
|
|
228
229
|
return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
|
|
@@ -297,16 +298,16 @@ var routesForServer = function(param) {
|
|
|
297
298
|
};
|
|
298
299
|
var fileSystemRoutes = function() {
|
|
299
300
|
var _ref = _asyncToGenerator(function(param) {
|
|
300
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRoutesChunks, splitRoutesChunks, loadings, errors, loaders, loadersMap,
|
|
301
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRoutesChunks, splitRoutesChunks, components, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importComponentsCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
|
301
302
|
return __generator(this, function(_state) {
|
|
302
303
|
switch(_state.label){
|
|
303
304
|
case 0:
|
|
304
305
|
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory, _param_splitRoutesChunks = param.splitRoutesChunks, splitRoutesChunks = _param_splitRoutesChunks === void 0 ? true : _param_splitRoutesChunks;
|
|
306
|
+
components = [];
|
|
305
307
|
loadings = [];
|
|
306
308
|
errors = [];
|
|
307
309
|
loaders = [];
|
|
308
310
|
loadersMap = {};
|
|
309
|
-
webpackMode = splitRoutesChunks ? "lazy" : "eager";
|
|
310
311
|
loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
|
|
311
312
|
importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
|
|
312
313
|
rootLayoutCode = "";
|
|
@@ -351,20 +352,30 @@ var fileSystemRoutes = function() {
|
|
|
351
352
|
};
|
|
352
353
|
}
|
|
353
354
|
if (route._component) {
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
if (splitRoutesChunks) {
|
|
356
|
+
if (route.isRoot) {
|
|
357
|
+
rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
|
|
358
|
+
component = "RootLayout";
|
|
359
|
+
} else if (ssrMode === "string") {
|
|
360
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
361
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
362
|
+
} else {
|
|
363
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
364
|
+
component = "lazy(".concat(lazyImport, ")");
|
|
365
|
+
}
|
|
360
366
|
} else {
|
|
361
|
-
|
|
362
|
-
component = "
|
|
367
|
+
components.push(route._component);
|
|
368
|
+
component = "component_".concat(components.length - 1);
|
|
363
369
|
}
|
|
364
370
|
}
|
|
365
371
|
} else if (route._component) {
|
|
366
|
-
|
|
367
|
-
|
|
372
|
+
if (splitRoutesChunks) {
|
|
373
|
+
lazyImport = "() => import('".concat(route._component, "')");
|
|
374
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
375
|
+
} else {
|
|
376
|
+
components.push(route._component);
|
|
377
|
+
component = "component_".concat(components.length - 1);
|
|
378
|
+
}
|
|
368
379
|
}
|
|
369
380
|
var finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
370
381
|
lazyImport: lazyImport,
|
|
@@ -385,13 +396,13 @@ var fileSystemRoutes = function() {
|
|
|
385
396
|
route = _step.value;
|
|
386
397
|
if ("type" in route) {
|
|
387
398
|
newRoute = traverseRouteTree(route);
|
|
388
|
-
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"'), ",");
|
|
399
|
+
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/("component":\s)"([^"]+)"/g, "$1$2").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"'), ",");
|
|
389
400
|
} else {
|
|
390
401
|
component = "loadable(() => import('".concat(route._component, "'))");
|
|
391
402
|
finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
392
403
|
component: component
|
|
393
404
|
});
|
|
394
|
-
routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$
|
|
405
|
+
routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2"), ",");
|
|
395
406
|
}
|
|
396
407
|
}
|
|
397
408
|
} catch (err) {
|
|
@@ -412,6 +423,9 @@ var fileSystemRoutes = function() {
|
|
|
412
423
|
importLoadingCode = loadings.map(function(loading, index2) {
|
|
413
424
|
return "import loading_".concat(index2, " from '").concat(loading, "';\n");
|
|
414
425
|
}).join("");
|
|
426
|
+
importComponentsCode = components.map(function(component, index2) {
|
|
427
|
+
return "import component_".concat(index2, " from '").concat(component, "';\n");
|
|
428
|
+
}).join("");
|
|
415
429
|
importErrorComponentsCode = errors.map(function(error, index2) {
|
|
416
430
|
return "import error_".concat(index2, " from '").concat(error, "';\n");
|
|
417
431
|
}).join("");
|
|
@@ -454,7 +468,7 @@ var fileSystemRoutes = function() {
|
|
|
454
468
|
_state.sent();
|
|
455
469
|
return [
|
|
456
470
|
2,
|
|
457
|
-
"\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
471
|
+
"\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
458
472
|
];
|
|
459
473
|
}
|
|
460
474
|
});
|
|
@@ -463,4 +477,17 @@ var fileSystemRoutes = function() {
|
|
|
463
477
|
return _ref.apply(this, arguments);
|
|
464
478
|
};
|
|
465
479
|
}();
|
|
466
|
-
|
|
480
|
+
function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
481
|
+
var entryName = entrypoint.entryName;
|
|
482
|
+
var packageName = appContext.packageName, internalDirectory = appContext.internalDirectory;
|
|
483
|
+
var ssr = getEntryOptions(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
|
|
484
|
+
var ssg = isSSGEntry(config, entryName, entrypoints);
|
|
485
|
+
if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
|
|
486
|
+
var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
487
|
+
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
488
|
+
var combinedModule = 'export * from "'.concat(slash(serverLoaderRuntime), '"; export * from "').concat(slash(serverLoadersFile), '"');
|
|
489
|
+
return combinedModule;
|
|
490
|
+
}
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
export { fileSystemRoutes, html, index, renderFunction, routesForServer, ssrLoaderCombinedModule };
|
|
@@ -287,7 +287,11 @@ var isPageComponentFile = function(filePath) {
|
|
|
287
287
|
return false;
|
|
288
288
|
};
|
|
289
289
|
var replaceWithAlias = function(base, filePath, alias) {
|
|
290
|
-
|
|
290
|
+
if (filePath.includes(base)) {
|
|
291
|
+
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
292
|
+
} else {
|
|
293
|
+
return filePath;
|
|
294
|
+
}
|
|
291
295
|
};
|
|
292
296
|
var parseModule = function() {
|
|
293
297
|
var _ref = _asyncToGenerator(function(param) {
|
|
@@ -371,4 +375,7 @@ var hasLoader = function() {
|
|
|
371
375
|
var getServerLoadersFile = function(internalDirectory, entryName) {
|
|
372
376
|
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
373
377
|
};
|
|
374
|
-
|
|
378
|
+
var getServerCombinedModueFile = function(internalDirectory, entryName) {
|
|
379
|
+
return path.join(internalDirectory, entryName, "server-loader-combined.js");
|
|
380
|
+
};
|
|
381
|
+
export { getDefaultImports, getServerCombinedModueFile, getServerLoadersFile, hasLoader, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -155,7 +155,7 @@ function _createBuilderGenerator() {
|
|
|
155
155
|
];
|
|
156
156
|
case 3:
|
|
157
157
|
_ = _state.sent();
|
|
158
|
-
throw new Error("Failed to use
|
|
158
|
+
throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
|
|
159
159
|
case 4:
|
|
160
160
|
return [
|
|
161
161
|
4,
|
|
@@ -1,5 +1,131 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return(g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g);
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
1
125
|
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
126
|
+
import { fs } from "@modern-js/utils";
|
|
2
127
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
|
128
|
+
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
|
3
129
|
import { isHtmlEnabled } from "./adapterHtml";
|
|
4
130
|
var builderPluginAdapterSSR = function(options) {
|
|
5
131
|
return {
|
|
@@ -16,29 +142,49 @@ var builderPluginAdapterSSR = function(options) {
|
|
|
16
142
|
}
|
|
17
143
|
return config;
|
|
18
144
|
});
|
|
19
|
-
api.modifyBundlerChain(function(
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
145
|
+
api.modifyBundlerChain(function() {
|
|
146
|
+
var _ref = _asyncToGenerator(function(chain, param) {
|
|
147
|
+
var target, CHAIN_ID, isProd, HtmlBundlerPlugin, isServer, builderConfig;
|
|
148
|
+
return __generator(this, function(_state) {
|
|
149
|
+
switch(_state.label){
|
|
150
|
+
case 0:
|
|
151
|
+
target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
|
|
152
|
+
builderConfig = api.getNormalizedConfig();
|
|
153
|
+
applyRouterPlugin(chain, options);
|
|
154
|
+
return [
|
|
155
|
+
4,
|
|
156
|
+
applySSRLoaderEntry(chain, options, isServer)
|
|
157
|
+
];
|
|
158
|
+
case 1:
|
|
159
|
+
_state.sent();
|
|
160
|
+
if ([
|
|
161
|
+
"node",
|
|
162
|
+
"service-worker"
|
|
163
|
+
].includes(target)) {
|
|
164
|
+
applyFilterEntriesBySSRConfig({
|
|
165
|
+
isProd: isProd,
|
|
166
|
+
chain: chain,
|
|
167
|
+
appNormalizedConfig: options.normalizedConfig
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (isHtmlEnabled(builderConfig, target)) {
|
|
171
|
+
applyAsyncChunkHtmlPlugin({
|
|
172
|
+
chain: chain,
|
|
173
|
+
modernConfig: options.normalizedConfig,
|
|
174
|
+
CHAIN_ID: CHAIN_ID,
|
|
175
|
+
HtmlBundlerPlugin: HtmlBundlerPlugin
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return [
|
|
179
|
+
2
|
|
180
|
+
];
|
|
181
|
+
}
|
|
39
182
|
});
|
|
40
|
-
}
|
|
41
|
-
|
|
183
|
+
});
|
|
184
|
+
return function(chain, _) {
|
|
185
|
+
return _ref.apply(this, arguments);
|
|
186
|
+
};
|
|
187
|
+
}());
|
|
42
188
|
}
|
|
43
189
|
};
|
|
44
190
|
};
|
|
@@ -128,4 +274,77 @@ function applyFilterEntriesBySSRConfig(param) {
|
|
|
128
274
|
}
|
|
129
275
|
});
|
|
130
276
|
}
|
|
277
|
+
function applySSRLoaderEntry(chain, optinos, isServer) {
|
|
278
|
+
return _applySSRLoaderEntry.apply(this, arguments);
|
|
279
|
+
}
|
|
280
|
+
function _applySSRLoaderEntry() {
|
|
281
|
+
_applySSRLoaderEntry = _asyncToGenerator(function(chain, optinos, isServer) {
|
|
282
|
+
var appContext, internalDirectory, entrypoints;
|
|
283
|
+
return __generator(this, function(_state) {
|
|
284
|
+
switch(_state.label){
|
|
285
|
+
case 0:
|
|
286
|
+
appContext = optinos.appContext;
|
|
287
|
+
internalDirectory = appContext.internalDirectory;
|
|
288
|
+
entrypoints = appContext.entrypoints;
|
|
289
|
+
return [
|
|
290
|
+
4,
|
|
291
|
+
Promise.all(entrypoints.map(function() {
|
|
292
|
+
var _ref = _asyncToGenerator(function(entrypoint) {
|
|
293
|
+
var entryName, serverLoadersFile, err;
|
|
294
|
+
return __generator(this, function(_state) {
|
|
295
|
+
switch(_state.label){
|
|
296
|
+
case 0:
|
|
297
|
+
entryName = entrypoint.entryName;
|
|
298
|
+
serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
|
|
299
|
+
if (!isServer) return [
|
|
300
|
+
3,
|
|
301
|
+
4
|
|
302
|
+
];
|
|
303
|
+
_state.label = 1;
|
|
304
|
+
case 1:
|
|
305
|
+
_state.trys.push([
|
|
306
|
+
1,
|
|
307
|
+
3,
|
|
308
|
+
,
|
|
309
|
+
4
|
|
310
|
+
]);
|
|
311
|
+
return [
|
|
312
|
+
4,
|
|
313
|
+
fs.access(serverLoadersFile, fs.constants.F_OK)
|
|
314
|
+
];
|
|
315
|
+
case 2:
|
|
316
|
+
_state.sent();
|
|
317
|
+
chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
|
|
318
|
+
return [
|
|
319
|
+
3,
|
|
320
|
+
4
|
|
321
|
+
];
|
|
322
|
+
case 3:
|
|
323
|
+
err = _state.sent();
|
|
324
|
+
return [
|
|
325
|
+
3,
|
|
326
|
+
4
|
|
327
|
+
];
|
|
328
|
+
case 4:
|
|
329
|
+
return [
|
|
330
|
+
2
|
|
331
|
+
];
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
return function(entrypoint) {
|
|
336
|
+
return _ref.apply(this, arguments);
|
|
337
|
+
};
|
|
338
|
+
}()))
|
|
339
|
+
];
|
|
340
|
+
case 1:
|
|
341
|
+
_state.sent();
|
|
342
|
+
return [
|
|
343
|
+
2
|
|
344
|
+
];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
return _applySSRLoaderEntry.apply(this, arguments);
|
|
349
|
+
}
|
|
131
350
|
export { builderPluginAdapterSSR };
|
|
@@ -303,6 +303,9 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
303
303
|
for(_iterator1 = entryChunkFiles[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
304
304
|
file = _step1.value;
|
|
305
305
|
asset = compilation.assets[file];
|
|
306
|
+
if (!asset) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
306
309
|
newContent = "".concat(injectedContent).concat(asset.source().toString());
|
|
307
310
|
newAssetsMap.set(path.join(outputPath, file), newContent);
|
|
308
311
|
compilation.updateAsset(file, new RawSource(newContent), // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
|
@@ -14,7 +14,11 @@ import {
|
|
|
14
14
|
ENTRY_POINT_FILE_NAME,
|
|
15
15
|
ENTRY_BOOTSTRAP_FILE_NAME
|
|
16
16
|
} from "./constants";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getDefaultImports,
|
|
19
|
+
getServerLoadersFile,
|
|
20
|
+
getServerCombinedModueFile
|
|
21
|
+
} from "./utils";
|
|
18
22
|
import { walk } from "./nestedRoutes";
|
|
19
23
|
const createImportSpecifier = (specifiers) => {
|
|
20
24
|
let defaults = "";
|
|
@@ -155,6 +159,19 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
155
159
|
await fs.ensureFile(routesServerFile);
|
|
156
160
|
await fs.writeFile(routesServerFile, code3);
|
|
157
161
|
}
|
|
162
|
+
const serverLoaderCombined = templates.ssrLoaderCombinedModule(
|
|
163
|
+
entrypoints,
|
|
164
|
+
entrypoint,
|
|
165
|
+
config2,
|
|
166
|
+
appContext
|
|
167
|
+
);
|
|
168
|
+
if (serverLoaderCombined) {
|
|
169
|
+
const serverLoaderFile = getServerCombinedModueFile(
|
|
170
|
+
internalDirectory,
|
|
171
|
+
entryName
|
|
172
|
+
);
|
|
173
|
+
await fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
174
|
+
}
|
|
158
175
|
fs.outputFileSync(
|
|
159
176
|
path.resolve(
|
|
160
177
|
internalDirectory,
|
|
@@ -3,27 +3,19 @@ import {
|
|
|
3
3
|
createDebugger,
|
|
4
4
|
findExists,
|
|
5
5
|
fs,
|
|
6
|
-
getEntryOptions,
|
|
7
6
|
isApiOnly,
|
|
8
7
|
minimist,
|
|
9
8
|
getCommand,
|
|
10
|
-
isDevCommand
|
|
11
|
-
isSSGEntry
|
|
9
|
+
isDevCommand
|
|
12
10
|
} from "@modern-js/utils";
|
|
13
11
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
14
|
-
import { createVirtualModule } from "@modern-js/builder-shared";
|
|
15
12
|
import { printInstructions } from "../utils/printInstructions";
|
|
16
13
|
import { generateRoutes } from "../utils/routes";
|
|
17
14
|
import { emitResolvedConfig } from "../utils/config";
|
|
18
15
|
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
19
16
|
import { initialNormalizedConfig } from "../config";
|
|
20
17
|
import { createBuilderGenerator } from "../builder";
|
|
21
|
-
import {
|
|
22
|
-
getServerLoadersFile,
|
|
23
|
-
isPageComponentFile,
|
|
24
|
-
parseModule,
|
|
25
|
-
replaceWithAlias
|
|
26
|
-
} from "./utils";
|
|
18
|
+
import { isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
27
19
|
import {
|
|
28
20
|
APP_CONFIG_NAME,
|
|
29
21
|
APP_INIT_EXPORTED,
|
|
@@ -177,42 +169,6 @@ var analyze_default = ({
|
|
|
177
169
|
watchFiles() {
|
|
178
170
|
return pagesDir;
|
|
179
171
|
},
|
|
180
|
-
config() {
|
|
181
|
-
return {
|
|
182
|
-
tools: {
|
|
183
|
-
webpackChain: (chain, { name }) => {
|
|
184
|
-
const appContext = api.useAppContext();
|
|
185
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
|
186
|
-
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
187
|
-
entrypoints.forEach((entrypoint) => {
|
|
188
|
-
const { entryName } = entrypoint;
|
|
189
|
-
const ssr = getEntryOptions(
|
|
190
|
-
entryName,
|
|
191
|
-
resolvedConfig.server.ssr,
|
|
192
|
-
resolvedConfig.server.ssrByEntries,
|
|
193
|
-
packageName
|
|
194
|
-
);
|
|
195
|
-
const useSSG = isSSGEntry(
|
|
196
|
-
resolvedConfig,
|
|
197
|
-
entryName,
|
|
198
|
-
entrypoints
|
|
199
|
-
);
|
|
200
|
-
if (entrypoint.nestedRoutesEntry && (ssr || useSSG) && name === "server") {
|
|
201
|
-
const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
202
|
-
const serverLoadersFile = getServerLoadersFile(
|
|
203
|
-
internalDirectory,
|
|
204
|
-
entryName
|
|
205
|
-
);
|
|
206
|
-
const combinedModule = createVirtualModule(
|
|
207
|
-
`export * from "${serverLoaderRuntime}"; export * from "${serverLoadersFile}"`
|
|
208
|
-
);
|
|
209
|
-
chain.entry(`${entryName}-server-loaders`).add(combinedModule);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
},
|
|
216
172
|
resolvedConfig({ resolved }) {
|
|
217
173
|
const appContext = api.useAppContext();
|
|
218
174
|
const config = initialNormalizedConfig(resolved, appContext, bundler);
|