@modern-js/app-tools 2.8.1-alpha.0 → 2.8.1-alpha.2

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 (137) hide show
  1. package/dist/cjs/analyze/generateCode.js +1 -3
  2. package/dist/cjs/analyze/index.js +0 -8
  3. package/dist/cjs/analyze/templates.js +14 -31
  4. package/dist/cjs/builder/index.js +2 -0
  5. package/dist/esm/analyze/generateCode.js +2 -3
  6. package/dist/esm/analyze/index.js +0 -8
  7. package/dist/esm/analyze/templates.js +16 -30
  8. package/dist/esm/builder/index.js +2 -0
  9. package/dist/esm-node/analyze/generateCode.js +1 -3
  10. package/dist/esm-node/analyze/index.js +0 -8
  11. package/dist/esm-node/analyze/templates.js +14 -31
  12. package/dist/esm-node/builder/index.js +2 -0
  13. package/dist/js/modern/analyze/constants.js +3 -1
  14. package/dist/js/modern/analyze/getServerRoutes.js +5 -2
  15. package/dist/js/modern/analyze/index.js +47 -46
  16. package/dist/js/modern/analyze/nestedRoutes.js +32 -3
  17. package/dist/js/modern/analyze/templates.js +4 -10
  18. package/dist/js/modern/builder/builder-rspack/index.js +8 -0
  19. package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  20. package/dist/js/modern/builder/builder-webpack/index.js +93 -0
  21. package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
  22. package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
  23. package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
  24. package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
  25. package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
  26. package/dist/js/modern/builder/generator/index.js +53 -0
  27. package/dist/js/modern/builder/index.js +13 -133
  28. package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
  29. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  30. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  31. package/dist/js/modern/builder/shared/index.js +3 -0
  32. package/dist/js/modern/builder/shared/types.js +0 -0
  33. package/dist/js/modern/config/default.js +2 -2
  34. package/dist/js/modern/config/index.js +3 -8
  35. package/dist/js/modern/config/initialize/index.js +12 -0
  36. package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
  37. package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
  38. package/dist/js/modern/index.js +18 -8
  39. package/dist/js/modern/initialize/index.js +36 -28
  40. package/dist/js/modern/locale/zh.js +1 -1
  41. package/dist/js/modern/types/utils.js +0 -0
  42. package/dist/js/node/analyze/constants.js +3 -1
  43. package/dist/js/node/analyze/getServerRoutes.js +3 -1
  44. package/dist/js/node/analyze/index.js +48 -47
  45. package/dist/js/node/analyze/nestedRoutes.js +32 -3
  46. package/dist/js/node/analyze/templates.js +4 -10
  47. package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
  48. package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  49. package/dist/js/node/builder/builder-webpack/index.js +118 -0
  50. package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
  51. package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
  52. package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
  53. package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
  54. package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
  55. package/dist/js/node/builder/generator/index.js +82 -0
  56. package/dist/js/node/builder/index.js +14 -123
  57. package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
  58. package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
  59. package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
  60. package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
  61. package/dist/js/node/builder/shared/index.js +19 -0
  62. package/dist/js/node/builder/shared/types.js +15 -0
  63. package/dist/js/node/config/default.js +2 -2
  64. package/dist/js/node/config/index.js +4 -19
  65. package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
  66. package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
  67. package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
  68. package/dist/js/node/index.js +18 -8
  69. package/dist/js/node/initialize/index.js +35 -28
  70. package/dist/js/node/locale/zh.js +1 -1
  71. package/dist/js/node/types/utils.js +15 -0
  72. package/dist/js/treeshaking/analyze/constants.js +3 -1
  73. package/dist/js/treeshaking/analyze/generateCode.js +14 -14
  74. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
  75. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
  76. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  77. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
  78. package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
  79. package/dist/js/treeshaking/analyze/index.js +142 -137
  80. package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
  81. package/dist/js/treeshaking/analyze/templates.js +10 -13
  82. package/dist/js/treeshaking/analyze/utils.js +3 -3
  83. package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
  84. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  85. package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
  86. package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
  87. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
  88. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
  89. package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
  90. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
  91. package/dist/js/treeshaking/builder/generator/index.js +199 -0
  92. package/dist/js/treeshaking/builder/index.js +29 -228
  93. package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
  94. package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
  95. package/dist/js/treeshaking/builder/shared/index.js +3 -0
  96. package/dist/js/treeshaking/builder/shared/types.js +1 -0
  97. package/dist/js/treeshaking/commands/dev.js +2 -2
  98. package/dist/js/treeshaking/commands/serve.js +2 -2
  99. package/dist/js/treeshaking/config/default.js +2 -2
  100. package/dist/js/treeshaking/config/index.js +3 -3
  101. package/dist/js/treeshaking/config/initialize/index.js +10 -0
  102. package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
  103. package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
  104. package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
  105. package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
  106. package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
  107. package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
  108. package/dist/js/treeshaking/index.js +19 -12
  109. package/dist/js/treeshaking/initialize/index.js +36 -28
  110. package/dist/js/treeshaking/locale/zh.js +1 -1
  111. package/dist/js/treeshaking/types/utils.js +1 -0
  112. package/dist/js/treeshaking/utils/config.js +2 -2
  113. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
  114. package/dist/types/analyze/templates.d.ts +1 -3
  115. package/dist/types/types/config/output.d.ts +0 -1
  116. package/package.json +11 -11
  117. package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
  118. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
  119. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
  120. package/dist/js/modern/config/initial/index.js +0 -16
  121. package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
  122. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
  123. package/dist/js/treeshaking/config/initial/index.js +0 -12
  124. /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
  125. /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  126. /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
  127. /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
  128. /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
  129. /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
  130. /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  131. /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
  132. /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
  133. /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
  134. /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
  135. /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
  136. /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
  137. /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
