@modern-js/app-tools 2.0.2 → 2.0.3-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.
Files changed (36) hide show
  1. package/dist/js/modern/analyze/generateCode.js +4 -81
  2. package/dist/js/modern/analyze/index.js +24 -10
  3. package/dist/js/modern/analyze/nestedRoutes.js +2 -15
  4. package/dist/js/modern/analyze/templates.js +26 -56
  5. package/dist/js/modern/analyze/utils.js +8 -0
  6. package/dist/js/modern/config/initial/inits.js +1 -9
  7. package/dist/js/modern/index.js +6 -7
  8. package/dist/js/modern/locale/en.js +2 -1
  9. package/dist/js/modern/locale/zh.js +2 -1
  10. package/dist/js/node/analyze/generateCode.js +2 -77
  11. package/dist/js/node/analyze/index.js +22 -8
  12. package/dist/js/node/analyze/nestedRoutes.js +1 -14
  13. package/dist/js/node/analyze/templates.js +26 -56
  14. package/dist/js/node/analyze/utils.js +9 -0
  15. package/dist/js/node/config/initial/inits.js +1 -9
  16. package/dist/js/node/index.js +2 -3
  17. package/dist/js/node/locale/en.js +2 -1
  18. package/dist/js/node/locale/zh.js +2 -1
  19. package/dist/js/treeshaking/analyze/generateCode.js +21 -148
  20. package/dist/js/treeshaking/analyze/index.js +22 -15
  21. package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
  22. package/dist/js/treeshaking/analyze/templates.js +88 -72
  23. package/dist/js/treeshaking/analyze/utils.js +4 -1
  24. package/dist/js/treeshaking/config/initial/inits.js +1 -12
  25. package/dist/js/treeshaking/index.js +8 -9
  26. package/dist/js/treeshaking/locale/en.js +2 -1
  27. package/dist/js/treeshaking/locale/zh.js +2 -1
  28. package/dist/types/analyze/utils.d.ts +2 -1
  29. package/dist/types/locale/en.d.ts +1 -0
  30. package/dist/types/locale/index.d.ts +2 -0
  31. package/dist/types/locale/zh.d.ts +1 -0
  32. package/package.json +10 -10
  33. package/dist/js/modern/analyze/Builder.js +0 -39
  34. package/dist/js/node/analyze/Builder.js +0 -64
  35. package/dist/js/treeshaking/analyze/Builder.js +0 -199
  36. package/dist/types/analyze/Builder.d.ts +0 -8
