@modern-js/app-tools 2.31.2 → 2.31.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 (257) hide show
  1. package/dist/cjs/analyze/constants.js +4 -0
  2. package/dist/cjs/analyze/nestedRoutes.js +14 -1
  3. package/dist/cjs/analyze/templates.js +10 -7
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  5. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +24 -22
  6. package/dist/cjs/index.js +19 -0
  7. package/dist/esm/analyze/constants.js +4 -0
  8. package/dist/esm/analyze/nestedRoutes.js +16 -1
  9. package/dist/esm/analyze/templates.js +10 -7
  10. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
  11. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +24 -22
  12. package/dist/esm/index.js +55 -1
  13. package/dist/esm-node/analyze/constants.js +4 -0
  14. package/dist/esm-node/analyze/nestedRoutes.js +14 -1
  15. package/dist/esm-node/analyze/templates.js +10 -7
  16. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
  17. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +24 -22
  18. package/dist/esm-node/index.js +20 -1
  19. package/dist/js/modern/analyze/constants.js +54 -0
  20. package/dist/js/modern/analyze/generateCode.js +247 -0
  21. package/dist/js/modern/analyze/getBundleEntry.js +71 -0
  22. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
  23. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
  24. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
  25. package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
  26. package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
  27. package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
  28. package/dist/js/modern/analyze/getServerRoutes.js +175 -0
  29. package/dist/js/modern/analyze/index.js +332 -0
  30. package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
  31. package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
  32. package/dist/js/modern/analyze/nestedRoutes.js +157 -0
  33. package/dist/js/modern/analyze/templates.js +334 -0
  34. package/dist/js/modern/analyze/utils.js +141 -0
  35. package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
  36. package/dist/js/modern/builder/index.js +159 -0
  37. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  38. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  39. package/dist/js/modern/builder/share.js +46 -0
  40. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
  41. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
  42. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
  43. package/dist/js/modern/commands/build.js +91 -0
  44. package/dist/js/modern/commands/deploy.js +28 -0
  45. package/dist/js/modern/commands/dev.js +109 -0
  46. package/dist/js/modern/commands/index.js +3 -0
  47. package/dist/js/modern/commands/inspect.js +38 -0
  48. package/dist/js/modern/commands/serve.js +54 -0
  49. package/dist/js/modern/config/default.js +175 -0
  50. package/dist/js/modern/config/index.js +8 -0
  51. package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
  52. package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
  53. package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
  54. package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
  55. package/dist/js/modern/config/initial/index.js +16 -0
  56. package/dist/js/modern/config/initial/inits.js +152 -0
  57. package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
  58. package/dist/js/modern/defineConfig.js +27 -0
  59. package/dist/js/modern/exports/server.js +4 -0
  60. package/dist/js/modern/hooks.js +35 -0
  61. package/dist/js/modern/index.js +211 -0
  62. package/dist/js/modern/initialize/index.js +124 -0
  63. package/dist/js/modern/locale/en.js +36 -0
  64. package/dist/js/modern/locale/index.js +9 -0
  65. package/dist/js/modern/locale/zh.js +36 -0
  66. package/dist/js/modern/schema/Schema.js +40 -0
  67. package/dist/js/modern/schema/index.js +88 -0
  68. package/dist/js/modern/schema/legacy.js +148 -0
  69. package/dist/js/modern/types/config/deploy.js +0 -0
  70. package/dist/js/modern/types/config/dev.js +0 -0
  71. package/dist/js/modern/types/config/experiments.js +0 -0
  72. package/dist/js/modern/types/config/html.js +0 -0
  73. package/dist/js/modern/types/config/index.js +1 -0
  74. package/dist/js/modern/types/config/output.js +0 -0
  75. package/dist/js/modern/types/config/performance.js +0 -0
  76. package/dist/js/modern/types/config/security.js +0 -0
  77. package/dist/js/modern/types/config/source.js +0 -0
  78. package/dist/js/modern/types/config/tools.js +0 -0
  79. package/dist/js/modern/types/hooks.js +0 -0
  80. package/dist/js/modern/types/index.js +3 -0
  81. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  82. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  83. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  84. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  85. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  86. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  87. package/dist/js/modern/utils/config.js +128 -0
  88. package/dist/js/modern/utils/createServer.js +75 -0
  89. package/dist/js/modern/utils/env.js +15 -0
  90. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  91. package/dist/js/modern/utils/getSelectedEntries.js +58 -0
  92. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  93. package/dist/js/modern/utils/language.js +8 -0
  94. package/dist/js/modern/utils/printInstructions.js +31 -0
  95. package/dist/js/modern/utils/restart.js +44 -0
  96. package/dist/js/modern/utils/routes.js +30 -0
  97. package/dist/js/modern/utils/types.js +0 -0
  98. package/dist/js/node/analyze/constants.js +98 -0
  99. package/dist/js/node/analyze/generateCode.js +271 -0
  100. package/dist/js/node/analyze/getBundleEntry.js +95 -0
  101. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
  102. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
  103. package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
  104. package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
  105. package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
  106. package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
  107. package/dist/js/node/analyze/getServerRoutes.js +194 -0
  108. package/dist/js/node/analyze/index.js +339 -0
  109. package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
  110. package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
  111. package/dist/js/node/analyze/nestedRoutes.js +184 -0
  112. package/dist/js/node/analyze/templates.js +365 -0
  113. package/dist/js/node/analyze/utils.js +172 -0
  114. package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
  115. package/dist/js/node/builder/index.js +177 -0
  116. package/dist/js/node/builder/loaders/routerLoader.js +38 -0
  117. package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
  118. package/dist/js/node/builder/share.js +75 -0
  119. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
  120. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
  121. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
  122. package/dist/js/node/commands/build.js +112 -0
  123. package/dist/js/node/commands/deploy.js +51 -0
  124. package/dist/js/node/commands/dev.js +126 -0
  125. package/dist/js/node/commands/index.js +19 -0
  126. package/dist/js/node/commands/inspect.js +61 -0
  127. package/dist/js/node/commands/serve.js +83 -0
  128. package/dist/js/node/config/default.js +197 -0
  129. package/dist/js/node/config/index.js +34 -0
  130. package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
  131. package/dist/js/node/config/initial/createOutputConfig.js +91 -0
  132. package/dist/js/node/config/initial/createSourceConfig.js +62 -0
  133. package/dist/js/node/config/initial/createToolsConfig.js +65 -0
  134. package/dist/js/node/config/initial/index.js +41 -0
  135. package/dist/js/node/config/initial/inits.js +175 -0
  136. package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
  137. package/dist/js/node/defineConfig.js +49 -0
  138. package/dist/js/node/exports/server.js +27 -0
  139. package/dist/js/node/hooks.js +54 -0
  140. package/dist/js/node/index.js +235 -0
  141. package/dist/js/node/initialize/index.js +134 -0
  142. package/dist/js/node/locale/en.js +59 -0
  143. package/dist/js/node/locale/index.js +33 -0
  144. package/dist/js/node/locale/zh.js +59 -0
  145. package/dist/js/node/schema/Schema.js +63 -0
  146. package/dist/js/node/schema/index.js +118 -0
  147. package/dist/js/node/schema/legacy.js +169 -0
  148. package/dist/js/node/types/config/deploy.js +15 -0
  149. package/dist/js/node/types/config/dev.js +15 -0
  150. package/dist/js/node/types/config/experiments.js +15 -0
  151. package/dist/js/node/types/config/html.js +15 -0
  152. package/dist/js/node/types/config/index.js +17 -0
  153. package/dist/js/node/types/config/output.js +15 -0
  154. package/dist/js/node/types/config/performance.js +15 -0
  155. package/dist/js/node/types/config/security.js +15 -0
  156. package/dist/js/node/types/config/source.js +15 -0
  157. package/dist/js/node/types/config/tools.js +15 -0
  158. package/dist/js/node/types/hooks.js +15 -0
  159. package/dist/js/node/types/index.js +19 -0
  160. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  161. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  162. package/dist/js/node/types/legacyConfig/index.js +15 -0
  163. package/dist/js/node/types/legacyConfig/output.js +15 -0
  164. package/dist/js/node/types/legacyConfig/source.js +15 -0
  165. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  166. package/dist/js/node/utils/config.js +153 -0
  167. package/dist/js/node/utils/createServer.js +106 -0
  168. package/dist/js/node/utils/env.js +38 -0
  169. package/dist/js/node/utils/generateWatchFiles.js +85 -0
  170. package/dist/js/node/utils/getSelectedEntries.js +81 -0
  171. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  172. package/dist/js/node/utils/language.js +31 -0
  173. package/dist/js/node/utils/printInstructions.js +54 -0
  174. package/dist/js/node/utils/restart.js +67 -0
  175. package/dist/js/node/utils/routes.js +59 -0
  176. package/dist/js/node/utils/types.js +15 -0
  177. package/dist/js/treeshaking/analyze/constants.js +40 -0
  178. package/dist/js/treeshaking/analyze/generateCode.js +485 -0
  179. package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
  180. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
  181. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  182. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
  183. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
  184. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
  185. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
  186. package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
  187. package/dist/js/treeshaking/analyze/index.js +697 -0
  188. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
  189. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
  190. package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
  191. package/dist/js/treeshaking/analyze/templates.js +468 -0
  192. package/dist/js/treeshaking/analyze/utils.js +374 -0
  193. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
  194. package/dist/js/treeshaking/builder/index.js +374 -0
  195. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  196. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  197. package/dist/js/treeshaking/builder/share.js +40 -0
  198. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
  199. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
  200. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
  201. package/dist/js/treeshaking/commands/build.js +291 -0
  202. package/dist/js/treeshaking/commands/deploy.js +154 -0
  203. package/dist/js/treeshaking/commands/dev.js +301 -0
  204. package/dist/js/treeshaking/commands/index.js +3 -0
  205. package/dist/js/treeshaking/commands/inspect.js +149 -0
  206. package/dist/js/treeshaking/commands/serve.js +199 -0
  207. package/dist/js/treeshaking/config/default.js +210 -0
  208. package/dist/js/treeshaking/config/index.js +3 -0
  209. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
  210. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
  211. package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
  212. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
  213. package/dist/js/treeshaking/config/initial/index.js +12 -0
  214. package/dist/js/treeshaking/config/initial/inits.js +209 -0
  215. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
  216. package/dist/js/treeshaking/defineConfig.js +61 -0
  217. package/dist/js/treeshaking/exports/server.js +2 -0
  218. package/dist/js/treeshaking/hooks.js +29 -0
  219. package/dist/js/treeshaking/index.js +706 -0
  220. package/dist/js/treeshaking/initialize/index.js +276 -0
  221. package/dist/js/treeshaking/locale/en.js +38 -0
  222. package/dist/js/treeshaking/locale/index.js +9 -0
  223. package/dist/js/treeshaking/locale/zh.js +38 -0
  224. package/dist/js/treeshaking/schema/Schema.js +273 -0
  225. package/dist/js/treeshaking/schema/index.js +181 -0
  226. package/dist/js/treeshaking/schema/legacy.js +337 -0
  227. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  228. package/dist/js/treeshaking/types/config/dev.js +1 -0
  229. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  230. package/dist/js/treeshaking/types/config/html.js +1 -0
  231. package/dist/js/treeshaking/types/config/index.js +1 -0
  232. package/dist/js/treeshaking/types/config/output.js +1 -0
  233. package/dist/js/treeshaking/types/config/performance.js +1 -0
  234. package/dist/js/treeshaking/types/config/security.js +1 -0
  235. package/dist/js/treeshaking/types/config/source.js +1 -0
  236. package/dist/js/treeshaking/types/config/tools.js +1 -0
  237. package/dist/js/treeshaking/types/hooks.js +1 -0
  238. package/dist/js/treeshaking/types/index.js +3 -0
  239. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  240. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  241. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  242. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  243. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  244. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  245. package/dist/js/treeshaking/utils/config.js +302 -0
  246. package/dist/js/treeshaking/utils/createServer.js +258 -0
  247. package/dist/js/treeshaking/utils/env.js +13 -0
  248. package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
  249. package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
  250. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  251. package/dist/js/treeshaking/utils/language.js +6 -0
  252. package/dist/js/treeshaking/utils/printInstructions.js +152 -0
  253. package/dist/js/treeshaking/utils/restart.js +187 -0
  254. package/dist/js/treeshaking/utils/routes.js +153 -0
  255. package/dist/js/treeshaking/utils/types.js +1 -0
  256. package/dist/types/analyze/constants.d.ts +4 -0
  257. package/package.json +14 -14