@@ -99,7 +99,6 @@ const generateCode = async (appContext, config, entrypoints, api) => {
99
99
  const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
100
100
  await Promise.all(entrypoints.map(generateEntryCode));
101
101
  async function generateEntryCode(entrypoint) {
102
- var _a;
103
102
  const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
104
103
  if (isAutoMount) {
105
104
  if (fileSystemRoutes) {
@@ -162,8 +161,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
162
161
  ssrMode: useSSG ? "string" : mode,
163
162
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
164
163
  entryName: entrypoint.entryName,
165
- internalDirectory,
166
- splitRoutesChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRoutesChunks
164
+ internalDirectory
167
165
  })
168
166
  });
169
167
  if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
@@ -247,14 +247,6 @@ var analyze_default = ({
247
247
  imports
248
248
  };
249
249
  },
250
- validateSchema() {
251
- return {
252
- target: "output.splitRoutesChunks",
253
- schema: {
254
- type: "boolean"
255
- }
256
- };
257
- },
258
250
  async fileChange(e) {
259
251
  const appContext = api.useAppContext();
260
252
  const { appDirectory } = appContext;
@@ -110,10 +110,10 @@ const html = (partials) => `
110
110
  </script>
111
111
  ${partials.head.join("\n")}
112
112
 
113
- <!--<?- chunksMap.css ?>-->
114
113
  </head>
115
114
 
116
115
  <body>
116
+ <!--<?- chunksMap.css ?>-->
117
117
  <noscript>
118
118
  We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
119
119
  </noscript>
@@ -182,10 +182,8 @@ const fileSystemRoutes = async ({
182
182
  ssrMode,
183
183
  nestedRoutesEntry,
184
184
  entryName,
185
- internalDirectory,
186
- splitRoutesChunks = true
185
+ internalDirectory
187
186
  }) => {
188
- const components = [];
189
187
  const loadings = [];
190
188
  const errors = [];
191
189
  const loaders = [];
@@ -244,30 +242,20 @@ const fileSystemRoutes = async ({
244
242
  };
245
243
  }
246
244
  if (route._component) {
247
- if (splitRoutesChunks) {
248
- if (route.isRoot) {
249
- rootLayoutCode = `import RootLayout from '${route._component}'`;
250
- component = `RootLayout`;
251
- } else if (ssrMode === "string") {
252
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
253
- component = `loadable(${lazyImport})`;
254
- } else {
255
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
256
- component = `lazy(${lazyImport})`;
257
- }
245
+ if (route.isRoot) {
246
+ rootLayoutCode = `import RootLayout from '${route._component}'`;
247
+ component = `RootLayout`;
248
+ } else if (ssrMode === "string") {
249
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
250
+ component = `loadable(${lazyImport})`;
258
251
  } else {
259
- components.push(route._component);
260
- component = `component_${components.length - 1}`;
252
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
253
+ component = `lazy(${lazyImport})`;
261
254
  }
262
255
  }
263
256
  } else if (route._component) {
264
- if (splitRoutesChunks) {
265
- lazyImport = `() => import('${route._component}')`;
266
- component = `loadable(${lazyImport})`;
267
- } else {
268
- components.push(route._component);
269
- component = `component_${components.length - 1}`;
270
- }
257
+ lazyImport = `() => import('${route._component}')`;
258
+ component = `loadable(${lazyImport})`;
271
259
  }
272
260
  const finalRoute = {
273
261
  ...route,
@@ -288,24 +276,20 @@ const fileSystemRoutes = async ({
288
276
  for (const route of routes) {
289
277
  if ("type" in route) {
290
278
  const newRoute = traverseRouteTree(route);
291
- routeComponentsCode += `${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, '"')},`;
279
+ routeComponentsCode += `${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, '"')},`;
292
280
  } else {
293
281
  const component = `loadable(() => import('${route._component}'))`;
294
282
  const finalRoute = {
295
283
  ...route,
296
284
  component
297
285
  };
298
- routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2")},`;
286
+ routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
299
287
  }
