@modern-js/app-tools 2.6.0 → 2.7.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/analyze/generateCode.js +7 -7
  4. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +1 -1
  5. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  6. package/dist/cjs/analyze/index.js +20 -2
  7. package/dist/cjs/analyze/nestedRoutes.js +1 -1
  8. package/dist/cjs/analyze/templates.js +6 -4
  9. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  10. package/dist/cjs/builder/generator/index.js +10 -2
  11. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +101 -0
  12. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +91 -0
  13. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +140 -0
  14. package/dist/cjs/builder/shared/builderPlugins/index.js +19 -0
  15. package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  16. package/dist/cjs/builder/shared/bundlerPlugins/index.js +19 -0
  17. package/dist/cjs/builder/shared/index.js +1 -1
  18. package/dist/cjs/commands/dev.js +6 -0
  19. package/dist/cjs/commands/serve.js +17 -0
  20. package/dist/cjs/index.js +1 -1
  21. package/dist/cjs/locale/en.js +1 -0
  22. package/dist/cjs/locale/zh.js +1 -0
  23. package/dist/cjs/schema/index.js +4 -0
  24. package/dist/esm/analyze/generateCode.js +8 -9
  25. package/dist/esm/analyze/getClientRoutes/getRoutes.js +1 -1
  26. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  27. package/dist/esm/analyze/index.js +15 -3
  28. package/dist/esm/analyze/nestedRoutes.js +1 -1
  29. package/dist/esm/analyze/templates.js +6 -5
  30. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +0 -11
  31. package/dist/esm/builder/generator/index.js +6 -4
  32. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +101 -0
  33. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +120 -0
  34. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +131 -0
  35. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  36. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +350 -0
  37. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  38. package/dist/esm/builder/shared/index.js +1 -1
  39. package/dist/esm/commands/dev.js +6 -0
  40. package/dist/esm/commands/serve.js +6 -1
  41. package/dist/esm/index.js +1 -1
  42. package/dist/esm/locale/en.js +1 -0
  43. package/dist/esm/locale/zh.js +1 -0
  44. package/dist/esm/schema/index.js +7 -0
  45. package/dist/esm-node/analyze/generateCode.js +14 -9
  46. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +1 -1
  47. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  48. package/dist/esm-node/analyze/index.js +22 -3
  49. package/dist/esm-node/analyze/nestedRoutes.js +1 -1
  50. package/dist/esm-node/analyze/templates.js +6 -4
  51. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  52. package/dist/esm-node/builder/generator/index.js +10 -2
  53. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +67 -0
  54. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +67 -0
  55. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +119 -0
  56. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  57. package/dist/esm-node/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  58. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  59. package/dist/esm-node/builder/shared/index.js +1 -1
  60. package/dist/esm-node/commands/dev.js +6 -0
  61. package/dist/esm-node/commands/serve.js +18 -1
  62. package/dist/esm-node/index.js +1 -1
  63. package/dist/esm-node/locale/en.js +1 -0
  64. package/dist/esm-node/locale/zh.js +1 -0
  65. package/dist/esm-node/schema/index.js +4 -0
  66. package/dist/js/modern/analyze/constants.js +54 -0
  67. package/dist/js/modern/analyze/generateCode.js +247 -0
  68. package/dist/js/modern/analyze/getBundleEntry.js +71 -0
  69. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
  70. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
  71. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
  72. package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
  73. package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
  74. package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
  75. package/dist/js/modern/analyze/getServerRoutes.js +175 -0
  76. package/dist/js/modern/analyze/index.js +332 -0
  77. package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
  78. package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
  79. package/dist/js/modern/analyze/nestedRoutes.js +157 -0
  80. package/dist/js/modern/analyze/templates.js +334 -0
  81. package/dist/js/modern/analyze/utils.js +141 -0
  82. package/dist/{esm-node/builder/shared/builderPlugins/adapterModern.js → js/modern/builder/builderPlugins/compatModern.js} +135 -104
  83. package/dist/js/modern/builder/index.js +159 -0
  84. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  85. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  86. package/dist/js/modern/builder/share.js +46 -0
  87. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
  88. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
  89. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
  90. package/dist/js/modern/commands/build.js +91 -0
  91. package/dist/js/modern/commands/deploy.js +28 -0
  92. package/dist/js/modern/commands/dev.js +109 -0
  93. package/dist/js/modern/commands/index.js +3 -0
  94. package/dist/js/modern/commands/inspect.js +38 -0
  95. package/dist/js/modern/commands/serve.js +54 -0
  96. package/dist/js/modern/config/default.js +175 -0
  97. package/dist/js/modern/config/index.js +8 -0
  98. package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
  99. package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
  100. package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
  101. package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
  102. package/dist/js/modern/config/initial/index.js +16 -0
  103. package/dist/js/modern/config/initial/inits.js +152 -0
  104. package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
  105. package/dist/js/modern/defineConfig.js +27 -0
  106. package/dist/js/modern/exports/server.js +4 -0
  107. package/dist/js/modern/hooks.js +35 -0
  108. package/dist/js/modern/index.js +211 -0
  109. package/dist/js/modern/initialize/index.js +124 -0
  110. package/dist/js/modern/locale/en.js +36 -0
  111. package/dist/js/modern/locale/index.js +9 -0
  112. package/dist/js/modern/locale/zh.js +36 -0
  113. package/dist/js/modern/schema/Schema.js +40 -0
  114. package/dist/js/modern/schema/index.js +88 -0
  115. package/dist/js/modern/schema/legacy.js +148 -0
  116. package/dist/js/modern/types/config/deploy.js +0 -0
  117. package/dist/js/modern/types/config/dev.js +0 -0
  118. package/dist/js/modern/types/config/experiments.js +0 -0
  119. package/dist/js/modern/types/config/html.js +0 -0
  120. package/dist/js/modern/types/config/index.js +1 -0
  121. package/dist/js/modern/types/config/output.js +0 -0
  122. package/dist/js/modern/types/config/performance.js +0 -0
  123. package/dist/js/modern/types/config/security.js +0 -0
  124. package/dist/js/modern/types/config/source.js +0 -0
  125. package/dist/js/modern/types/config/tools.js +0 -0
  126. package/dist/js/modern/types/hooks.js +0 -0
  127. package/dist/js/modern/types/index.js +3 -0
  128. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  129. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  130. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  131. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  132. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  133. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  134. package/dist/js/modern/utils/config.js +128 -0
  135. package/dist/js/modern/utils/createServer.js +75 -0
  136. package/dist/js/modern/utils/env.js +15 -0
  137. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  138. package/dist/js/modern/utils/getSelectedEntries.js +58 -0
  139. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  140. package/dist/js/modern/utils/language.js +8 -0
  141. package/dist/js/modern/utils/printInstructions.js +31 -0
  142. package/dist/js/modern/utils/restart.js +44 -0
  143. package/dist/js/modern/utils/routes.js +30 -0
  144. package/dist/js/modern/utils/types.js +0 -0
  145. package/dist/js/node/analyze/constants.js +98 -0
  146. package/dist/js/node/analyze/generateCode.js +271 -0
  147. package/dist/js/node/analyze/getBundleEntry.js +95 -0
  148. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
  149. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
  150. package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
  151. package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
  152. package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
  153. package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
  154. package/dist/js/node/analyze/getServerRoutes.js +194 -0
  155. package/dist/js/node/analyze/index.js +339 -0
  156. package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
  157. package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
  158. package/dist/js/node/analyze/nestedRoutes.js +184 -0
  159. package/dist/js/node/analyze/templates.js +365 -0
  160. package/dist/js/node/analyze/utils.js +172 -0
  161. package/dist/{cjs/builder/shared/builderPlugins/adapterModern.js → js/node/builder/builderPlugins/compatModern.js} +137 -113
  162. package/dist/js/node/builder/index.js +177 -0
  163. package/dist/js/node/builder/loaders/routerLoader.js +38 -0
  164. package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
  165. package/dist/js/node/builder/share.js +75 -0
  166. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
  167. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
  168. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
  169. package/dist/js/node/commands/build.js +112 -0
  170. package/dist/js/node/commands/deploy.js +51 -0
  171. package/dist/js/node/commands/dev.js +126 -0
  172. package/dist/js/node/commands/index.js +19 -0
  173. package/dist/js/node/commands/inspect.js +61 -0
  174. package/dist/js/node/commands/serve.js +83 -0
  175. package/dist/js/node/config/default.js +197 -0
  176. package/dist/js/node/config/index.js +34 -0
  177. package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
  178. package/dist/js/node/config/initial/createOutputConfig.js +91 -0
  179. package/dist/js/node/config/initial/createSourceConfig.js +62 -0
  180. package/dist/js/node/config/initial/createToolsConfig.js +65 -0
  181. package/dist/js/node/config/initial/index.js +41 -0
  182. package/dist/js/node/config/initial/inits.js +175 -0
  183. package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
  184. package/dist/js/node/defineConfig.js +49 -0
  185. package/dist/js/node/exports/server.js +27 -0
  186. package/dist/js/node/hooks.js +54 -0
  187. package/dist/js/node/index.js +235 -0
  188. package/dist/js/node/initialize/index.js +134 -0
  189. package/dist/js/node/locale/en.js +59 -0
  190. package/dist/js/node/locale/index.js +33 -0
  191. package/dist/js/node/locale/zh.js +59 -0
  192. package/dist/js/node/schema/Schema.js +63 -0
  193. package/dist/js/node/schema/index.js +118 -0
  194. package/dist/js/node/schema/legacy.js +169 -0
  195. package/dist/js/node/types/config/deploy.js +15 -0
  196. package/dist/js/node/types/config/dev.js +15 -0
  197. package/dist/js/node/types/config/experiments.js +15 -0
  198. package/dist/js/node/types/config/html.js +15 -0
  199. package/dist/{cjs/builder/builder-webpack/webpackPlugins → js/node/types/config}/index.js +3 -3
  200. package/dist/js/node/types/config/output.js +15 -0
  201. package/dist/js/node/types/config/performance.js +15 -0
  202. package/dist/js/node/types/config/security.js +15 -0
  203. package/dist/js/node/types/config/source.js +15 -0
  204. package/dist/js/node/types/config/tools.js +15 -0
  205. package/dist/js/node/types/hooks.js +15 -0
  206. package/dist/js/node/types/index.js +19 -0
  207. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  208. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  209. package/dist/js/node/types/legacyConfig/index.js +15 -0
  210. package/dist/js/node/types/legacyConfig/output.js +15 -0
  211. package/dist/js/node/types/legacyConfig/source.js +15 -0
  212. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  213. package/dist/js/node/utils/config.js +153 -0
  214. package/dist/js/node/utils/createServer.js +106 -0
  215. package/dist/js/node/utils/env.js +38 -0
  216. package/dist/js/node/utils/generateWatchFiles.js +85 -0
  217. package/dist/js/node/utils/getSelectedEntries.js +81 -0
  218. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  219. package/dist/js/node/utils/language.js +31 -0
  220. package/dist/js/node/utils/printInstructions.js +54 -0
  221. package/dist/js/node/utils/restart.js +67 -0
  222. package/dist/js/node/utils/routes.js +59 -0
  223. package/dist/js/node/utils/types.js +15 -0
  224. package/dist/js/treeshaking/analyze/constants.js +40 -0
  225. package/dist/js/treeshaking/analyze/generateCode.js +485 -0
  226. package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
  227. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
  228. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  229. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
  230. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
  231. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
  232. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
  233. package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
  234. package/dist/js/treeshaking/analyze/index.js +697 -0
  235. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
  236. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
  237. package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
  238. package/dist/js/treeshaking/analyze/templates.js +468 -0
  239. package/dist/js/treeshaking/analyze/utils.js +374 -0
  240. package/dist/{esm/builder/shared/builderPlugins/adapterModern.js → js/treeshaking/builder/builderPlugins/compatModern.js} +142 -138
  241. package/dist/js/treeshaking/builder/index.js +374 -0
  242. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  243. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  244. package/dist/js/treeshaking/builder/share.js +40 -0
  245. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
  246. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
  247. package/dist/{esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js → js/treeshaking/builder/webpackPlugins/routerPlugin.js} +3 -6
  248. package/dist/js/treeshaking/commands/build.js +291 -0
  249. package/dist/js/treeshaking/commands/deploy.js +154 -0
  250. package/dist/js/treeshaking/commands/dev.js +301 -0
  251. package/dist/js/treeshaking/commands/index.js +3 -0
  252. package/dist/js/treeshaking/commands/inspect.js +149 -0
  253. package/dist/js/treeshaking/commands/serve.js +199 -0
  254. package/dist/js/treeshaking/config/default.js +210 -0
  255. package/dist/js/treeshaking/config/index.js +3 -0
  256. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
  257. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
  258. package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
  259. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
  260. package/dist/js/treeshaking/config/initial/index.js +12 -0
  261. package/dist/js/treeshaking/config/initial/inits.js +209 -0
  262. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
  263. package/dist/js/treeshaking/defineConfig.js +61 -0
  264. package/dist/js/treeshaking/exports/server.js +2 -0
  265. package/dist/js/treeshaking/hooks.js +29 -0
  266. package/dist/js/treeshaking/index.js +706 -0
  267. package/dist/js/treeshaking/initialize/index.js +276 -0
  268. package/dist/js/treeshaking/locale/en.js +38 -0
  269. package/dist/js/treeshaking/locale/index.js +9 -0
  270. package/dist/js/treeshaking/locale/zh.js +38 -0
  271. package/dist/js/treeshaking/schema/Schema.js +273 -0
  272. package/dist/js/treeshaking/schema/index.js +181 -0
  273. package/dist/js/treeshaking/schema/legacy.js +337 -0
  274. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  275. package/dist/js/treeshaking/types/config/dev.js +1 -0
  276. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  277. package/dist/js/treeshaking/types/config/html.js +1 -0
  278. package/dist/js/treeshaking/types/config/index.js +1 -0
  279. package/dist/js/treeshaking/types/config/output.js +1 -0
  280. package/dist/js/treeshaking/types/config/performance.js +1 -0
  281. package/dist/js/treeshaking/types/config/security.js +1 -0
  282. package/dist/js/treeshaking/types/config/source.js +1 -0
  283. package/dist/js/treeshaking/types/config/tools.js +1 -0
  284. package/dist/js/treeshaking/types/hooks.js +1 -0
  285. package/dist/js/treeshaking/types/index.js +3 -0
  286. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  287. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  288. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  289. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  290. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  291. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  292. package/dist/js/treeshaking/utils/config.js +302 -0
  293. package/dist/js/treeshaking/utils/createServer.js +258 -0
  294. package/dist/js/treeshaking/utils/env.js +13 -0
  295. package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
  296. package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
  297. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  298. package/dist/js/treeshaking/utils/language.js +6 -0
  299. package/dist/js/treeshaking/utils/printInstructions.js +152 -0
  300. package/dist/js/treeshaking/utils/restart.js +187 -0
  301. package/dist/js/treeshaking/utils/routes.js +153 -0
  302. package/dist/js/treeshaking/utils/types.js +1 -0
  303. package/dist/types/analyze/templates.d.ts +5 -3
  304. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +7 -0
  305. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +5 -0
  306. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +4 -0
  307. package/dist/types/builder/shared/builderPlugins/index.d.ts +3 -0
  308. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +5 -0
  309. package/dist/types/builder/shared/bundlerPlugins/index.d.ts +3 -0
  310. package/dist/types/builder/shared/index.d.ts +1 -1
  311. package/dist/types/builder/shared/types.d.ts +7 -4
  312. package/dist/types/locale/en.d.ts +1 -0
  313. package/dist/types/locale/index.d.ts +2 -0
  314. package/dist/types/locale/zh.d.ts +1 -0
  315. package/dist/types/types/config/output.d.ts +3 -15
  316. package/lib/types.d.ts +1 -1
  317. package/package.json +28 -28
  318. package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +0 -1
  319. package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +0 -1
  320. package/dist/types/builder/builder-webpack/webpackPlugins/RouterPlugin.d.ts +0 -4
  321. package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +0 -1
  322. package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +0 -13