@@ -107,8 +107,12 @@ const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
107
107
  const NESTED_ROUTE = {
108
108
  LAYOUT_FILE: "layout",
109
109
  LAYOUT_LOADER_FILE: "layout.loader",
110
+ LAYOUT_DATA_FILE: "layout.data",
111
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
110
112
  PAGE_FILE: "page",
111
113
  PAGE_LOADER_FILE: "page.loader",
114
+ PAGE_DATA_FILE: "layout.data",
115
+ PAGE_CLIENT_LOADER: "page.data.client",
112
116
  LOADING_FILE: "loading",
113
117
  ERROR_FILE: "error",
114
118
  LOADER_FILE: "loader",
@@ -66,7 +66,8 @@ const optimizeRoute = (routeTree) => {
66
66
  ];
67
67
  }
68
68
  const { children } = routeTree;
69
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
69
+ const hasPage = children.some((child) => child.index);
70
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData && !hasPage) {
70
71
  const newRoutes = children.map((child) => {
71
72
  const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
72
73
  const newRoute = {
@@ -142,6 +143,12 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
142
143
  route.loader = itemPath;
143
144
  }
144
145
  }
146
+ if (itemWithoutExt === _constants.NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
147
+ route.clientData = itemPath;
148
+ }
149
+ if (itemWithoutExt === _constants.NESTED_ROUTE.LAYOUT_DATA_FILE) {
150
+ route.data = itemPath;
151
+ }
145
152
  if (itemWithoutExt === _constants.NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
146
153
  if (!route.config) {
147
154
  route.config = itemPath;
@@ -153,6 +160,12 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
153
160
  if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
154
161
  pageLoaderFile = itemPath;
155
162
  }
163
+ if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_CLIENT_LOADER) {
164
+ route.clientData = itemPath;
165
+ }
166
+ if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_DATA_FILE) {
167
+ route.data = itemPath;
168
+ }
156
169
  if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_CONFIG_FILE) {
157
170
  pageConfigFile = itemPath;
158
171
  }
