@modern-js/app-tools 2.8.1-alpha.0 → 2.8.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/analyze/generateCode.js +1 -3
- package/dist/cjs/analyze/index.js +0 -8
- package/dist/cjs/analyze/templates.js +14 -31
- package/dist/cjs/builder/index.js +2 -0
- package/dist/esm/analyze/generateCode.js +2 -3
- package/dist/esm/analyze/index.js +0 -8
- package/dist/esm/analyze/templates.js +16 -30
- package/dist/esm/builder/index.js +2 -0
- package/dist/esm-node/analyze/generateCode.js +1 -3
- package/dist/esm-node/analyze/index.js +0 -8
- package/dist/esm-node/analyze/templates.js +14 -31
- package/dist/esm-node/builder/index.js +2 -0
- package/dist/js/modern/analyze/constants.js +3 -1
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +47 -46
- package/dist/js/modern/analyze/nestedRoutes.js +32 -3
- package/dist/js/modern/analyze/templates.js +4 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +48 -47
- package/dist/js/node/analyze/nestedRoutes.js +32 -3
- package/dist/js/node/analyze/templates.js +4 -10
- package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
- package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +3 -1
- package/dist/js/treeshaking/analyze/generateCode.js +14 -14
- package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
- package/dist/js/treeshaking/analyze/index.js +142 -137
- package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -13
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +36 -28
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/analyze/templates.d.ts +1 -3
- package/dist/types/types/config/output.d.ts +0 -1
- package/package.json +12 -12
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
|
@@ -104,7 +104,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
104
104
|
}
|
|
105
105
|
import path from "path";
|
|
106
106
|
import fs from "fs";
|
|
107
|
-
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash } from "@modern-js/utils";
|
|
107
|
+
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
108
108
|
import { walkDirectory } from "./utils";
|
|
109
109
|
var applyBaseUrl = function(baseUrl, routes) {
|
|
110
110
|
if (baseUrl) {
|
|
@@ -130,8 +130,8 @@ var applyRouteOptions = function(original, routeOptions) {
|
|
|
130
130
|
var routes;
|
|
131
131
|
if (route) {
|
|
132
132
|
if (Array.isArray(route)) {
|
|
133
|
-
var
|
|
134
|
-
|
|
133
|
+
var _route_map;
|
|
134
|
+
_route_map = route.map(function(url) {
|
|
135
135
|
if (isPlainObject(url)) {
|
|
136
136
|
var urlPath = url.path, other = _objectWithoutProperties(url, [
|
|
137
137
|
"path"
|
|
@@ -144,7 +144,7 @@ var applyRouteOptions = function(original, routeOptions) {
|
|
|
144
144
|
urlPath: url
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
}), routes =
|
|
147
|
+
}), routes = _route_map, _route_map;
|
|
148
148
|
} else if (isPlainObject(route)) {
|
|
149
149
|
var urlPath = route.path, other = _objectWithoutProperties(route, [
|
|
150
150
|
"path"
|
|
@@ -169,12 +169,13 @@ var applyRouteOptions = function(original, routeOptions) {
|
|
|
169
169
|
return routes;
|
|
170
170
|
};
|
|
171
171
|
var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
172
|
-
var disableHtmlFolder = config.html.disableHtmlFolder,
|
|
172
|
+
var disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, worker = _config_server.worker;
|
|
173
173
|
var packageName = appContext.packageName;
|
|
174
174
|
var htmlRoutes = entrypoints.reduce(function(previous, param) {
|
|
175
175
|
var entryName = param.entryName;
|
|
176
176
|
var entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
|
|
177
177
|
var isSSR = Boolean(entryOptions);
|
|
178
|
+
var isWorker = Boolean(worker);
|
|
178
179
|
var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
|
|
179
180
|
var route = {
|
|
180
181
|
urlPath: "/".concat(entryName === MAIN_ENTRY_NAME ? "" : entryName),
|
|
@@ -183,6 +184,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
|
183
184
|
isSPA: true,
|
|
184
185
|
isSSR: isSSR,
|
|
185
186
|
responseHeaders: resHeaders,
|
|
187
|
+
worker: isWorker ? "".concat(SERVER_WORKER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0,
|
|
186
188
|
bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
|
|
187
189
|
};
|
|
188
190
|
if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
|
|
@@ -200,7 +202,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
|
200
202
|
};
|
|
201
203
|
var collectStaticRoutes = function(appContext, config) {
|
|
202
204
|
var appDirectory = appContext.appDirectory;
|
|
203
|
-
var configDir = config.source.configDir,
|
|
205
|
+
var configDir = config.source.configDir, _config_server = config.server, _config_server_publicRoutes = _config_server.publicRoutes, publicRoutes = _config_server_publicRoutes === void 0 ? {} : _config_server_publicRoutes;
|
|
204
206
|
var publicFolder = path.resolve(appDirectory, configDir || "", "public");
|
|
205
207
|
return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map(function(filePath) {
|
|
206
208
|
var urlPath = "".concat(urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length)));
|
|
@@ -223,16 +223,17 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
223
223
|
import * as path from "path";
|
|
224
224
|
import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
|
-
import { createBuilderForModern } from "../builder";
|
|
227
226
|
import { printInstructions } from "../utils/printInstructions";
|
|
228
227
|
import { generateRoutes } from "../utils/routes";
|
|
229
228
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
229
|
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
231
230
|
import { initialNormalizedConfig } from "../config";
|
|
231
|
+
import { createBuilderGenerator } from "../builder";
|
|
232
232
|
import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
233
233
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
234
234
|
var debug = createDebugger("plugin-analyze");
|
|
235
|
-
var analyze_default = function() {
|
|
235
|
+
var analyze_default = function(param) {
|
|
236
|
+
var bundler = param.bundler;
|
|
236
237
|
return {
|
|
237
238
|
name: "@modern-js/plugin-analyze",
|
|
238
239
|
setup: function(api) {
|
|
@@ -242,7 +243,7 @@ var analyze_default = function() {
|
|
|
242
243
|
return {
|
|
243
244
|
prepare: function prepare() {
|
|
244
245
|
return _asyncToGenerator(function() {
|
|
245
|
-
var
|
|
246
|
+
var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, _ref, routes2, _ref1, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, createBuilderForModern, builder;
|
|
246
247
|
return __generator(this, function(_state) {
|
|
247
248
|
switch(_state.label){
|
|
248
249
|
case 0:
|
|
@@ -254,7 +255,7 @@ var analyze_default = function() {
|
|
|
254
255
|
} catch (e) {}
|
|
255
256
|
return [
|
|
256
257
|
4,
|
|
257
|
-
isApiOnly(appContext.appDirectory, (
|
|
258
|
+
isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir)
|
|
258
259
|
];
|
|
259
260
|
case 1:
|
|
260
261
|
apiOnly = _state.sent();
|
|
@@ -275,7 +276,7 @@ var analyze_default = function() {
|
|
|
275
276
|
})
|
|
276
277
|
];
|
|
277
278
|
case 3:
|
|
278
|
-
|
|
279
|
+
_ref = _state.sent(), routes2 = _ref.routes;
|
|
279
280
|
debug("server routes: %o", routes2);
|
|
280
281
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
281
282
|
apiOnly: apiOnly,
|
|
@@ -296,10 +297,10 @@ var analyze_default = function() {
|
|
|
296
297
|
])
|
|
297
298
|
];
|
|
298
299
|
case 5:
|
|
299
|
-
|
|
300
|
+
_ref1 = _slicedToArray.apply(void 0, [
|
|
300
301
|
_state.sent(),
|
|
301
302
|
4
|
|
302
|
-
]), getBundleEntry =
|
|
303
|
+
]), getBundleEntry = _ref1[0].getBundleEntry, getServerRoutes = _ref1[1].getServerRoutes, generateCode = _ref1[2].generateCode, getHtmlTemplate = _ref1[3].getHtmlTemplate;
|
|
303
304
|
entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
304
305
|
debug("entrypoints: %o", entrypoints);
|
|
305
306
|
initialRoutes = getServerRoutes(entrypoints, {
|
|
@@ -384,149 +385,153 @@ var analyze_default = function() {
|
|
|
384
385
|
];
|
|
385
386
|
if (!buildCommands.includes(command)) return [
|
|
386
387
|
3,
|
|
387
|
-
|
|
388
|
+
14
|
|
388
389
|
];
|
|
389
390
|
normalizedConfig = api.useResolvedConfigContext();
|
|
391
|
+
return [
|
|
392
|
+
4,
|
|
393
|
+
createBuilderGenerator(bundler)
|
|
394
|
+
];
|
|
395
|
+
case 12:
|
|
396
|
+
createBuilderForModern = _state.sent();
|
|
390
397
|
return [
|
|
391
398
|
4,
|
|
392
399
|
createBuilderForModern({
|
|
393
400
|
normalizedConfig: normalizedConfig,
|
|
394
401
|
appContext: appContext,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
printInstructions(hookRunners2, appContext, normalizedConfig);
|
|
464
|
-
}
|
|
402
|
+
onBeforeBuild: function onBeforeBuild(param) {
|
|
403
|
+
var bundlerConfigs = param.bundlerConfigs;
|
|
404
|
+
return _asyncToGenerator(function() {
|
|
405
|
+
var hookRunners2;
|
|
406
|
+
return __generator(this, function(_state) {
|
|
407
|
+
switch(_state.label){
|
|
408
|
+
case 0:
|
|
409
|
+
hookRunners2 = api.useHookRunners();
|
|
410
|
+
return [
|
|
411
|
+
4,
|
|
412
|
+
generateRoutes(appContext)
|
|
413
|
+
];
|
|
414
|
+
case 1:
|
|
415
|
+
_state.sent();
|
|
416
|
+
return [
|
|
417
|
+
4,
|
|
418
|
+
hookRunners2.beforeBuild({
|
|
419
|
+
bundlerConfigs: bundlerConfigs
|
|
420
|
+
})
|
|
421
|
+
];
|
|
422
|
+
case 2:
|
|
423
|
+
_state.sent();
|
|
424
|
+
return [
|
|
425
|
+
2
|
|
426
|
+
];
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
})();
|
|
430
|
+
},
|
|
431
|
+
onAfterBuild: function onAfterBuild(param) {
|
|
432
|
+
var stats = param.stats;
|
|
433
|
+
return _asyncToGenerator(function() {
|
|
434
|
+
var hookRunners2;
|
|
435
|
+
return __generator(this, function(_state) {
|
|
436
|
+
switch(_state.label){
|
|
437
|
+
case 0:
|
|
438
|
+
hookRunners2 = api.useHookRunners();
|
|
439
|
+
return [
|
|
440
|
+
4,
|
|
441
|
+
hookRunners2.afterBuild({
|
|
442
|
+
stats: stats
|
|
443
|
+
})
|
|
444
|
+
];
|
|
445
|
+
case 1:
|
|
446
|
+
_state.sent();
|
|
447
|
+
return [
|
|
448
|
+
4,
|
|
449
|
+
emitResolvedConfig(appContext.appDirectory, normalizedConfig)
|
|
450
|
+
];
|
|
451
|
+
case 2:
|
|
452
|
+
_state.sent();
|
|
453
|
+
return [
|
|
454
|
+
2
|
|
455
|
+
];
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
})();
|
|
459
|
+
},
|
|
460
|
+
onDevCompileDone: function onDevCompileDone(param) {
|
|
461
|
+
var isFirstCompile = param.isFirstCompile;
|
|
462
|
+
return _asyncToGenerator(function() {
|
|
463
|
+
var hookRunners2;
|
|
464
|
+
return __generator(this, function(_state) {
|
|
465
|
+
hookRunners2 = api.useHookRunners();
|
|
466
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
467
|
+
hookRunners2.afterDev();
|
|
468
|
+
if (isFirstCompile) {
|
|
469
|
+
printInstructions(hookRunners2, appContext, normalizedConfig);
|
|
465
470
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
})
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
})
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
})
|
|
517
|
-
}
|
|
471
|
+
}
|
|
472
|
+
return [
|
|
473
|
+
2
|
|
474
|
+
];
|
|
475
|
+
});
|
|
476
|
+
})();
|
|
477
|
+
},
|
|
478
|
+
onBeforeCreateCompiler: function onBeforeCreateCompiler(param) {
|
|
479
|
+
var bundlerConfigs = param.bundlerConfigs;
|
|
480
|
+
return _asyncToGenerator(function() {
|
|
481
|
+
var hookRunners2;
|
|
482
|
+
return __generator(this, function(_state) {
|
|
483
|
+
switch(_state.label){
|
|
484
|
+
case 0:
|
|
485
|
+
hookRunners2 = api.useHookRunners();
|
|
486
|
+
return [
|
|
487
|
+
4,
|
|
488
|
+
hookRunners2.beforeCreateCompiler({
|
|
489
|
+
bundlerConfigs: bundlerConfigs
|
|
490
|
+
})
|
|
491
|
+
];
|
|
492
|
+
case 1:
|
|
493
|
+
_state.sent();
|
|
494
|
+
return [
|
|
495
|
+
2
|
|
496
|
+
];
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
})();
|
|
500
|
+
},
|
|
501
|
+
onAfterCreateCompiler: function onAfterCreateCompiler(param) {
|
|
502
|
+
var compiler = param.compiler;
|
|
503
|
+
return _asyncToGenerator(function() {
|
|
504
|
+
var hookRunners2;
|
|
505
|
+
return __generator(this, function(_state) {
|
|
506
|
+
switch(_state.label){
|
|
507
|
+
case 0:
|
|
508
|
+
hookRunners2 = api.useHookRunners();
|
|
509
|
+
return [
|
|
510
|
+
4,
|
|
511
|
+
hookRunners2.afterCreateCompiler({
|
|
512
|
+
compiler: compiler
|
|
513
|
+
})
|
|
514
|
+
];
|
|
515
|
+
case 1:
|
|
516
|
+
_state.sent();
|
|
517
|
+
return [
|
|
518
|
+
2
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
})();
|
|
518
523
|
}
|
|
519
524
|
})
|
|
520
525
|
];
|
|
521
|
-
case
|
|
526
|
+
case 13:
|
|
522
527
|
builder = _state.sent();
|
|
523
528
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
524
529
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
525
530
|
builder: builder
|
|
526
531
|
});
|
|
527
532
|
api.setAppContext(appContext);
|
|
528
|
-
_state.label =
|
|
529
|
-
case
|
|
533
|
+
_state.label = 14;
|
|
534
|
+
case 14:
|
|
530
535
|
return [
|
|
531
536
|
2
|
|
532
537
|
];
|
|
@@ -560,7 +565,7 @@ var analyze_default = function() {
|
|
|
560
565
|
resolvedConfig: function resolvedConfig(param) {
|
|
561
566
|
var resolved = param.resolved;
|
|
562
567
|
var appContext = api.useAppContext();
|
|
563
|
-
var config = initialNormalizedConfig(resolved, appContext);
|
|
568
|
+
var config = initialNormalizedConfig(resolved, appContext, bundler);
|
|
564
569
|
return {
|
|
565
570
|
resolved: config
|
|
566
571
|
};
|
|
@@ -568,7 +573,7 @@ var analyze_default = function() {
|
|
|
568
573
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
569
574
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
570
575
|
return _asyncToGenerator(function() {
|
|
571
|
-
var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout,
|
|
576
|
+
var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, _ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
|
|
572
577
|
return __generator(this, function(_state) {
|
|
573
578
|
switch(_state.label){
|
|
574
579
|
case 0:
|
|
@@ -607,10 +612,10 @@ var analyze_default = function() {
|
|
|
607
612
|
})
|
|
608
613
|
];
|
|
609
614
|
case 2:
|
|
610
|
-
|
|
615
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
611
616
|
_state.sent(),
|
|
612
617
|
2
|
|
613
|
-
]), moduleExports =
|
|
618
|
+
]), moduleExports = _ref[1];
|
|
614
619
|
hasAppConfig = moduleExports.some(function(e) {
|
|
615
620
|
return e.n === APP_CONFIG_NAME;
|
|
616
621
|
});
|
|
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
|
197
197
|
};
|
|
198
198
|
var walk = function() {
|
|
199
199
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
|
200
|
-
var
|
|
200
|
+
var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, path2;
|
|
201
201
|
return __generator(this, function(_state) {
|
|
202
202
|
switch(_state.label){
|
|
203
203
|
case 0:
|
|
@@ -242,6 +242,8 @@ var walk = function() {
|
|
|
242
242
|
};
|
|
243
243
|
pageLoaderFile = "";
|
|
244
244
|
pageRoute = null;
|
|
245
|
+
splatLoaderFile = "";
|
|
246
|
+
splatRoute = null;
|
|
245
247
|
return [
|
|
246
248
|
4,
|
|
247
249
|
fs.readdir(dirname)
|
|
@@ -286,7 +288,7 @@ var walk = function() {
|
|
|
286
288
|
childRoute = _state.sent();
|
|
287
289
|
if (childRoute) {
|
|
288
290
|
;
|
|
289
|
-
(
|
|
291
|
+
(_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(childRoute);
|
|
290
292
|
}
|
|
291
293
|
_state.label = 8;
|
|
292
294
|
case 8:
|
|
@@ -315,7 +317,21 @@ var walk = function() {
|
|
|
315
317
|
if (pageLoaderFile) {
|
|
316
318
|
pageRoute.loader = pageLoaderFile;
|
|
317
319
|
}
|
|
318
|
-
(
|
|
320
|
+
(_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(pageRoute);
|
|
321
|
+
}
|
|
322
|
+
if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
323
|
+
splatLoaderFile = itemPath;
|
|
324
|
+
}
|
|
325
|
+
if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
|
|
326
|
+
;
|
|
327
|
+
splatRoute = createRoute({
|
|
328
|
+
_component: replaceWithAlias(alias.basename, itemPath, alias.name),
|
|
329
|
+
path: "*"
|
|
330
|
+
}, rootDir, itemPath, entryName);
|
|
331
|
+
if (splatLoaderFile) {
|
|
332
|
+
splatRoute.loader = splatLoaderFile;
|
|
333
|
+
}
|
|
334
|
+
(_route_children3 = route.children) === null || _route_children3 === void 0 ? void 0 : _route_children3.push(splatRoute);
|
|
319
335
|
}
|
|
320
336
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
321
337
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
@@ -361,7 +377,7 @@ var walk = function() {
|
|
|
361
377
|
if (isPathlessLayout) {
|
|
362
378
|
delete finalRoute.path;
|
|
363
379
|
}
|
|
364
|
-
route.children = (
|
|
380
|
+
route.children = (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.filter(function(childRoute) {
|
|
365
381
|
return childRoute;
|
|
366
382
|
});
|
|
367
383
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
@@ -370,6 +386,15 @@ var walk = function() {
|
|
|
370
386
|
null
|
|
371
387
|
];
|
|
372
388
|
}
|
|
389
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
390
|
+
childRoute1 = finalRoute.children[0];
|
|
391
|
+
if (childRoute1.path === "*") {
|
|
392
|
+
path2 = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
|
|
393
|
+
finalRoute = _objectSpreadProps(_objectSpread({}, childRoute1), {
|
|
394
|
+
path: path2
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
373
398
|
return [
|
|
374
399
|
2,
|
|
375
400
|
finalRoute
|
|
@@ -229,10 +229,11 @@ var index = function(param) {
|
|
|
229
229
|
};
|
|
230
230
|
var renderFunction = function(param) {
|
|
231
231
|
var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes2 = param.fileSystemRoutes;
|
|
232
|
+
var bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
|
232
233
|
return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param) {
|
|
233
234
|
var name = param.name, options = param.options, args = param.args;
|
|
234
235
|
return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
|
|
235
|
-
}).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap
|
|
236
|
+
}).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper, () => ".concat(bootstrap, ");") : "".concat(bootstrap, ";"), "\n }\n\n return AppWrapper\n");
|
|
236
237
|
};
|
|
237
238
|
var html = function(partials) {
|
|
238
239
|
return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join("\n"), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join("\n"), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\n <div id=\"<%= mountId %>\"><!--<?- html ?>--></div>\n ").concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
|
|
@@ -243,8 +244,8 @@ var routesForServer = function(param) {
|
|
|
243
244
|
var traverseRouteTree = function(route) {
|
|
244
245
|
var children;
|
|
245
246
|
if ("children" in route && route.children) {
|
|
246
|
-
var
|
|
247
|
-
children = route === null || route === void 0 ? void 0 : (
|
|
247
|
+
var _route_children;
|
|
248
|
+
children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
|
248
249
|
}
|
|
249
250
|
var loader;
|
|
250
251
|
if (route.type === "nested") {
|
|
@@ -296,7 +297,7 @@ var routesForServer = function(param) {
|
|
|
296
297
|
};
|
|
297
298
|
var fileSystemRoutes = function() {
|
|
298
299
|
var _ref = _asyncToGenerator(function(param) {
|
|
299
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode,
|
|
300
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
|
300
301
|
return __generator(this, function(_state) {
|
|
301
302
|
switch(_state.label){
|
|
302
303
|
case 0:
|
|
@@ -308,7 +309,6 @@ var fileSystemRoutes = function() {
|
|
|
308
309
|
loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
|
|
309
310
|
importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
|
|
310
311
|
rootLayoutCode = "";
|
|
311
|
-
componentLoaderPath = "";
|
|
312
312
|
getDataLoaderPath = function(loaderId) {
|
|
313
313
|
if (!ssrMode) {
|
|
314
314
|
return "";
|
|
@@ -319,14 +319,11 @@ var fileSystemRoutes = function() {
|
|
|
319
319
|
}
|
|
320
320
|
return dataLoaderPath;
|
|
321
321
|
};
|
|
322
|
-
if (ssrMode) {
|
|
323
|
-
componentLoaderPath = "".concat(path.join(__dirname, "../builder/loaders/routerLoader"), "!");
|
|
324
|
-
}
|
|
325
322
|
traverseRouteTree = function(route) {
|
|
326
323
|
var children;
|
|
327
324
|
if ("children" in route && route.children) {
|
|
328
|
-
var
|
|
329
|
-
children = route === null || route === void 0 ? void 0 : (
|
|
325
|
+
var _route_children;
|
|
326
|
+
children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
|
330
327
|
}
|
|
331
328
|
var loading;
|
|
332
329
|
var error;
|
|
@@ -357,10 +354,10 @@ var fileSystemRoutes = function() {
|
|
|
357
354
|
rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
|
|
358
355
|
component = "RootLayout";
|
|
359
356
|
} else if (ssrMode === "string") {
|
|
360
|
-
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(
|
|
357
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
361
358
|
component = "loadable(".concat(lazyImport, ")");
|
|
362
359
|
} else {
|
|
363
|
-
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(
|
|
360
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
364
361
|
component = "lazy(".concat(lazyImport, ")");
|
|
365
362
|
}
|
|
366
363
|
}
|
|
@@ -421,7 +418,7 @@ var fileSystemRoutes = function() {
|
|
|
421
418
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
422
419
|
try {
|
|
423
420
|
for(_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
424
|
-
|
|
421
|
+
_step_value = _slicedToArray(_step1.value, 2), key = _step_value[0], loaderInfo = _step_value[1];
|
|
425
422
|
if (loaderInfo.inline) {
|
|
426
423
|
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
|
|
427
424
|
} else {
|
|
@@ -333,7 +333,7 @@ var parseModule = function() {
|
|
|
333
333
|
}();
|
|
334
334
|
var hasLoader = function() {
|
|
335
335
|
var _ref = _asyncToGenerator(function(filename) {
|
|
336
|
-
var source,
|
|
336
|
+
var source, _ref, moduleExports;
|
|
337
337
|
return __generator(this, function(_state) {
|
|
338
338
|
switch(_state.label){
|
|
339
339
|
case 0:
|
|
@@ -351,10 +351,10 @@ var hasLoader = function() {
|
|
|
351
351
|
})
|
|
352
352
|
];
|
|
353
353
|
case 2:
|
|
354
|
-
|
|
354
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
355
355
|
_state.sent(),
|
|
356
356
|
2
|
|
357
|
-
]), moduleExports =
|
|
357
|
+
]), moduleExports = _ref[1];
|
|
358
358
|
return [
|
|
359
359
|
2,
|
|
360
360
|
moduleExports.some(function(e) {
|