@@ -65,7 +65,7 @@ class RouterPlugin {
65
65
  chunkGroups: true,
66
66
  chunks: true
67
67
  });
68
- const { publicPath } = stats;
68
+ const { publicPath, chunks = [] } = stats;
69
69
  const routeAssets = {};
70
70
  const { namedChunkGroups, assetsByChunkName } = stats;
71
71
  if (!namedChunkGroups || !assetsByChunkName) {
@@ -98,17 +98,23 @@ class RouterPlugin {
98
98
  const entryChunkIds = entrypointsArray.map(
99
99
  (entrypoint) => entrypoint[0]
100
100
  );
101
- const entryChunks = [...compilation.chunks].filter((chunk) => {
102
- return entryChunkIds.includes(chunk.name);
101
+ const entryChunks = [...chunks].filter((chunk) => {
102
+ var _a;
103
+ return (_a = chunk.names) == null ? void 0 : _a.some((name) => entryChunkIds.includes(name));
103
104
  });
104
105
  const entryChunkFiles = entryChunks.map(
105
- (chunk) => [...chunk.files].find((fname) => fname.includes(".js"))
106
+ (chunk) => [...chunk.files || []].find((fname) => fname.includes(".js"))
106
107
  );
107
108
  for (const file of entryChunkFiles) {
108
109
  const asset = compilation.assets[file];
109
110
  const newContent = `${injectedContent}${asset.source().toString()}`;
110
111
  newAssetsMap.set(import_path.default.join(outputPath, file), newContent);
111
- compilation.updateAsset(file, new RawSource(newContent));
112
+ compilation.updateAsset(
113
+ file,
114
+ new RawSource(newContent),
115
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
116
+ void 0
117
+ );
112
118
  }
113
119
  const filename = import_path.default.join(outputPath, import_utils.ROUTE_MINIFEST_FILE);
114
120
  await import_utils.fs.ensureFile(filename);
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var bundlerPlugins_exports = {};
16
+ module.exports = __toCommonJS(bundlerPlugins_exports);
17
+ __reExport(bundlerPlugins_exports, require("./HtmlAsyncChunkPlugin"), module.exports);
18
+ __reExport(bundlerPlugins_exports, require("./HtmlBottomTemplate"), module.exports);
19
+ __reExport(bundlerPlugins_exports, require("./RouterPlugin"), module.exports);
@@ -16,4 +16,4 @@ var shared_exports = {};
16
16
  module.exports = __toCommonJS(shared_exports);
17
17
  __reExport(shared_exports, require("./createCopyPattern"), module.exports);
18
18
  __reExport(shared_exports, require("./types"), module.exports);
19
- __reExport(shared_exports, require("./builderPlugins/adapterModern"), module.exports);
19
+ __reExport(shared_exports, require("./builderPlugins"), module.exports);
@@ -63,6 +63,12 @@ const dev = async (api, options) => {
63
63
  host: normalizedConfig.dev.host,
64
64
  ...(_a = normalizedConfig.tools) == null ? void 0 : _a.devServer
65
65
  },
66
+ appContext: {
67
+ appDirectory: appContext.appDirectory,
68
+ sharedDirectory: appContext.sharedDirectory,
69
+ apiDirectory: appContext.apiDirectory,
70
+ lambdaDirectory: appContext.lambdaDirectory
71
+ },
66
72
  pwd: appDirectory,
67
73
  config: normalizedConfig,
68
74
  serverConfigFile,
@@ -50,6 +50,23 @@ const start = async (api) => {
50
50
  const app = await (0, import_prod_server.default)({
51
51
  pwd: appDirectory,
52
52
  config: userConfig,
53
+ appContext: {
54
+ sharedDirectory: (0, import_utils.getTargetDir)(
55
+ appContext.sharedDirectory,
56
+ appContext.appDirectory,
57
+ appContext.distDirectory
58
+ ),
59
+ apiDirectory: (0, import_utils.getTargetDir)(
60
+ appContext.apiDirectory,
61
+ appContext.appDirectory,
62
+ appContext.distDirectory
63
+ ),
64
+ lambdaDirectory: (0, import_utils.getTargetDir)(
65
+ appContext.lambdaDirectory,
66
+ appContext.appDirectory,
67
+ appContext.distDirectory
68
+ )
69
+ },
53
70
  serverConfigFile,
54
71
  internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
55
72
  apiOnly
package/dist/cjs/index.js CHANGED
@@ -53,7 +53,7 @@ const upgradeModel = import_utils.Import.lazy(
53
53
  const devCommand = async (program, api) => {
54
54
  const runner = api.useHookRunners();
55
55
  const devToolMetas = await runner.registerDev();
56
- const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).action(async (options) => {
56
+ const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
57
57
  const { dev } = await Promise.resolve().then(() => __toESM(require("./commands/dev")));
58
58
  await dev(api, options);
59
59
  });
@@ -30,6 +30,7 @@ const EN_LOCALE = {
30
30
  describe: "start dev server",
31
31
  entry: "compiler by entry",
32
32
  apiOnly: "start api server only",
33
+ webOnly: "start web server only",
33
34
  selectEntry: "Please select the entry that needs to be built",
34
35
  requireEntry: "You must choose at least one entry"
35
36
  },
@@ -30,6 +30,7 @@ const ZH_LOCALE = {
30
30
  describe: "本地开发命令",
31
31
  entry: "指定入口,编译特定的页面",
32
32
  apiOnly: "仅启动 API 接口服务",
33
+ webOnly: "仅启动 Web 服务",
33
34
  selectEntry: "请选择需要构建的入口",
34
35
  requireEntry: "请至少选择一个入口"
35
36
  },
@@ -64,6 +64,10 @@ const bff = {
64
64
  prefix: {
65
65
  type: "string"
66
66
  },
67
+ httpMethodDecider: {
68
+ type: "string",
69
+ enum: ["functionName", "inputParams"]
70
+ },
67
71
  proxy: {
68
72
  type: "object",
69
73
  additionalProperties: {
@@ -148,8 +148,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
148
148
  }
149
149
  };
150
150
  import path from "path";
151
- import { fs, getEntryOptions, isRouterV5, logger } from "@modern-js/utils";
152
- import { useResolvedConfigContext } from "@modern-js/core";
151
+ import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
153
152
  import * as templates from "./templates";
154
153
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
155
154
  import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
@@ -246,7 +245,7 @@ var generateCode = function() {
246
245
  }
247
246
  function _generateEntryCode() {
248
247
  _generateEntryCode = _asyncToGenerator(function(entrypoint) {
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;
248
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config2_output, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
250
249
  return __generator(this, function(_state) {
251
250
  switch(_state.label){
252
251
  case 0:
@@ -297,12 +296,11 @@ var generateCode = function() {
297
296
  ];
298
297
  case 3:
299
298
  routes = _state.sent().routes;
300
- config2 = useResolvedConfigContext();
299
+ config2 = api.useResolvedConfigContext();
301
300
  ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
301
+ useSSG = isSSGEntry(config2, entryName, entrypoints);
302
302
  if (ssr) {
303
303
  mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
304
- } else {
305
- mode = false;
306
304
  }
307
305
  if (mode === "stream") {
308
306
  hasPageRoute = routes.some(function(route) {
@@ -321,10 +319,11 @@ var generateCode = function() {
321
319
  4,
322
320
  templates.fileSystemRoutes({
323
321
  routes: routes,
324
- ssrMode: mode,
322
+ ssrMode: useSSG ? "string" : mode,
325
323
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
326
324
  entryName: entrypoint.entryName,
327
- internalDirectory: internalDirectory
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
328
327
  })
329
328
  ];
330
329
  case 4:
@@ -336,7 +335,7 @@ var generateCode = function() {
336
335
  ];
337
336
  case 5:
338
337
  _ref = _state.sent(), code2 = _ref.code;
339
- if (!(entrypoint.nestedRoutesEntry && mode)) return [
338
+ if (!(entrypoint.nestedRoutesEntry && isUseSSRBundle(config2))) return [
340
339
  3,
341
340
  8
342
341
  ];
@@ -111,7 +111,7 @@ var recursiveReadDir = function(param) {
111
111
  }
112
112
  }
113
113
  var route1 = {
114
- path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1]).concat(dynamicRouteMatched[2]) : filename),
114
+ path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1].replace(/\$$/, "?")).concat(dynamicRouteMatched[2]) : filename),
115
115
  _component: alias1,
116
116
  component: componentName1,
117
117
  parent: parent,
@@ -111,7 +111,7 @@ var recursiveReadDirLegacy = function(param) {
111
111
  }
112
112
  }
113
113
  var route1 = {
114
- path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1]).concat(dynamicRouteMatched[2]) : filename),
114
+ path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1].replace(/\$$/, "?")).concat(dynamicRouteMatched[2]) : filename),
115
115
  _component: alias1,
116
116
  component: componentName1,
117
117
  exact: true,
@@ -221,8 +221,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
221
221
  }
222
222
  };
223
223
  import * as path from "path";
224
- import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
224
+ import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist, getCommand, isDevCommand, isSSGEntry } from "@modern-js/utils";
225
225
  import { cloneDeep } from "@modern-js/utils/lodash";
226
+ import { createVirtualModule } from "@modern-js/builder-shared";
226
227
  import { printInstructions } from "../utils/printInstructions";
227
228
  import { generateRoutes } from "../utils/routes";
228
229
  import { emitResolvedConfig } from "../utils/config";
@@ -553,9 +554,12 @@ var analyze_default = function(param) {
553
554
  entrypoints.forEach(function(entrypoint) {
554
555
  var entryName = entrypoint.entryName;
555
556
  var ssr = getEntryOptions(entryName, resolvedConfig.server.ssr, resolvedConfig.server.ssrByEntries, packageName);
556
- if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
557
+ var useSSG = isSSGEntry(resolvedConfig, entryName, entrypoints);
558
+ if (entrypoint.nestedRoutesEntry && (ssr || useSSG) && name === "server") {
559
+ var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
557
560
  var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
558
- chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
561
+ var combinedModule = createVirtualModule('export * from "'.concat(serverLoaderRuntime, '"; export * from "').concat(serverLoadersFile, '"'));
562
+ chain.entry("".concat(entryName, "-server-loaders")).add(combinedModule);
559
563
  }
560
564
  });
561
565
  }
@@ -658,6 +662,14 @@ var analyze_default = function(param) {
658
662
  });
659
663
  })();
660
664
  },