@@ -164,12 +164,13 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
164
164
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
165
165
  `;
166
166
  let rootLayoutCode = ``;
167
- const getDataLoaderPath = (loaderId) => {
167
+ const getDataLoaderPath = (loaderId, clientData) => {
168
168
  if (!ssrMode) {
169
169
  return "";
170
170
  }
171
+ const clientDataStr = clientData ? `&clientData=${clientData}` : "";
171
172
  if (nestedRoutesEntry) {
172
- return `?mapFile=${(0, _utils.slash)(loadersMapFile)}&loaderId=${loaderId}`;
173
+ return `?mapFile=${(0, _utils.slash)(loadersMapFile)}&loaderId=${loaderId}${clientDataStr}`;
173
174
  }
174
175
  return "";
175
176
  };
@@ -194,15 +195,17 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
194
195
  errors.push(route.error);
195
196
  error = `error_${errors.length - 1}`;
196
197
  }
197
- if (route.loader) {
198
+ if (route.loader || route.data) {
198
199
  loaders.push(route.loader);
199
200
  const loaderId = loaders.length - 1;
200
201
  loader = `loader_${loaderId}`;
201
202
  loadersMap[loader] = {
202
203
  routeId: route.id,
203
- filePath: route.loader,
204
- inline: false
204
+ filePath: route.data || route.loader,
205
+ clientData: Boolean(route.clientData),
206
+ inline: Boolean(route.data)
205
207
  };
208
+ loader = `loader_${loaderId}`;
206
209
  }
207
210
  if (typeof route.config === "string") {
208
211
  configs.push(route.config);
@@ -301,10 +304,10 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
301
304
  let importLoadersCode = "";
302
305
  for (const [key, loaderInfo] of Object.entries(loadersMap)) {
303
306
  if (loaderInfo.inline) {
304
- importLoadersCode += `import { loader as ${key} } from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key)}";
307
+ importLoadersCode += `import { loader as ${key} } from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key, loaderInfo.clientData)}";
305
308
  `;