300
288
  }
301
289
  routeComponentsCode += `
302
290
  ];`;
303
291
  const importLoadingCode = loadings.map((loading, index2) => {
304
292
  return `import loading_${index2} from '${loading}';
305
- `;
306
- }).join("");
307
- const importComponentsCode = components.map((component, index2) => {
308
- return `import component_${index2} from '${component}';
309
293
  `;
310
294
  }).join("");
311
295
  const importErrorComponentsCode = errors.map((error, index2) => {
@@ -330,7 +314,6 @@ const fileSystemRoutes = async ({
330
314
  await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
331
315
  return `
332
316
  ${importLazyCode}
333
- ${importComponentsCode}
334
317
  ${rootLayoutCode}
335
318
  ${importLoadingCode}
336
319
  ${importErrorComponentsCode}
@@ -30,10 +30,12 @@ __export(builder_exports, {
30
30
  createBuilderGenerator: () => createBuilderGenerator
31
31
  });
32
32
  module.exports = __toCommonJS(builder_exports);
33
+ var import_utils = require("@modern-js/utils");
33
34
  async function createBuilderGenerator(bundler) {
34
35
  if (bundler === "rspack") {
35
36
  try {
36
37
  const { createRspackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-rspack")));
38
+ import_utils.logger.info("Using Rspack ✨");
37
39
  return createRspackBuilderForModern;
38
40
  } catch (_) {
39
41
  throw new Error(
@@ -245,7 +245,7 @@ var generateCode = function() {
245
245
  }
246
246
  function _generateEntryCode() {
247
247
  _generateEntryCode = _asyncToGenerator(function(entrypoint) {
248
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config2_output, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, serverLoaderCombined, serverLoaderFile, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
248
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, serverLoaderCombined, serverLoaderFile, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
249
249
  return __generator(this, function(_state) {
250
250
  switch(_state.label){
251
251
  case 0:
@@ -322,8 +322,7 @@ var generateCode = function() {
322
322
  ssrMode: useSSG ? "string" : mode,
323
323
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
324
324
  entryName: entrypoint.entryName,
325
- internalDirectory: internalDirectory,
326
- splitRoutesChunks: config2 === null || config2 === void 0 ? void 0 : (_config2_output = config2.output) === null || _config2_output === void 0 ? void 0 : _config2_output.splitRoutesChunks
325
+ internalDirectory: internalDirectory
327
326
  })
328
327
  ];
329
328
  case 4:
@@ -638,14 +638,6 @@ var analyze_default = function(param) {
638
638
  });
639
639
  })();
640
640
  },
641
- validateSchema: function validateSchema() {
642
- return {
643
- target: "output.splitRoutesChunks",
644
- schema: {
645
- type: "boolean"
646
- }
647
- };
648
- },
649
641
  fileChange: function fileChange(e) {
650
642
  return _asyncToGenerator(function() {
651
643
  var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
@@ -237,7 +237,7 @@ var renderFunction = function(param) {
237
237
  }).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");
238
238
  };
239
239
  var html = function(partials) {
240
- 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");
240
+ 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</head>\n\n<body>\n <!--<?- chunksMap.css ?>-->\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");
241
241
  };
242
242
  var routesForServer = function(param) {
243
243
  var routes = param.routes;
@@ -298,12 +298,11 @@ var routesForServer = function(param) {
298
298
  };
299
299
  var fileSystemRoutes = function() {
300
300
  var _ref = _asyncToGenerator(function(param) {
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
+ 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;
302
302
  return __generator(this, function(_state) {
303
303
  switch(_state.label){
304
304
  case 0:
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
+ routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
307
306
  loadings = [];
308
307
  errors = [];
309
308
  loaders = [];
@@ -352,30 +351,20 @@ var fileSystemRoutes = function() {
352
351
  };
353
352
  }
354
353
  if (route._component) {
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
- }
354
+ if (route.isRoot) {
355
+ rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
356
+ component = "RootLayout";
357
+ } else if (ssrMode === "string") {
358
+ lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
359
+ component = "loadable(".concat(lazyImport, ")");
366
360
  } else {
367
- components.push(route._component);
368
- component = "component_".concat(components.length - 1);
361
+ lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
362
+ component = "lazy(".concat(lazyImport, ")");
369
363
  }
370
364
  }
371
365
  } else if (route._component) {
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
- }
366
+ lazyImport = "() => import('".concat(route._component, "')");
367
+ component = "loadable(".concat(lazyImport, ")");
379
368
  }
380
369
  var finalRoute = _objectSpreadProps(_objectSpread({}, route), {
381
370
  lazyImport: lazyImport,
@@ -396,13 +385,13 @@ var fileSystemRoutes = function() {
396
385
  route = _step.value;
397
386
  if ("type" in route) {
398
387
  newRoute = traverseRouteTree(route);
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, '"'), ",");
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, '"'), ",");
400
389
  } else {
401
390
  component = "loadable(() => import('".concat(route._component, "'))");
402
391
  finalRoute = _objectSpreadProps(_objectSpread({}, route), {
403
392
  component: component
404
393
  });
405
- routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2"), ",");
394
+ routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1"), ",");
406
395
  }
407
396
  }
408
397
  } catch (err) {
@@ -423,9 +412,6 @@ var fileSystemRoutes = function() {
423
412
  importLoadingCode = loadings.map(function(loading, index2) {
424
413
  return "import loading_".concat(index2, " from '").concat(loading, "';\n");
425
414
  }).join("");
426
- importComponentsCode = components.map(function(component, index2) {
427
- return "import component_".concat(index2, " from '").concat(component, "';\n");
428
- }).join("");
429
415
  importErrorComponentsCode = errors.map(function(error, index2) {
430
416
  return "import error_".concat(index2, " from '").concat(error, "';\n");
431
417
  }).join("");
@@ -468,7 +454,7 @@ var fileSystemRoutes = function() {
468
454
  _state.sent();
469
455
  return [
470
456
  2,
471
- "\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
457
+ "\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
472
458
  ];
473
459
  }
474
460
  });
@@ -122,6 +122,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
122
122
  };
123
123
  }
124
124
  };
125
+ import { logger } from "@modern-js/utils";
125
126
  function createBuilderGenerator(bundler) {
126
127
  return _createBuilderGenerator.apply(this, arguments);
127
128
  }
@@ -149,6 +150,7 @@ function _createBuilderGenerator() {
149
150
  ];
150
151
  case 2:
151
152
  createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
153
+ logger.info("Using Rspack ✨");
152
154
  return [
153
155
  2,
154
156
  createRspackBuilderForModern
@@ -81,7 +81,6 @@ const generateCode = async (appContext, config, entrypoints, api) => {
81
81
  const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
82
82
  await Promise.all(entrypoints.map(generateEntryCode));
83
83
  async function generateEntryCode(entrypoint) {
84
- var _a;
85
84
  const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
86
85
  if (isAutoMount) {
87
86
  if (fileSystemRoutes) {
@@ -144,8 +143,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
144
143
  ssrMode: useSSG ? "string" : mode,
145
144
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
146
145
  entryName: entrypoint.entryName,
147
- internalDirectory,
148
- splitRoutesChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRoutesChunks
146
+ internalDirectory
149
147
  })
150
148
  });
151
149
  if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
@@ -227,14 +227,6 @@ var analyze_default = ({
227
227
  imports
228
228
  };
229
229
  },
230
- validateSchema() {
231
- return {
232
- target: "output.splitRoutesChunks",
233
- schema: {
234
- type: "boolean"
235
- }
236
- };
237
- },
238
230
  async fileChange(e) {
239
231
  const appContext = api.useAppContext();
240
232
  const { appDirectory } = appContext;
@@ -73,10 +73,10 @@ const html = (partials) => `
73
73
  </script>
74
74
  ${partials.head.join("\n")}
75
75
 
76
- <!--<?- chunksMap.css ?>-->
77
76
  </head>
78
77
 
79
78
  <body>
79
+ <!--<?- chunksMap.css ?>-->
80
80
  <noscript>
81
81
  We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
82
82
  </noscript>
@@ -145,10 +145,8 @@ const fileSystemRoutes = async ({
145
145
  ssrMode,
146
146
  nestedRoutesEntry,
147
147
  entryName,
148
- internalDirectory,
149
- splitRoutesChunks = true
148
+ internalDirectory
150
149
  }) => {
151
- const components = [];
152
150
  const loadings = [];
153
151
  const errors = [];
154
152
  const loaders = [];
@@ -207,30 +205,20 @@ const fileSystemRoutes = async ({
207
205
  };
208
206
  }
209
207
  if (route._component) {
210
- if (splitRoutesChunks) {
211
- if (route.isRoot) {
212
- rootLayoutCode = `import RootLayout from '${route._component}'`;
213
- component = `RootLayout`;
214
- } else if (ssrMode === "string") {
215
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
216
- component = `loadable(${lazyImport})`;
217
- } else {
218
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
219
- component = `lazy(${lazyImport})`;
220
- }
208
+ if (route.isRoot) {
209
+ rootLayoutCode = `import RootLayout from '${route._component}'`;
210
+ component = `RootLayout`;
211
+ } else if (ssrMode === "string") {
212
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
213
+ component = `loadable(${lazyImport})`;
221
214
  } else {
222
- components.push(route._component);
223
- component = `component_${components.length - 1}`;
215
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
216
+ component = `lazy(${lazyImport})`;
224
217
  }
225
218
  }
226
219
  } else if (route._component) {
227
- if (splitRoutesChunks) {
228
- lazyImport = `() => import('${route._component}')`;
229
- component = `loadable(${lazyImport})`;
230
- } else {
231
- components.push(route._component);
232
- component = `component_${components.length - 1}`;
233
- }
220
+ lazyImport = `() => import('${route._component}')`;
221
+ component = `loadable(${lazyImport})`;
234
222
  }
235
223
  const finalRoute = {
236
224
  ...route,
@@ -251,24 +239,20 @@ const fileSystemRoutes = async ({
251
239
  for (const route of routes) {
252
240
  if ("type" in route) {
253
241
  const newRoute = traverseRouteTree(route);
254
- routeComponentsCode += `${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, '"')},`;
242
+ routeComponentsCode += `${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, '"')},`;
255
243
  } else {
256
244
  const component = `loadable(() => import('${route._component}'))`;
257
245
  const finalRoute = {
258
246
  ...route,
259
247
  component
260
248
  };
261
- routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy[^"]*)"/g, "$2")},`;
249
+ routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
262
250
  }
263
251
  }
264
252
  routeComponentsCode += `
265
253
  ];`;
266
254
  const importLoadingCode = loadings.map((loading, index2) => {
267
255
  return `import loading_${index2} from '${loading}';
268
- `;
269
- }).join("");
270
- const importComponentsCode = components.map((component, index2) => {
271
- return `import component_${index2} from '${component}';
272
256
  `;
273
257
  }).join("");
274
258
  const importErrorComponentsCode = errors.map((error, index2) => {
@@ -293,7 +277,6 @@ const fileSystemRoutes = async ({
293
277
  await fs.writeJSON(loadersMapFile, loadersMap);
294
278
  return `
295
279
  ${importLazyCode}
296
- ${importComponentsCode}
297
280
  ${rootLayoutCode}
298
281
  ${importLoadingCode}
299
282
  ${importErrorComponentsCode}
@@ -1,7 +1,9 @@
1
+ import { logger } from "@modern-js/utils";
1
2
  async function createBuilderGenerator(bundler) {
2
3
  if (bundler === "rspack") {
3
4
  try {
4
5
  const { createRspackBuilderForModern } = await import("./builder-rspack");
6
+ logger.info("Using Rspack ✨");
5
7
  return createRspackBuilderForModern;
6
8
  } catch (_) {
7
9
  throw new Error(
@@ -23,7 +23,9 @@ const NESTED_ROUTE = {
23
23
  PAGE_LOADER_FILE: "page.loader",
24
24
  LOADING_FILE: "loading",
25
25
  ERROR_FILE: "error",
26
- LOADER_FILE: "loader"
26
+ LOADER_FILE: "loader",
27
+ SPLATE_FILE: "$",
28
+ SPLATE_LOADER_FILE: "$.loader"
27
29
  };
28
30
  const APP_CONFIG_NAME = "config";
29
31
  const APP_INIT_EXPORTED = "init";
@@ -38,7 +38,8 @@ import {
38
38
  getEntryOptions,
39
39
  SERVER_BUNDLE_DIRECTORY,
40
40
  MAIN_ENTRY_NAME,
41
- removeTailSlash
41
+ removeTailSlash,
42
+ SERVER_WORKER_BUNDLE_DIRECTORY
42
43
  } from "@modern-js/utils";
43
44
  import { walkDirectory } from "./utils";
44
45
  const applyBaseUrl = (baseUrl, routes) => {
@@ -101,7 +102,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
101
102
  const {
102
103
  html: { disableHtmlFolder },
103
104
  output: { distPath: { html: htmlPath } = {} },
104
- server: { baseUrl, routes, ssr, ssrByEntries }
105
+ server: { baseUrl, routes, ssr, ssrByEntries, worker }
105
106
  } = config;
106
107
  const { packageName } = appContext;
107
108
  let htmlRoutes = entrypoints.reduce(
@@ -113,6 +114,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
113
114
  packageName
114
115
  );
115
116
  const isSSR = Boolean(entryOptions);
117
+ const isWorker = Boolean(worker);
116
118
  const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
117
119
  let route = {
118
120
  urlPath: `/${entryName === MAIN_ENTRY_NAME ? "" : entryName}`,
@@ -125,6 +127,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
125
127
  isSPA: true,
126
128
  isSSR,
127
129
  responseHeaders: resHeaders,
130
+ worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
128
131
  bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
129
132
  };
130
133
  if (routes == null ? void 0 : routes.hasOwnProperty(entryName)) {
@@ -49,12 +49,12 @@ import {
49
49
  isDevCommand
50
50
  } from "@modern-js/utils";
51
51
  import { cloneDeep } from "@modern-js/utils/lodash";
52
- import { createBuilderForModern } from "../builder";
53
52
  import { printInstructions } from "../utils/printInstructions";
54
53
  import { generateRoutes } from "../utils/routes";
55
54
  import { emitResolvedConfig } from "../utils/config";
56
55
  import { getSelectedEntries } from "../utils/getSelectedEntries";
57
56
  import { initialNormalizedConfig } from "../config";
57
+ import { createBuilderGenerator } from "../builder";
58
58
  import {
59
59
  getServerLoadersFile,
60
60
  isPageComponentFile,
@@ -67,7 +67,9 @@ import {
67
67
  APP_INIT_IMPORTED
68
68
  } from "./constants";
69
69
  const debug = createDebugger("plugin-analyze");
70
- var analyze_default = () => ({
70
+ var analyze_default = ({
71
+ bundler
72
+ }) => ({
71
73
  name: "@modern-js/plugin-analyze",
72
74
  setup: (api) => {
73
75
  let pagesDir = [];
@@ -159,56 +161,55 @@ var analyze_default = () => ({
159
161
  if (buildCommands.includes(command)) {
160
162
  let _b;
161
163
  const normalizedConfig = api.useResolvedConfigContext();
164
+ const createBuilderForModern = yield createBuilderGenerator(bundler);
162
165
  const builder = yield createBuilderForModern({
163
166
  normalizedConfig,
164
167
  appContext,
165
- compatPluginConfig: {
166
- onBeforeBuild(_0) {
167
- return __async(this, arguments, function* ({ bundlerConfigs }) {
168
- const hookRunners2 = api.useHookRunners();
169
- yield generateRoutes(appContext);
170
- yield hookRunners2.beforeBuild({ bundlerConfigs });
168
+ onBeforeBuild(_0) {
169
+ return __async(this, arguments, function* ({ bundlerConfigs }) {
170
+ const hookRunners2 = api.useHookRunners();
171
+ yield generateRoutes(appContext);
172
+ yield hookRunners2.beforeBuild({
173
+ bundlerConfigs
171
174
  });
172
- },
173
- onAfterBuild(_0) {
174
- return __async(this, arguments, function* ({ stats }) {
175
- const hookRunners2 = api.useHookRunners();
176
- yield hookRunners2.afterBuild({ stats });
177
- yield emitResolvedConfig(
178
- appContext.appDirectory,
179
- normalizedConfig
180
- );
181
- });
182
- },
183
- onDevCompileDone(_0) {
184
- return __async(this, arguments, function* ({ isFirstCompile }) {
185
- const hookRunners2 = api.useHookRunners();
186
- if (process.stdout.isTTY || isFirstCompile) {
187
- hookRunners2.afterDev();
188
- if (isFirstCompile) {
189
- printInstructions(
190
- hookRunners2,
191
- appContext,
192
- normalizedConfig
193
- );
194
- }
175
+ });
176
+ },
177
+ onAfterBuild(_0) {
178
+ return __async(this, arguments, function* ({ stats }) {
179
+ const hookRunners2 = api.useHookRunners();
180
+ yield hookRunners2.afterBuild({ stats });
181
+ yield emitResolvedConfig(
182
+ appContext.appDirectory,
183
+ normalizedConfig
184
+ );
185
+ });
186
+ },
187
+ onDevCompileDone(_0) {
188
+ return __async(this, arguments, function* ({ isFirstCompile }) {
189
+ const hookRunners2 = api.useHookRunners();
190
+ if (process.stdout.isTTY || isFirstCompile) {
191
+ hookRunners2.afterDev();
192
+ if (isFirstCompile) {
193
+ printInstructions(hookRunners2, appContext, normalizedConfig);
195
194
  }
195
+ }
196
+ });
197
+ },
198
+ onBeforeCreateCompiler(_0) {
199
+ return __async(this, arguments, function* ({ bundlerConfigs }) {
200
+ const hookRunners2 = api.useHookRunners();
201
+ yield hookRunners2.beforeCreateCompiler({
202
+ bundlerConfigs
196
203
  });
197
- },
198
- onBeforeCreateCompiler(_0) {
199
- return __async(this, arguments, function* ({ bundlerConfigs }) {
200
- const hookRunners2 = api.useHookRunners();
201
- yield hookRunners2.beforeCreateCompiler({
202
- bundlerConfigs
203
- });
204
- });
205
- },
206
- onAfterCreateCompiler(_0) {
207
- return __async(this, arguments, function* ({ compiler }) {
208
- const hookRunners2 = api.useHookRunners();
209
- yield hookRunners2.afterCreateCompiler({ compiler });
204
+ });
205
+ },
206
+ onAfterCreateCompiler(_0) {
207
+ return __async(this, arguments, function* ({ compiler }) {
208
+ const hookRunners2 = api.useHookRunners();
209
+ yield hookRunners2.afterCreateCompiler({
210
+ compiler
210
211
  });
211
- }
212
+ });
212
213
  }
213
214
  });
214
215
  builder.addPlugins(resolvedConfig.builderPlugins);
@@ -251,7 +252,7 @@ var analyze_default = () => ({
251
252
  },
252
253
  resolvedConfig({ resolved }) {
253
254
  const appContext = api.useAppContext();
254
- const config = initialNormalizedConfig(resolved, appContext);
255
+ const config = initialNormalizedConfig(resolved, appContext, bundler);
255
256
  return {
256
257
  resolved: config
257
258
  };