665
+ validateSchema: function validateSchema() {
666
+ return {
667
+ target: "output.splitRoutesChunks",
668
+ schema: {
669
+ type: "boolean"
670
+ }
671
+ };
672
+ },
661
673
  fileChange: function fileChange(e) {
662
674
  return _asyncToGenerator(function() {
663
675
  var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
@@ -236,7 +236,7 @@ var walk = function() {
236
236
  }
237
237
  routePath = replaceDynamicPath(routePath);
238
238
  route = {
239
- path: routePath,
239
+ path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
240
240
  children: [],
241
241
  isRoot: isRoot
242
242
  };
@@ -297,15 +297,16 @@ var routesForServer = function(param) {
297
297
  };
298
298
  var fileSystemRoutes = function() {
299
299
  var _ref = _asyncToGenerator(function(param) {
300
- var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
300
+ var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRoutesChunks, splitRoutesChunks, loadings, errors, loaders, loadersMap, webpackMode, 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;
301
301
  return __generator(this, function(_state) {
302
302
  switch(_state.label){
303
303
  case 0:
304
- routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
304
+ 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;
305
305
  loadings = [];
306
306
  errors = [];
307
307
  loaders = [];
308
308
  loadersMap = {};
309
+ webpackMode = splitRoutesChunks ? "lazy" : "eager";
309
310
  loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
310
311
  importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
311
312
  rootLayoutCode = "";
@@ -354,15 +355,15 @@ var fileSystemRoutes = function() {
354
355
  rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
355
356
  component = "RootLayout";
356
357
  } else if (ssrMode === "string") {
357
- lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
358
+ lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, '" */ /* webpackMode: "').concat(webpackMode, "\" */ '").concat(route._component, "')");
358
359
  component = "loadable(".concat(lazyImport, ")");
359
360
  } else {
360
- lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
361
+ lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, '" */ /* webpackMode: "').concat(webpackMode, "\" */ '").concat(route._component, "')");
361
362
  component = "lazy(".concat(lazyImport, ")");
362
363
  }
363
364
  }
364
365
  } else if (route._component) {
365
- lazyImport = "() => import('".concat(route._component, "')");
366
+ lazyImport = '() => import( /* webpackMode: "'.concat(webpackMode, "\" */ '").concat(route._component, "')");
366
367
  component = "loadable(".concat(lazyImport, ")");
367
368
  }
368
369
  var finalRoute = _objectSpreadProps(_objectSpread({}, route), {
@@ -25,7 +25,6 @@ function _unsupportedIterableToArray(o, minLen) {
25
25
  }
26
26
  import { join } from "path";
27
27
  import { createCopyPattern } from "../../shared";
28
- import { RouterPlugin } from "../webpackPlugins";
29
28
  var builderPluginCompatModern = function(options) {
30
29
  return {
31
30
  name: "builder-plugin-compat-modern",
@@ -33,7 +32,6 @@ var builderPluginCompatModern = function(options) {
33
32
  var modernConfig = options.normalizedConfig, appContext = options.appContext;
34
33
  api.modifyWebpackChain(function(chain, param) {
35
34
  var CHAIN_ID = param.CHAIN_ID;
36
- var _modernConfig_runtime;
37
35
  chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
38
36
  if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
39
37
  var defaultCopyPattern = createCopyPattern(appContext, modernConfig, "public", chain);
@@ -48,15 +46,6 @@ var builderPluginCompatModern = function(options) {
48
46
  ];
49
47
  });
50
48
  }
51
- var entrypoints = appContext.entrypoints;
52
- var existNestedRoutes = entrypoints.some(function(entrypoint) {
53
- return entrypoint.nestedRoutesEntry;
54
- });
55
- var routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_runtime = modernConfig.runtime) === null || _modernConfig_runtime === void 0 ? void 0 : _modernConfig_runtime.router;
56
- var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
57
- if (existNestedRoutes || routerManifest) {
58
- chain.plugin("route-plugin").use(RouterPlugin);
59
- }
60
49
  });
61
50
  }
62
51
  };
@@ -175,18 +175,20 @@ function applyBuilderPlugins(builder, options) {
175
175
  }
176
176
  function _applyBuilderPlugins() {
177
177
  _applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
178
- var builderPluginAdapterModern;
178
+ var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR;
179
179
  return __generator(this, function(_state) {
180
180
  switch(_state.label){
181
181
  case 0:
182
182
  return [
183
183
  4,
184
- import("../shared/builderPlugins/adapterModern")
184
+ import("../shared/builderPlugins")
185
185
  ];
186
186
  case 1:
187
- builderPluginAdapterModern = _state.sent().builderPluginAdapterModern;
187
+ _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR;
188
188
  builder.addPlugins([
189
- builderPluginAdapterModern(options)
189
+ builderPluginAdapterBasic(options),
190
+ builderPluginAdapterSSR(options),
191
+ builderPluginAdapterHtml(options)
190
192
  ]);
191
193
  return [
192
194
  2
@@ -0,0 +1,101 @@
1
+ var builderPluginAdapterBasic = function(options) {
2
+ return {
3
+ name: "builder-plugin-adapter-modern-basic",
4
+ setup: function setup(api) {
5
+ api.modifyBundlerChain(function(chain, param) {
6
+ var target = param.target, CHAIN_ID = param.CHAIN_ID;
7
+ if (target === "node") {
8
+ chain.name("server");
9
+ } else if (target === "service-worker") {
10
+ chain.name("service-worker");
11
+ } else if (target === "web-worker") {
12
+ chain.name("worker");
13
+ } else if (target === "modern-web") {
14
+ chain.name("modern");
15
+ } else {
16
+ chain.name("client");
17
+ }
18
+ if (target === "node" || target === "service-worker") {
19
+ applyNodeCompat(target, chain);
20
+ }
21
+ if (target === "web" || target === "modern-web") {
22
+ var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
23
+ chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
24
+ chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
25
+ }
26
+ });
27
+ applyCallbacks(api, options);
28
+ }
29
+ };
30
+ };
31
+ function applyCallbacks(api, options) {
32
+ options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
33
+ options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
34
+ options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
35
+ options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
36
+ options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
37
+ options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
38
+ options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
39
+ options.onExit && api.onExit(options.onExit);
40
+ }
41
+ function applyNodeCompat(target, chain) {
42
+ var nodeExts = [
43
+ ".node.js",
44
+ ".node.jsx",
45
+ ".node.ts",
46
+ ".node.tsx",
47
+ ".server.js",
48
+ ".server.ts",
49
+ ".server.ts",
50
+ ".server.tsx"
51
+ ];
52
+ var webWorkerExts = [
53
+ ".worker.js",
54
+ ".worker.jsx",
55
+ ".worker.ts",
56
+ ".worker.tsx"
57
+ ];
58
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
59
+ try {
60
+ for(var _iterator = nodeExts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
61
+ var ext = _step.value;
62
+ chain.resolve.extensions.prepend(ext);
63
+ }
64
+ } catch (err) {
65
+ _didIteratorError = true;
66
+ _iteratorError = err;
67
+ } finally{
68
+ try {
69
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
70
+ _iterator.return();
71
+ }
72
+ } finally{
73
+ if (_didIteratorError) {
74
+ throw _iteratorError;
75
+ }
76
+ }
77
+ }
78
+ if (target === "service-worker") {
79
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
80
+ try {
81
+ for(var _iterator1 = webWorkerExts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
82
+ var ext1 = _step1.value;
83
+ chain.resolve.extensions.prepend(ext1);
84
+ }
85
+ } catch (err) {
86
+ _didIteratorError1 = true;
87
+ _iteratorError1 = err;
88
+ } finally{
89
+ try {
90
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
91
+ _iterator1.return();
92
+ }
93
+ } finally{
94
+ if (_didIteratorError1) {
95
+ throw _iteratorError1;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+ export { applyCallbacks, builderPluginAdapterBasic };
@@ -0,0 +1,120 @@
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _objectSpread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _defineProperty(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ function ownKeys(object, enumerableOnly) {
30
+ var keys = Object.keys(object);
31
+ if (Object.getOwnPropertySymbols) {
32
+ var symbols = Object.getOwnPropertySymbols(object);
33
+ if (enumerableOnly) {
34
+ symbols = symbols.filter(function(sym) {
35
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
+ });
37
+ }
38
+ keys.push.apply(keys, symbols);
39
+ }
40
+ return keys;
41
+ }
42
+ function _objectSpreadProps(target, source) {
43
+ source = source != null ? source : {};
44
+ if (Object.getOwnPropertyDescriptors) {
45
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
+ } else {
47
+ ownKeys(Object(source)).forEach(function(key) {
48
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
+ });
50
+ }
51
+ return target;
52
+ }
53
+ import { getEntryOptions } from "@modern-js/utils";
54
+ import { template as lodashTemplate } from "@modern-js/utils/lodash";
55
+ import { BottomTemplatePlugin } from "../bundlerPlugins";
56
+ function isHtmlEnabled(config, target) {
57
+ var _config_tools;
58
+ return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
59
+ }
60
+ var builderPluginAdapterHtml = function(options) {
61
+ return {
62
+ name: "builder-plugin-adpater-modern-html",
63
+ setup: function setup(api) {
64
+ api.modifyBundlerChain(function(chain, param) {
65
+ var CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin;
66
+ var builderConfig = api.getNormalizedConfig();
67
+ if (isHtmlEnabled(builderConfig, target)) {
68
+ applyBottomHtmlPlugin({
69
+ api: api,
70
+ options: options,
71
+ chain: chain,
72
+ CHAIN_ID: CHAIN_ID,
73
+ HtmlBundlerPlugin: HtmlBundlerPlugin
74
+ });
75
+ }
76
+ });
77
+ }
78
+ };
79
+ };
80
+ function applyBottomHtmlPlugin(param) {
81
+ var api = param.api, chain = param.chain, options = param.options, CHAIN_ID = param.CHAIN_ID, HtmlBundlerPlugin = param.HtmlBundlerPlugin;
82
+ var modernConfig = options.normalizedConfig, appContext = options.appContext;
83
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
84
+ try {
85
+ var _loop = function() {
86
+ var entryName = _step.value;
87
+ var baseTemplateParams = _objectSpread({
88
+ entryName: entryName,
89
+ title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
90
+ mountId: modernConfig.html.mountId
91
+ }, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
92
+ chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
93
+ return [
94
+ _objectSpreadProps(_objectSpread({}, args[0] || {}), {
95
+ __internal__: true,
96
+ bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
97
+ })
98
+ ];
99
+ });
100
+ };
101
+ for(var _iterator = Object.keys(api.context.entry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
102
+ } catch (err) {
103
+ _didIteratorError = true;
104
+ _iteratorError = err;
105
+ } finally{
106
+ try {
107
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
108
+ _iterator.return();
109
+ }
110
+ } finally{
111
+ if (_didIteratorError) {
112
+ throw _iteratorError;
113
+ }
114
+ }
115
+ }
116
+ chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [
117
+ HtmlBundlerPlugin
118
+ ]);
119
+ }
120
+ export { builderPluginAdapterHtml, isHtmlEnabled };