306
309
  } else {
307
- importLoadersCode += `import ${key} from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key)}";
310
+ importLoadersCode += `import ${key} from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key, loaderInfo.clientData)}";
308
311
  `;
309
312
  }
310
313
  }
@@ -154,6 +154,6 @@ function applySSRDataLoader(chain, options) {
154
154
  const { appDirectory } = appContext;
155
155
  const { entriesDir = "./src" } = normalizedConfig.source;
156
156
  const absolutePath = _path.resolve(appDirectory, entriesDir).split(_path.sep).join("(\\\\|/)");
157
- const reg = new RegExp(`${absolutePath}.*\\.loader\\.[t|j]s$`);
157
+ const reg = new RegExp(`${absolutePath}.*\\.(loader|data|data.client)\\.[t|j]sx?$`);
158
158
  chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
159
159
  }
@@ -164,28 +164,30 @@ class RouterPlugin {
164
164
  const oldHtml = compilation.assets[htmlName];
165
165
  const { enableInlineRouteManifests, disableFilenameHash, staticJsDir, scriptLoading, nonce } = this;
166
166
  const nonceAttr = nonce ? `nonce="${nonce}"` : "";
167
- if (enableInlineRouteManifests) {
168
- compilation.updateAsset(
169
- htmlName,
170
- new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
171
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
172
- void 0
173
- );
174
- } else {
175
- const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
176
- const scriptUrl = `${publicPath}${scriptPath}`;
177
- const scriptLoadingAttr = (
178
- // eslint-disable-next-line no-nested-ternary
179
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
180
- );
181
- const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
182
- compilation.updateAsset(
183
- htmlName,
184
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
185
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
186
- void 0
187
- );
188
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
167
+ if (oldHtml) {
168
+ if (enableInlineRouteManifests) {
169
+ compilation.updateAsset(
170
+ htmlName,
171
+ new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
172
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
173
+ void 0
174
+ );
175
+ } else {
176
+ const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
177
+ const scriptUrl = `${publicPath}${scriptPath}`;
178
+ const scriptLoadingAttr = (
179
+ // eslint-disable-next-line no-nested-ternary
180
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
181
+ );
182
+ const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
183
+ compilation.updateAsset(
184
+ htmlName,
185
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
186
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
187
+ void 0
188
+ );
189
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
190
+ }
189
191
  }
190
192
  }
191
193
  if (prevManifestAsset) {
package/dist/cjs/index.js CHANGED
@@ -123,6 +123,7 @@ const appTools = (options = {
123
123
  ...appContext,
124
124
  toolsType: "app-tools"
125
125
  });
126
+ const nestedRoutes = {};
126
127
  const locale = (0, _languagedetector.getLocaleLanguage)();
127
128
  _locale.i18n.changeLanguage({
128
129
  locale
@@ -208,6 +209,24 @@ const appTools = (options = {
208
209
  (0, _utils.cleanRequireCache)([
209
210
  require.resolve("./analyze")
210
211
  ]);
212
+ },
213
+ async modifyFileSystemRoutes({ entrypoint, routes }) {
214
+ nestedRoutes[entrypoint.entryName] = routes;
215
+ return {
216
+ entrypoint,
217
+ routes
218
+ };
219
+ },
220
+ async beforeGenerateRoutes({ entrypoint, code }) {
221
+ const { distDirectory } = api.useAppContext();
222
+ if (!_utils.fs.existsSync(distDirectory)) {
223
+ await _utils.fs.mkdir(distDirectory);
224
+ }
225
+ await _utils.fs.writeJSON(_path.default.resolve(distDirectory, _utils.NESTED_ROUTE_SPEC_FILE), nestedRoutes);
226
+ return {
227
+ entrypoint,
228
+ code
229
+ };
211
230
  }
212
231
  };
213
232
  }
@@ -28,8 +28,12 @@ export var FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
28
28
  export var NESTED_ROUTE = {
29
29
  LAYOUT_FILE: "layout",
30
30
  LAYOUT_LOADER_FILE: "layout.loader",
31
+ LAYOUT_DATA_FILE: "layout.data",
32
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
31
33
  PAGE_FILE: "page",
32
34
  PAGE_LOADER_FILE: "page.loader",
35
+ PAGE_DATA_FILE: "layout.data",
36
+ PAGE_CLIENT_LOADER: "page.data.client",
33
37
  LOADING_FILE: "loading",
34
38
  ERROR_FILE: "error",
35
39
  LOADER_FILE: "loader",
@@ -45,7 +45,10 @@ export var optimizeRoute = function(routeTree) {
45
45
  ];
46
46
  }
47
47
  var children = routeTree.children;
48
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
48
+ var hasPage = children.some(function(child) {
49
+ return child.index;
50
+ });
51
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData && !hasPage) {
49
52
  var newRoutes = children.map(function(child) {
50
53
  var routePath = "".concat(routeTree.path ? routeTree.path : "").concat(child.path ? "/".concat(child.path) : "");
51
54
  var newRoute = _object_spread_props(_object_spread({}, child), {
@@ -179,6 +182,12 @@ export var walk = function() {
179
182
  route.loader = itemPath;
180
183
  }
181
184
  }
185
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
186
+ route.clientData = itemPath;
187
+ }
188
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_DATA_FILE) {
189
+ route.data = itemPath;
190
+ }
182
191
  if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
183
192
  if (!route.config) {
184
193
  route.config = itemPath;
@@ -190,6 +199,12 @@ export var walk = function() {
190
199
  if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
191
200
  pageLoaderFile = itemPath;
192
201
  }
202
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CLIENT_LOADER) {
203
+ route.clientData = itemPath;
204
+ }
205
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_DATA_FILE) {
206
+ route.data = itemPath;
207
+ }
193
208
  if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
194
209
  pageConfigFile = itemPath;
195
210
  }
@@ -99,12 +99,13 @@ export var fileSystemRoutes = function() {
99
99
  loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
100
100
  importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
101
101
  rootLayoutCode = "";
102
- getDataLoaderPath = function(loaderId) {
102
+ getDataLoaderPath = function(loaderId, clientData) {
103
103
  if (!ssrMode) {
104
104
  return "";
105
105
  }
106
+ var clientDataStr = clientData ? "&clientData=".concat(clientData) : "";
106
107
  if (nestedRoutesEntry) {
107
- return "?mapFile=".concat(slash(loadersMapFile), "&loaderId=").concat(loaderId);
108
+ return "?mapFile=".concat(slash(loadersMapFile), "&loaderId=").concat(loaderId).concat(clientDataStr);
108
109
  }
109
110
  return "";
110
111
  };
@@ -129,15 +130,17 @@ export var fileSystemRoutes = function() {
129
130
  errors.push(route2.error);
130
131
  error = "error_".concat(errors.length - 1);
131
132
  }
132
- if (route2.loader) {
133
+ if (route2.loader || route2.data) {
133
134
  loaders.push(route2.loader);
134
135
  var loaderId = loaders.length - 1;
135
136
  loader = "loader_".concat(loaderId);
136
137
  loadersMap[loader] = {
137
138
  routeId: route2.id,
138
- filePath: route2.loader,
139
- inline: false
139
+ filePath: route2.data || route2.loader,
140
+ clientData: Boolean(route2.clientData),
141
+ inline: Boolean(route2.data)
140
142
  };
143
+ loader = "loader_".concat(loaderId);
141
144
  }
142
145
  if (typeof route2.config === "string") {
143
146
  configs.push(route2.config);
@@ -252,9 +255,9 @@ export var fileSystemRoutes = function() {
252
255
  for (_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
253
256
  _step_value = _sliced_to_array(_step1.value, 2), key = _step_value[0], loaderInfo = _step_value[1];
254
257
  if (loaderInfo.inline) {
255
- importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key), '";\n');
258
+ importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key, loaderInfo.clientData), '";\n');
256
259
  } else {
257
- importLoadersCode += "import ".concat(key, ' from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key), '";\n');
260
+ importLoadersCode += "import ".concat(key, ' from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key, loaderInfo.clientData), '";\n');
258
261
  }
259
262
  }
260
263
  } catch (err) {
@@ -253,6 +253,6 @@ function applySSRDataLoader(chain, options) {
253
253
  var appDirectory = appContext.appDirectory;
254
254
  var _normalizedConfig_source = normalizedConfig.source, _normalizedConfig_source_entriesDir = _normalizedConfig_source.entriesDir, entriesDir = _normalizedConfig_source_entriesDir === void 0 ? "./src" : _normalizedConfig_source_entriesDir;
255
255
  var absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
256
- var reg = new RegExp("".concat(absolutePath, ".*\\.loader\\.[t|j]s$"));
256
+ var reg = new RegExp("".concat(absolutePath, ".*\\.(loader|data|data.client)\\.[t|j]sx?$"));
257
257
  chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
258
258
  }
@@ -172,28 +172,30 @@ export var RouterPlugin = /* @__PURE__ */ function() {
172
172
  var oldHtml = compilation.assets[htmlName];
173
173
  var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
174
174
  var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
175
- if (enableInlineRouteManifests) {
176
- compilation.updateAsset(
177
- htmlName,
178
- new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
179
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
180
- void 0
181
- );
182
- } else {
183
- var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
184
- var scriptUrl = "".concat(publicPath).concat(scriptPath);
185
- var scriptLoadingAttr = (
186
- // eslint-disable-next-line no-nested-ternary
187
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
188
- );
189
- var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
190
- compilation.updateAsset(
191
- htmlName,
192
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
193
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
194
- void 0
195
- );
196
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
175
+ if (oldHtml) {
176
+ if (enableInlineRouteManifests) {
177
+ compilation.updateAsset(
178
+ htmlName,
179
+ new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
180
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
181
+ void 0
182
+ );
183
+ } else {
184
+ var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
185
+ var scriptUrl = "".concat(publicPath).concat(scriptPath);
186
+ var scriptLoadingAttr = (
187
+ // eslint-disable-next-line no-nested-ternary
188
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
189
+ );
190
+ var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
191
+ compilation.updateAsset(
192
+ htmlName,
193
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
194
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
195
+ void 0
196
+ );
197
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
198
+ }
197
199
  }
198
200
  };
199
201
  stats = compilation.getStats().toJson({
package/dist/esm/index.js CHANGED
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "path";
6
6
  import { lintPlugin } from "@modern-js/plugin-lint";
7
- import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
7
+ import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
8
8
  import { castArray } from "@modern-js/utils/lodash";
9
9
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
10
10
  import analyzePlugin from "./analyze";
@@ -301,6 +301,7 @@ export var appTools = function() {
301
301
  api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
302
302
  toolsType: "app-tools"
303
303
  }));
304
+ var nestedRoutes = {};
304
305
  var locale = getLocaleLanguage();
305
306
  i18n.changeLanguage({
306
307
  locale: locale
@@ -601,6 +602,59 @@ export var appTools = function() {
601
602
  ];
602
603
  });
603
604
  })();
605
+ },
606
+ modifyFileSystemRoutes: function modifyFileSystemRoutes(param) {
607
+ var entrypoint = param.entrypoint, routes = param.routes;
608
+ return _async_to_generator(function() {
609
+ return _ts_generator(this, function(_state) {
610
+ nestedRoutes[entrypoint.entryName] = routes;
611
+ return [
612
+ 2,
613
+ {
614
+ entrypoint: entrypoint,
615
+ routes: routes
616
+ }
617
+ ];
618
+ });
619
+ })();
620
+ },
621
+ beforeGenerateRoutes: function beforeGenerateRoutes(param) {
622
+ var entrypoint = param.entrypoint, code = param.code;
623
+ return _async_to_generator(function() {
624
+ var distDirectory;
625
+ return _ts_generator(this, function(_state) {
626
+ switch (_state.label) {
627
+ case 0:
628
+ distDirectory = api.useAppContext().distDirectory;
629
+ if (!!fs.existsSync(distDirectory))
630
+ return [
631
+ 3,
632
+ 2
633
+ ];
634
+ return [
635
+ 4,
636
+ fs.mkdir(distDirectory)
637
+ ];
638
+ case 1:
639
+ _state.sent();
640
+ _state.label = 2;
641
+ case 2:
642
+ return [
643
+ 4,
644
+ fs.writeJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes)
645
+ ];
646
+ case 3:
647
+ _state.sent();
648
+ return [
649
+ 2,
650
+ {
651
+ entrypoint: entrypoint,
652
+ code: code
653
+ }
654
+ ];
655
+ }
656
+ });
657
+ })();
604
658
  }
605
659
  };
606
660
  }
@@ -28,8 +28,12 @@ export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
28
28
  export const NESTED_ROUTE = {
29
29
  LAYOUT_FILE: "layout",
30
30
  LAYOUT_LOADER_FILE: "layout.loader",
31
+ LAYOUT_DATA_FILE: "layout.data",
32
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
31
33
  PAGE_FILE: "page",
32
34
  PAGE_LOADER_FILE: "page.loader",
35
+ PAGE_DATA_FILE: "layout.data",
36
+ PAGE_CLIENT_LOADER: "page.data.client",
33
37
  LOADING_FILE: "loading",
34
38
  ERROR_FILE: "error",
35
39
  LOADER_FILE: "loader",
@@ -43,7 +43,8 @@ export const optimizeRoute = (routeTree) => {
43
43
  ];
44
44
  }
45
45
  const { children } = routeTree;
46
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
46
+ const hasPage = children.some((child) => child.index);
47
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData && !hasPage) {
47
48
  const newRoutes = children.map((child) => {
48
49
  const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
49
50
  const newRoute = {
@@ -119,6 +120,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
119
120
  route.loader = itemPath;
120
121
  }
121
122
  }
123
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
124
+ route.clientData = itemPath;
125
+ }
126
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_DATA_FILE) {
127
+ route.data = itemPath;
128
+ }
122
129
  if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
123
130
  if (!route.config) {
124
131
  route.config = itemPath;
@@ -130,6 +137,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
130
137
  if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
131
138
  pageLoaderFile = itemPath;
132
139
  }
140
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CLIENT_LOADER) {
141
+ route.clientData = itemPath;
142
+ }
143
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_DATA_FILE) {
144
+ route.data = itemPath;
145
+ }
133
146
  if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
134
147
  pageConfigFile = itemPath;
135
148
  }
@@ -132,12 +132,13 @@ export const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, ent
132
132
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
133
133
  `;