@@ -205,10 +205,9 @@ const routesForServer = ({
205
205
  ];`;
206
206
  let importLoadersCode = "";
207
207
  if (loaders.length > 0) {
208
- importLoadersCode = `
209
- import { ${loaders.map(
210
- (loader, index2) => `loader_${index2}`
211
- )} } from "${(0, import_utils.slash)(loaderIndexFile)}"`;
208
+ importLoadersCode = loaders.map((loader, index2) => {
209
+ return `import loader_${index2} from "${loader}"`;
210
+ }).join("\n");
212
211
  }
213
212
  return `
214
213
  ${importLoadersCode}
@@ -227,12 +226,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
227
226
  const errors = [];
228
227
  const loaders = [];
229
228
  const loadersMap = {};
230
- const loadersIndexFile = import_path.default.join(
231
- internalDirAlias,
232
- entryName,
233
- import_constants.TEMP_LOADERS_DIR,
234
- "index.js"
235
- );
236
229
  const loadersMapFile = import_path.default.join(
237
230
  internalDirectory,
238
231
  entryName,
@@ -244,13 +237,17 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
244
237
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
245
238
  `;
246
239
  let rootLayoutCode = ``;
247
- let dataLoaderPath = "";
248
240
  let componentLoaderPath = "";
249
- if (ssrMode) {
250
- dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
241
+ const getDataLoaderPath = (loaderId) => {
242
+ if (!ssrMode)
243
+ return "";
244
+ let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
251
245
  if (nestedRoutesEntry) {
252
- dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&mapFile=${loadersMapFile}!`;
246
+ dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(loadersMapFile)}&loaderId=${loaderId}!`;
253
247
  }
248
+ return dataLoaderPath;
249
+ };
250
+ if (ssrMode) {
254
251
  componentLoaderPath = `${import_path.default.join(
255
252
  __dirname,
256
253
  "../builder/loaders/routerLoader"
@@ -280,7 +277,11 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
280
277
  loaders.push(route.loader);
281
278
  const loaderId = loaders.length - 1;
282
279
  loader = `loader_${loaderId}`;
283
- loadersMap[loader] = route.id;
280
+ loadersMap[loader] = {
281
+ routeId: route.id,
282
+ filePath: route.loader,
283
+ inline: false
284
+ };
284
285
  }
285
286
  if (route._component) {
286
287
  if (route.isRoot) {
@@ -336,48 +337,17 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
336
337
  `;
337
338
  }).join("");
338
339
  let importLoadersCode = "";
339
- if (loaders.length > 0) {
340
- importLoadersCode = `
341
- import { ${loaders.map(
342
- (loader, index2) => `loader_${index2}`
343
- )} } from "${(0, import_utils.slash)(dataLoaderPath)}${(0, import_utils.slash)(loadersIndexFile)}"
344
- `;
345
- const loaderEntryCode = loaders.map((loader, index2) => {
346
- return `export * from './loader_${index2}.js';`;
347
- }).join("\n");
348
- const loaderEntryFile = import_path.default.join(
349
- internalDirectory,
350
- entryName,
351
- import_constants.TEMP_LOADERS_DIR,
352
- "entry.js"
353
- );
354
- yield import_utils.fs.ensureFile(loaderEntryFile);
355
- yield import_utils.fs.writeFile(loaderEntryFile, loaderEntryCode);
356
- yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
357
- yield Promise.all(
358
- loaders.map((loader, index2) => __async(void 0, null, function* () {
359
- const name = `loader_${index2}`;
360
- const filename = import_path.default.join(
361
- internalDirectory,
362
- entryName,
363
- import_constants.TEMP_LOADERS_DIR,
364
- `${name}.js`
365
- );
366
- let code = "";
367
- if (loader.includes(".loader.")) {
368
- code = `
369
- export { default as ${name} } from '${(0, import_utils.slash)(loader)}'
370
- `;
371
- } else {
372
- code = `
373
- export { loader as ${name} } from '${(0, import_utils.slash)(loader)}'
374
- `;
375
- }
376
- yield import_utils.fs.ensureFile(filename);
377
- yield import_utils.fs.writeFile(filename, code);
378
- }))
379
- );
340
+ for (const [key, loaderInfo] of Object.entries(loadersMap)) {
341
+ if (loaderInfo.inline) {
342
+ importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
343
+ `;
344
+ } else {
345
+ importLoadersCode += `import ${key} from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
346
+ `;
347
+ }
380
348
  }
349
+ yield import_utils.fs.ensureFile(loadersMapFile);
350
+ yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
381
351
  return `
382
352
  ${importLazyCode}
383
353
  ${rootLayoutCode}
@@ -44,6 +44,7 @@ var __async = (__this, __arguments, generator) => {
44
44
  var utils_exports = {};
45
45
  __export(utils_exports, {
46
46
  getDefaultImports: () => getDefaultImports,
47
+ getServerLoadersFile: () => getServerLoadersFile,
47
48
  hasLoader: () => hasLoader,
48
49
  isNestedRouteComponent: () => isNestedRouteComponent,
49
50
  isPageComponentFile: () => isPageComponentFile,
@@ -168,9 +169,17 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
168
169
  });
169
170
  return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
170
171
  });
172
+ const getServerLoadersFile = (internalDirectory, entryName) => {
173
+ return import_path.default.join(
174
+ internalDirectory,
175
+ entryName,
176
+ "route-server-loaders.js"
177
+ );
178
+ };
171
179
  // Annotate the CommonJS export names for ESM import in node:
172
180
  0 && (module.exports = {
173
181
  getDefaultImports,
182
+ getServerLoadersFile,
174
183
  hasLoader,
175
184
  isNestedRouteComponent,
176
185
  isPageComponentFile,
@@ -154,7 +154,7 @@ function initToolsConfig(config) {
154
154
  ]
155
155
  }
156
156
  };
157
- const { tsChecker, tsLoader, htmlPlugin } = config.tools;
157
+ const { tsChecker, tsLoader } = config.tools;
158
158
  config.tools.tsChecker = (0, import_utils.applyOptionsChain)(defaultTsChecker, tsChecker);
159
159
  tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
160
160
  (0, import_utils.applyOptionsChain)(
@@ -166,14 +166,6 @@ function initToolsConfig(config) {
166
166
  utils
167
167
  );
168
168
  });
169
- config.tools.htmlPlugin = [
170
- (config2) => __spreadProps(__spreadValues({}, config2), {
171
- minify: typeof config2.minify === "object" ? __spreadProps(__spreadValues({}, config2.minify), {
172
- removeComments: false
173
- }) : config2.minify
174
- }),
175
- ...Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : []
176
- ];
177
169
  }
178
170
  // Annotate the CommonJS export names for ESM import in node:
179
171
  0 && (module.exports = {
@@ -112,7 +112,6 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
112
112
  const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action((options) => __async(void 0, null, function* () {
113
113
  const { build } = yield Promise.resolve().then(() => __toESM(require("./commands/build")));
114
114
  yield build(api, options);
115
- process.exit(0);
116
115
  }));
117
116
  for (const platformBuilder of platformBuilders) {
118
117
  const platforms = (0, import_lodash.castArray)(platformBuilder.platform);
@@ -167,12 +166,12 @@ var src_default = () => ({
167
166
  yield deploy(api, options);
168
167
  process.exit(0);
169
168
  }));
170
- program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
169
+ program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
171
170
  "-c, --config <config>",
172
171
  import_locale.i18n.t(import_locale.localeKeys.command.new.config)
173
172
  ).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
174
173
  const { MWANewAction } = yield Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
175
- yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale }));
174
+ yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
176
175
  }));
177
176
  program.command("inspect").description("inspect internal webpack config").option(
178
177
  `--env <env>`,
@@ -41,7 +41,8 @@ const EN_LOCALE = {
41
41
  debug: "using debug mode to log something",
42
42
  config: "set default generator config(json string)",
43
43
  distTag: `use specified tag version for it's generator`,
44
- registry: "set npm registry url to run npm command"
44
+ registry: "set npm registry url to run npm command",
45
+ lang: "set new command language(en or zh)"
45
46
  },
46
47
  inspect: {
47
48
  env: "specify env mode",
@@ -41,7 +41,8 @@ const ZH_LOCALE = {
41
41
  debug: "开启 Debug 模式,打印调试日志信息",
42
42
  config: "生成器运行默认配置(JSON 字符串)",
43
43
  distTag: "生成器使用特殊的 npm Tag 版本",
44
- registry: "生成器运行过程中定制 npm Registry"
44
+ registry: "生成器运行过程中定制 npm Registry",
45
+ lang: "设置 new 命令执行语言(zh 或者 en)"
45
46
  },
46
47
  inspect: {
47
48
  env: "查看指定环境下的配置",
@@ -148,20 +148,13 @@ var __generator = this && this.__generator || function(thisArg, body) {
148
148
  }
149
149
  };
150
150
  import path from "path";
151
- import { fs, getEntryOptions, LOADER_ROUTES_DIR, logger } from "@modern-js/utils";
151
+ import { fs, getEntryOptions, logger } from "@modern-js/utils";
152
152
  import { useResolvedConfigContext } from "@modern-js/core";
153
- import { isDevCommand } from "../utils/commands";
154
153
  import * as templates from "./templates";
155
154
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
156
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
157
- import { getDefaultImports } from "./utils";
155
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
156
+ import { getDefaultImports, getServerLoadersFile } from "./utils";
158
157
  import { walk } from "./nestedRoutes";
159
- import { loaderBuilder, serverLoaderBuilder } from "./Builder";
160
- var loader = {
161
- ".js": "jsx",
162
- ".ts": "tsx"
163
- };
164
- var EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
165
158
  var createImportSpecifier = function(specifiers) {
166
159
  var defaults = "";
167
160
  var named = [];
@@ -245,91 +238,6 @@ var createImportStatements = function(statements) {
245
238
  return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || "");
246
239
  }).join("\n");
247
240
  };
248
- var buildLoader = function() {
249
- var _ref = _asyncToGenerator(function(entry, outfile) {
250
- return __generator(this, function(_state) {
251
- switch(_state.label){
252
- case 0:
253
- return [
254
- 4,
255
- loaderBuilder.build({
256
- format: "esm",
257
- platform: "browser",
258
- target: "esnext",
259
- loader: loader,
260
- watch: isDevCommand() && {},
261
- bundle: true,
262
- logLevel: "error",
263
- entryPoints: [
264
- entry
265
- ],
266
- outfile: outfile,
267
- plugins: [
268
- {
269
- name: "make-all-packages-external",
270
- setup: function setup(build) {
271
- build.onResolve({
272
- filter: EXTERNAL_REGEXP
273
- }, function(args) {
274
- var external = true;
275
- if (args.kind === "entry-point") {
276
- external = false;
277
- }
278
- return {
279
- path: args.path,
280
- external: external
281
- };
282
- });
283
- }
284
- }
285
- ]
286
- })
287
- ];
288
- case 1:
289
- _state.sent();
290
- return [
291
- 2
292
- ];
293
- }
294
- });
295
- });
296
- return function buildLoader(entry, outfile) {
297
- return _ref.apply(this, arguments);
298
- };
299
- }();
300
- var buildServerLoader = function() {
301
- var _ref = _asyncToGenerator(function(entry, outfile) {
302
- return __generator(this, function(_state) {
303
- switch(_state.label){
304
- case 0:
305
- return [
306
- 4,
307
- serverLoaderBuilder.build({
308
- format: "cjs",
309
- platform: "node",
310
- target: "esnext",
311
- loader: loader,
312
- watch: isDevCommand() && {},
313
- bundle: true,
314
- logLevel: "error",
315
- entryPoints: [
316
- entry
317
- ],
318
- outfile: outfile
319
- })
320
- ];
321
- case 1:
322
- _state.sent();
323
- return [
324
- 2
325
- ];
326
- }
327
- });
328
- });
329
- return function buildServerLoader(entry, outfile) {
330
- return _ref.apply(this, arguments);
331
- };
332
- }();
333
241
  var generateCode = function() {
334
242
  var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
335
243
  var ref, ref1, ref2, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
@@ -338,18 +246,18 @@ var generateCode = function() {
338
246
  }
339
247
  function _generateEntryCode() {
340
248
  _generateEntryCode = _asyncToGenerator(function(entrypoint) {
341
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, outputRoutesServerFile, code3, loaderEntryFile, loaderIndexFile, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
249
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, code3, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
342
250
  return __generator(this, function(_state) {
343
251
  switch(_state.label){
344
252
  case 0:
345
253
  entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
346
254
  if (!isAutoMount) return [
347
255
  3,
348
- 22
256
+ 17
349
257
  ];
350
258
  if (!fileSystemRoutes) return [
351
259
  3,
352
- 15
260
+ 10
353
261
  ];
354
262
  initialRoutes = [];
355
263
  nestedRoute = null;
@@ -442,10 +350,9 @@ var generateCode = function() {
442
350
  ref = _state.sent(), code2 = ref.code;
443
351
  if (!entrypoint.nestedRoutesEntry) return [
444
352
  3,
445
- 14
353
+ 9
446
354
  ];
447
- routesServerFile = path.join(internalDirectory, entryName, "route-server-loaders.js");
448
- outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, "index.js");
355
+ routesServerFile = getServerLoadersFile(internalDirectory, entryName);
449
356
  code3 = templates.routesForServer({
450
357
  routes: routes,
451
358
  internalDirectory: internalDirectory,
@@ -463,45 +370,11 @@ var generateCode = function() {
463
370
  ];
464
371
  case 8:
465
372
  _state.sent();
466
- loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "entry.js");
467
- loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
468
- return [
469
- 4,
470
- fs.pathExists(loaderEntryFile)
471
- ];
373
+ _state.label = 9;
472
374
  case 9:
473
- if (!_state.sent()) return [
474
- 3,
475
- 11
476
- ];
477
- return [
478
- 4,
479
- buildLoader(loaderEntryFile, loaderIndexFile)
480
- ];
481
- case 10:
482
- _state.sent();
483
- _state.label = 11;
484
- case 11:
485
- return [
486
- 4,
487
- fs.pathExists(routesServerFile)
488
- ];
489
- case 12:
490
- if (!_state.sent()) return [
491
- 3,
492
- 14
493
- ];
494
- return [
495
- 4,
496
- buildServerLoader(routesServerFile, outputRoutesServerFile)
497
- ];
498
- case 13:
499
- _state.sent();
500
- _state.label = 14;
501
- case 14:
502
375
  fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
503
- _state.label = 15;
504
- case 15:
376
+ _state.label = 10;
377
+ case 10:
505
378
  return [
506
379
  4,
507
380
  hookRunners.modifyEntryImports({
@@ -515,7 +388,7 @@ var generateCode = function() {
515
388
  })
516
389
  })
517
390
  ];
518
- case 16:
391
+ case 11:
519
392
  ref1 = _state.sent(), importStatements = ref1.imports;
520
393
  return [
521
394
  4,
@@ -524,7 +397,7 @@ var generateCode = function() {
524
397
  plugins: []
525
398
  })
526
399
  ];
527
- case 17:
400
+ case 12:
528
401
  plugins = _state.sent().plugins;
529
402
  return [
530
403
  4,
@@ -537,7 +410,7 @@ var generateCode = function() {
537
410
  })
538
411
  })
539
412
  ];
540
- case 18:
413
+ case 13:
541
414
  ref2 = _state.sent(), renderFunction = ref2.code;
542
415
  return [
543
416
  4,
@@ -546,7 +419,7 @@ var generateCode = function() {
546
419
  exportStatement: "export default AppWrapper;"
547
420
  })
548
421
  ];
549
- case 19:
422
+ case 14:
550
423
  exportStatement = _state.sent().exportStatement;
551
424
  code = templates.index({
552
425
  mountId: mountId,
@@ -558,7 +431,7 @@ var generateCode = function() {
558
431
  entrypoint.entry = entryFile;
559
432
  if (!config.source.enableAsyncEntry) return [
560
433
  3,
561
- 21
434
+ 16
562
435
  ];
563
436
  return [
564
437
  4,
@@ -567,19 +440,19 @@ var generateCode = function() {
567
440
  code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
568
441
  })
569
442
  ];
570
- case 20:
443
+ case 15:
571
444
  ref3 = _state.sent(), asyncEntryCode = ref3.code;
572
445
  fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
573
446
  bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
574
447
  fs.outputFileSync(bootstrapFile, code, "utf8");
575
448
  return [
576
449
  3,
577
- 22
450
+ 17
578
451
  ];
579
- case 21:
452
+ case 16:
580
453
  fs.outputFileSync(entryFile, code, "utf8");
581
- _state.label = 22;
582
- case 22:
454
+ _state.label = 17;
455
+ case 17:
583
456
  return [
584
457
  2
585
458
  ];
@@ -221,7 +221,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
221
221
  }
222
222
  };
223
223
  import * as path from "path";
224
- import { createDebugger, findExists, fs, isApiOnly } from "@modern-js/utils";
224
+ import { createDebugger, findExists, fs, isApiOnly, isUseSSRBundle } from "@modern-js/utils";
225
225
  import { cloneDeep } from "@modern-js/utils/lodash";
226
226
  import { createBuilderForModern } from "../builder";
227
227
  import { printInstructions } from "../utils/printInstructions";
@@ -229,8 +229,7 @@ import { generateRoutes } from "../utils/routes";
229
229
  import { emitResolvedConfig } from "../utils/config";
230
230
  import { getCommand } from "../utils/commands";
231
231
  import { initialNormalizedConfig } from "../config";
232
- import { isNestedRouteComponent, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
233
- import { loaderBuilder, serverLoaderBuilder } from "./Builder";
232
+ import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
234
233
  import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
235
234
  var debug = createDebugger("plugin-analyze");
236
235
  var analyze_default = function() {
@@ -525,6 +524,25 @@ var analyze_default = function() {
525
524
  watchFiles: function watchFiles() {
526
525
  return pagesDir;
527
526
  },
527
+ config: function config() {
528
+ return {
529
+ tools: {
530
+ webpackChain: function(chain, param) {
531
+ var name = param.name, CHAIN_ID = param.CHAIN_ID;
532
+ var appContext = api.useAppContext();
533
+ var resolvedConfig = api.useResolvedConfigContext();
534
+ var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory;
535
+ entrypoints.forEach(function(entrypoint) {
536
+ var entryName = entrypoint.entryName;
537
+ if (entrypoint.nestedRoutesEntry && isUseSSRBundle(resolvedConfig)) {
538
+ var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
539
+ chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
540
+ }
541
+ });
542
+ }
543
+ }
544
+ };
545
+ },
528
546
  resolvedConfig: function resolvedConfig(param) {
529
547
  var resolved = param.resolved;
530
548
  var appContext = api.useAppContext();
@@ -620,17 +638,6 @@ var analyze_default = function() {
620
638
  });
621
639
  })();
622
640
  },
623
- beforeRestart: function beforeRestart() {
624
- return _asyncToGenerator(function() {
625
- return __generator(this, function(_state) {
626
- serverLoaderBuilder.stop();
627
- loaderBuilder.stop();
628
- return [
629
- 2
630
- ];
631
- });
632
- })();
633
- },
634
641
  fileChange: function fileChange(e) {
635
642
  return _asyncToGenerator(function() {
636
643
  var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
@@ -647,7 +654,7 @@ var analyze_default = function() {
647
654
  };
648
655
  absoluteFilePath = path.resolve(appDirectory, filename);
649
656
  isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
650
- if (!(isRouteComponent && (eventType === "add" || eventType === "unlink") || isNestedRouteComponent(nestedRouteEntries, absoluteFilePath) && eventType === "change")) return [
657
+ if (!(isRouteComponent && (eventType === "add" || eventType === "unlink"))) return [
651
658
  3,
652
659
  2
653
660
  ];