134
134
  let rootLayoutCode = ``;
135
- const getDataLoaderPath = (loaderId) => {
135
+ const getDataLoaderPath = (loaderId, clientData) => {
136
136
  if (!ssrMode) {
137
137
  return "";
138
138
  }
139
+ const clientDataStr = clientData ? `&clientData=${clientData}` : "";
139
140
  if (nestedRoutesEntry) {
140
- return `?mapFile=${slash(loadersMapFile)}&loaderId=${loaderId}`;
141
+ return `?mapFile=${slash(loadersMapFile)}&loaderId=${loaderId}${clientDataStr}`;
141
142
  }
142
143
  return "";
143
144
  };
@@ -162,15 +163,17 @@ export const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, ent
162
163
  errors.push(route.error);
163
164
  error = `error_${errors.length - 1}`;
164
165
  }
165
- if (route.loader) {
166
+ if (route.loader || route.data) {
166
167
  loaders.push(route.loader);
167
168
  const loaderId = loaders.length - 1;
168
169
  loader = `loader_${loaderId}`;
169
170
  loadersMap[loader] = {
170
171
  routeId: route.id,
171
- filePath: route.loader,
172
- inline: false
172
+ filePath: route.data || route.loader,
173
+ clientData: Boolean(route.clientData),
174
+ inline: Boolean(route.data)
173
175
  };
176
+ loader = `loader_${loaderId}`;
174
177
  }
175
178
  if (typeof route.config === "string") {
176
179
  configs.push(route.config);
@@ -269,10 +272,10 @@ export const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, ent
269
272
  let importLoadersCode = "";
270
273
  for (const [key, loaderInfo] of Object.entries(loadersMap)) {
271
274
  if (loaderInfo.inline) {
272
- importLoadersCode += `import { loader as ${key} } from "${slash(loaderInfo.filePath)}${getDataLoaderPath(key)}";
275
+ importLoadersCode += `import { loader as ${key} } from "${slash(loaderInfo.filePath)}${getDataLoaderPath(key, loaderInfo.clientData)}";
273
276
  `;
274
277
  } else {
275
- importLoadersCode += `import ${key} from "${slash(loaderInfo.filePath)}${getDataLoaderPath(key)}";
278
+ importLoadersCode += `import ${key} from "${slash(loaderInfo.filePath)}${getDataLoaderPath(key, loaderInfo.clientData)}";
276
279
  `;
277
280
  }
278
281
  }
@@ -143,6 +143,6 @@ function applySSRDataLoader(chain, options) {
143
143
  const { appDirectory } = appContext;
144
144
  const { entriesDir = "./src" } = normalizedConfig.source;
145
145
  const absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
146
- const reg = new RegExp(`${absolutePath}.*\\.loader\\.[t|j]s$`);
146
+ const reg = new RegExp(`${absolutePath}.*\\.(loader|data|data.client)\\.[t|j]sx?$`);
147
147
  chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
148
148
  }
@@ -154,28 +154,30 @@ export class RouterPlugin {
154
154
  const oldHtml = compilation.assets[htmlName];
155
155
  const { enableInlineRouteManifests, disableFilenameHash, staticJsDir, scriptLoading, nonce } = this;
156
156
  const nonceAttr = nonce ? `nonce="${nonce}"` : "";
157
- if (enableInlineRouteManifests) {
158
- compilation.updateAsset(
159
- htmlName,
160
- new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
161
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
162
- void 0
163
- );
164
- } else {
165
- const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
166
- const scriptUrl = `${publicPath}${scriptPath}`;
167
- const scriptLoadingAttr = (
168
- // eslint-disable-next-line no-nested-ternary
169
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
170
- );
171
- const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
172
- compilation.updateAsset(
173
- htmlName,
174
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
175
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
176
- void 0
177
- );
178
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
157
+ if (oldHtml) {
158
+ if (enableInlineRouteManifests) {
159
+ compilation.updateAsset(
160
+ htmlName,
161
+ new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
162
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
163
+ void 0
164
+ );
165
+ } else {
166
+ const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
167
+ const scriptUrl = `${publicPath}${scriptPath}`;
168
+ const scriptLoadingAttr = (
169
+ // eslint-disable-next-line no-nested-ternary
170
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
171
+ );
172
+ const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
173
+ compilation.updateAsset(
174
+ htmlName,
175
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
176
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
177
+ void 0
178
+ );
179
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
180
+ }
179
181
  }
180
182
  }
181
183
  if (prevManifestAsset) {