@modern-js/app-tools 2.15.0 → 2.17.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 (268) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/cjs/analyze/constants.js +37 -61
  3. package/dist/cjs/analyze/generateCode.js +102 -127
  4. package/dist/cjs/analyze/getBundleEntry.js +33 -66
  5. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +61 -117
  6. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +61 -115
  7. package/dist/cjs/analyze/getClientRoutes/index.js +15 -28
  8. package/dist/cjs/analyze/getClientRoutes/utils.js +24 -48
  9. package/dist/cjs/analyze/getFileSystemEntry.js +39 -79
  10. package/dist/cjs/analyze/getHtmlTemplate.js +88 -98
  11. package/dist/cjs/analyze/getServerRoutes.js +67 -110
  12. package/dist/cjs/analyze/index.js +265 -257
  13. package/dist/cjs/analyze/isDefaultExportFunction.js +66 -44
  14. package/dist/cjs/analyze/makeLegalIdentifier.js +7 -25
  15. package/dist/cjs/analyze/nestedRoutes.js +99 -104
  16. package/dist/cjs/analyze/templates.js +49 -110
  17. package/dist/cjs/analyze/utils.js +98 -102
  18. package/dist/cjs/builder/builder-rspack/adapterCopy.js +58 -100
  19. package/dist/cjs/builder/builder-rspack/index.js +14 -30
  20. package/dist/cjs/builder/builder-webpack/adapterModern.js +33 -50
  21. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +16 -32
  22. package/dist/cjs/builder/builder-webpack/index.js +65 -46
  23. package/dist/cjs/builder/generator/createBuilderOptions.js +10 -26
  24. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +11 -27
  25. package/dist/cjs/builder/generator/getBuilderTargets.js +13 -29
  26. package/dist/cjs/builder/generator/index.js +61 -55
  27. package/dist/cjs/builder/index.js +53 -43
  28. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +13 -36
  29. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +90 -90
  30. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +108 -111
  31. package/dist/cjs/builder/shared/builderPlugins/index.js +20 -19
  32. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -30
  33. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +32 -38
  34. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +86 -116
  35. package/dist/cjs/builder/shared/bundlerPlugins/index.js +20 -19
  36. package/dist/cjs/builder/shared/createCopyInfo.js +16 -42
  37. package/dist/cjs/builder/shared/index.js +20 -19
  38. package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +8 -24
  39. package/dist/cjs/builder/shared/types.js +4 -15
  40. package/dist/cjs/commands/build.js +23 -40
  41. package/dist/cjs/commands/deploy.js +7 -25
  42. package/dist/cjs/commands/dev.js +38 -57
  43. package/dist/cjs/commands/index.js +20 -19
  44. package/dist/cjs/commands/inspect.js +10 -30
  45. package/dist/cjs/commands/serve.js +28 -66
  46. package/dist/cjs/config/default.js +34 -34
  47. package/dist/cjs/config/index.js +20 -19
  48. package/dist/cjs/config/initialize/index.js +11 -29
  49. package/dist/cjs/config/initialize/inits.js +103 -82
  50. package/dist/cjs/config/legacy/createHtmlConfig.js +8 -40
  51. package/dist/cjs/config/legacy/createOutputConfig.js +8 -51
  52. package/dist/cjs/config/legacy/createSourceConfig.js +8 -38
  53. package/dist/cjs/config/legacy/createToolsConfig.js +8 -43
  54. package/dist/cjs/config/legacy/index.js +22 -46
  55. package/dist/cjs/defineConfig.js +16 -31
  56. package/dist/cjs/exports/server.js +7 -25
  57. package/dist/cjs/hooks.js +33 -51
  58. package/dist/cjs/index.js +185 -166
  59. package/dist/cjs/initialize/index.js +84 -100
  60. package/dist/cjs/locale/en.js +13 -27
  61. package/dist/cjs/locale/index.js +18 -28
  62. package/dist/cjs/locale/zh.js +13 -27
  63. package/dist/cjs/schema/Schema.js +27 -31
  64. package/dist/cjs/schema/index.js +141 -71
  65. package/dist/cjs/schema/legacy.js +273 -96
  66. package/dist/cjs/types/config/deploy.js +4 -15
  67. package/dist/cjs/types/config/dev.js +4 -15
  68. package/dist/cjs/types/config/experiments.js +4 -15
  69. package/dist/cjs/types/config/html.js +4 -15
  70. package/dist/cjs/types/config/index.js +18 -17
  71. package/dist/cjs/types/config/output.js +4 -15
  72. package/dist/cjs/types/config/performance.js +4 -15
  73. package/dist/cjs/types/config/security.js +4 -15
  74. package/dist/cjs/types/config/source.js +4 -15
  75. package/dist/cjs/types/config/tools.js +4 -15
  76. package/dist/cjs/types/hooks.js +4 -15
  77. package/dist/cjs/types/index.js +20 -19
  78. package/dist/cjs/types/legacyConfig/deploy.js +4 -15
  79. package/dist/cjs/types/legacyConfig/dev.js +4 -15
  80. package/dist/cjs/types/legacyConfig/index.js +4 -15
  81. package/dist/cjs/types/legacyConfig/output.js +4 -15
  82. package/dist/cjs/types/legacyConfig/source.js +4 -15
  83. package/dist/cjs/types/legacyConfig/tools.js +4 -15
  84. package/dist/cjs/types/utils.js +4 -15
  85. package/dist/cjs/utils/config.js +74 -79
  86. package/dist/cjs/utils/createServer.js +16 -42
  87. package/dist/cjs/utils/env.js +7 -25
  88. package/dist/cjs/utils/generateWatchFiles.js +31 -52
  89. package/dist/cjs/utils/getSelectedEntries.js +13 -35
  90. package/dist/cjs/utils/getServerInternalPlugins.js +8 -29
  91. package/dist/cjs/utils/printInstructions.js +10 -28
  92. package/dist/cjs/utils/restart.js +13 -31
  93. package/dist/cjs/utils/routes.js +18 -39
  94. package/dist/cjs/utils/types.js +4 -15
  95. package/dist/esm/analyze/constants.js +40 -41
  96. package/dist/esm/analyze/generateCode.js +477 -455
  97. package/dist/esm/analyze/getBundleEntry.js +53 -54
  98. package/dist/esm/analyze/getClientRoutes/getRoutes.js +201 -202
  99. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +199 -200
  100. package/dist/esm/analyze/getClientRoutes/index.js +2 -3
  101. package/dist/esm/analyze/getClientRoutes/utils.js +15 -15
  102. package/dist/esm/analyze/getFileSystemEntry.js +86 -87
  103. package/dist/esm/analyze/getHtmlTemplate.js +289 -278
  104. package/dist/esm/analyze/getServerRoutes.js +203 -190
  105. package/dist/esm/analyze/index.js +679 -651
  106. package/dist/esm/analyze/isDefaultExportFunction.js +38 -39
  107. package/dist/esm/analyze/makeLegalIdentifier.js +8 -9
  108. package/dist/esm/analyze/nestedRoutes.js +400 -392
  109. package/dist/esm/analyze/templates.js +536 -509
  110. package/dist/esm/analyze/utils.js +357 -336
  111. package/dist/esm/builder/builder-rspack/adapterCopy.js +347 -330
  112. package/dist/esm/builder/builder-rspack/index.js +8 -9
  113. package/dist/esm/builder/builder-webpack/adapterModern.js +51 -43
  114. package/dist/esm/builder/builder-webpack/createCopyPattern.js +31 -32
  115. package/dist/esm/builder/builder-webpack/index.js +266 -249
  116. package/dist/esm/builder/generator/createBuilderOptions.js +37 -38
  117. package/dist/esm/builder/generator/createBuilderProviderConfig.js +62 -63
  118. package/dist/esm/builder/generator/getBuilderTargets.js +13 -14
  119. package/dist/esm/builder/generator/index.js +203 -196
  120. package/dist/esm/builder/index.js +183 -176
  121. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +90 -91
  122. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +300 -291
  123. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +337 -329
  124. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +108 -97
  125. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +66 -64
  126. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +364 -337
  127. package/dist/esm/builder/shared/createCopyInfo.js +9 -10
  128. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +2 -3
  129. package/dist/esm/builder/shared/types.js +1 -1
  130. package/dist/esm/commands/build.js +279 -272
  131. package/dist/esm/commands/deploy.js +150 -144
  132. package/dist/esm/commands/dev.js +296 -289
  133. package/dist/esm/commands/inspect.js +144 -138
  134. package/dist/esm/commands/serve.js +241 -235
  135. package/dist/esm/config/default.js +202 -203
  136. package/dist/esm/config/initialize/index.js +7 -8
  137. package/dist/esm/config/initialize/inits.js +189 -181
  138. package/dist/esm/config/legacy/createHtmlConfig.js +17 -18
  139. package/dist/esm/config/legacy/createOutputConfig.js +41 -42
  140. package/dist/esm/config/legacy/createSourceConfig.js +38 -39
  141. package/dist/esm/config/legacy/createToolsConfig.js +24 -25
  142. package/dist/esm/config/legacy/index.js +31 -32
  143. package/dist/esm/defineConfig.js +52 -53
  144. package/dist/esm/exports/server.js +1 -2
  145. package/dist/esm/hooks.js +26 -27
  146. package/dist/esm/index.js +685 -671
  147. package/dist/esm/initialize/index.js +276 -269
  148. package/dist/esm/locale/en.js +36 -37
  149. package/dist/esm/locale/index.js +2 -2
  150. package/dist/esm/locale/zh.js +36 -37
  151. package/dist/esm/schema/Schema.js +255 -244
  152. package/dist/esm/schema/index.js +165 -165
  153. package/dist/esm/schema/legacy.js +316 -317
  154. package/dist/esm/types/config/deploy.js +1 -1
  155. package/dist/esm/types/config/dev.js +1 -1
  156. package/dist/esm/types/config/experiments.js +1 -1
  157. package/dist/esm/types/config/html.js +1 -1
  158. package/dist/esm/types/config/output.js +1 -1
  159. package/dist/esm/types/config/performance.js +1 -1
  160. package/dist/esm/types/config/security.js +1 -1
  161. package/dist/esm/types/config/source.js +1 -1
  162. package/dist/esm/types/config/tools.js +1 -1
  163. package/dist/esm/types/hooks.js +1 -1
  164. package/dist/esm/types/legacyConfig/deploy.js +1 -1
  165. package/dist/esm/types/legacyConfig/dev.js +1 -1
  166. package/dist/esm/types/legacyConfig/index.js +1 -1
  167. package/dist/esm/types/legacyConfig/output.js +1 -1
  168. package/dist/esm/types/legacyConfig/source.js +1 -1
  169. package/dist/esm/types/legacyConfig/tools.js +1 -1
  170. package/dist/esm/types/utils.js +1 -1
  171. package/dist/esm/utils/config.js +285 -278
  172. package/dist/esm/utils/createServer.js +242 -234
  173. package/dist/esm/utils/env.js +11 -12
  174. package/dist/esm/utils/generateWatchFiles.js +205 -190
  175. package/dist/esm/utils/getSelectedEntries.js +180 -173
  176. package/dist/esm/utils/getServerInternalPlugins.js +197 -191
  177. package/dist/esm/utils/printInstructions.js +147 -141
  178. package/dist/esm/utils/restart.js +179 -173
  179. package/dist/esm/utils/routes.js +146 -139
  180. package/dist/esm/utils/types.js +1 -1
  181. package/dist/esm-node/analyze/constants.js +31 -46
  182. package/dist/esm-node/analyze/generateCode.js +28 -94
  183. package/dist/esm-node/analyze/getBundleEntry.js +8 -27
  184. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +24 -65
  185. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +24 -63
  186. package/dist/esm-node/analyze/getClientRoutes/index.js +2 -6
  187. package/dist/esm-node/analyze/getClientRoutes/utils.js +5 -19
  188. package/dist/esm-node/analyze/getFileSystemEntry.js +10 -37
  189. package/dist/esm-node/analyze/getHtmlTemplate.js +29 -59
  190. package/dist/esm-node/analyze/getServerRoutes.js +43 -75
  191. package/dist/esm-node/analyze/index.js +208 -230
  192. package/dist/esm-node/analyze/isDefaultExportFunction.js +7 -5
  193. package/dist/esm-node/analyze/makeLegalIdentifier.js +1 -4
  194. package/dist/esm-node/analyze/nestedRoutes.js +23 -43
  195. package/dist/esm-node/analyze/templates.js +22 -69
  196. package/dist/esm-node/analyze/utils.js +66 -60
  197. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +40 -62
  198. package/dist/esm-node/builder/builder-rspack/index.js +4 -5
  199. package/dist/esm-node/builder/builder-webpack/adapterModern.js +24 -26
  200. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +3 -10
  201. package/dist/esm-node/builder/builder-webpack/index.js +13 -11
  202. package/dist/esm-node/builder/generator/createBuilderOptions.js +4 -5
  203. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +5 -6
  204. package/dist/esm-node/builder/generator/getBuilderTargets.js +5 -11
  205. package/dist/esm-node/builder/generator/index.js +7 -16
  206. package/dist/esm-node/builder/index.js +2 -7
  207. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +2 -6
  208. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +34 -60
  209. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +54 -74
  210. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +23 -8
  211. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +25 -16
  212. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +66 -76
  213. package/dist/esm-node/builder/shared/createCopyInfo.js +2 -8
  214. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +1 -4
  215. package/dist/esm-node/builder/shared/types.js +1 -0
  216. package/dist/esm-node/commands/build.js +7 -9
  217. package/dist/esm-node/commands/deploy.js +1 -4
  218. package/dist/esm-node/commands/dev.js +19 -27
  219. package/dist/esm-node/commands/inspect.js +3 -8
  220. package/dist/esm-node/commands/serve.js +7 -25
  221. package/dist/esm-node/config/default.js +20 -11
  222. package/dist/esm-node/config/initialize/index.js +1 -4
  223. package/dist/esm-node/config/initialize/inits.js +48 -54
  224. package/dist/esm-node/config/legacy/createHtmlConfig.js +2 -19
  225. package/dist/esm-node/config/legacy/createOutputConfig.js +2 -30
  226. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -17
  227. package/dist/esm-node/config/legacy/createToolsConfig.js +2 -22
  228. package/dist/esm-node/config/legacy/index.js +3 -18
  229. package/dist/esm-node/defineConfig.js +7 -13
  230. package/dist/esm-node/exports/server.js +1 -4
  231. package/dist/esm-node/hooks.js +2 -9
  232. package/dist/esm-node/index.js +95 -120
  233. package/dist/esm-node/initialize/index.js +74 -87
  234. package/dist/esm-node/locale/en.js +7 -6
  235. package/dist/esm-node/locale/index.js +5 -5
  236. package/dist/esm-node/locale/zh.js +7 -6
  237. package/dist/esm-node/schema/Schema.js +19 -8
  238. package/dist/esm-node/schema/index.js +121 -36
  239. package/dist/esm-node/schema/legacy.js +262 -72
  240. package/dist/esm-node/types/config/deploy.js +1 -0
  241. package/dist/esm-node/types/config/dev.js +1 -0
  242. package/dist/esm-node/types/config/experiments.js +1 -0
  243. package/dist/esm-node/types/config/html.js +1 -0
  244. package/dist/esm-node/types/config/output.js +1 -0
  245. package/dist/esm-node/types/config/performance.js +1 -0
  246. package/dist/esm-node/types/config/security.js +1 -0
  247. package/dist/esm-node/types/config/source.js +1 -0
  248. package/dist/esm-node/types/config/tools.js +1 -0
  249. package/dist/esm-node/types/hooks.js +1 -0
  250. package/dist/esm-node/types/legacyConfig/deploy.js +1 -0
  251. package/dist/esm-node/types/legacyConfig/dev.js +1 -0
  252. package/dist/esm-node/types/legacyConfig/index.js +1 -0
  253. package/dist/esm-node/types/legacyConfig/output.js +1 -0
  254. package/dist/esm-node/types/legacyConfig/source.js +1 -0
  255. package/dist/esm-node/types/legacyConfig/tools.js +1 -0
  256. package/dist/esm-node/types/utils.js +1 -0
  257. package/dist/esm-node/utils/config.js +16 -47
  258. package/dist/esm-node/utils/createServer.js +5 -12
  259. package/dist/esm-node/utils/env.js +1 -4
  260. package/dist/esm-node/utils/generateWatchFiles.js +13 -20
  261. package/dist/esm-node/utils/getSelectedEntries.js +2 -9
  262. package/dist/esm-node/utils/getServerInternalPlugins.js +2 -8
  263. package/dist/esm-node/utils/printInstructions.js +1 -4
  264. package/dist/esm-node/utils/restart.js +2 -11
  265. package/dist/esm-node/utils/routes.js +4 -4
  266. package/dist/esm-node/utils/types.js +1 -0
  267. package/dist/types/index.d.ts +2 -2
  268. package/package.json +29 -25
@@ -1,34 +1,43 @@
1
- class BottomTemplatePlugin {
2
- constructor(htmlWebpackPlugin) {
3
- this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
4
- this.bodyRegExp = /(<\/\s*body\s*>)/i;
5
- this.htmlWebpackPlugin = htmlWebpackPlugin;
6
- this.name = "bottom-template";
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
7
11
  }
12
+ return obj;
13
+ }
14
+ export class BottomTemplatePlugin {
8
15
  apply(compiler) {
9
16
  compiler.hooks.compilation.tap(this.name, (compilation) => {
10
17
  this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
11
- var _a;
12
- if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
18
+ var _data_plugin_options;
19
+ if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
13
20
  return data;
14
21
  }
15
22
  if (this.bottomTemplateReg.test(data.html)) {
16
23
  data.html = data.html.replace(this.bottomTemplateReg, "");
17
24
  const { bottomTemplate } = data.plugin.options;
18
25
  if (bottomTemplate) {
19
- data.html = data.html.replace(
20
- this.bodyRegExp,
21
- (match) => `
26
+ data.html = data.html.replace(this.bodyRegExp, (match) => `
22
27
  ${bottomTemplate}
23
- ${match}`
24
- );
28
+ ${match}`);
25
29
  }
26
30
  }
27
31
  return data;
28
32
  });
29
33
  });
30
34
  }
35
+ constructor(htmlWebpackPlugin) {
36
+ _define_property(this, "htmlWebpackPlugin", void 0);
37
+ _define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
38
+ _define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
39
+ _define_property(this, "name", void 0);
40
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
41
+ this.name = "bottom-template";
42
+ }
31
43
  }
32
- export {
33
- BottomTemplatePlugin
34
- };
@@ -3,7 +3,7 @@ import { fs } from "@modern-js/utils";
3
3
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
4
4
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
5
5
  const PLUGIN_NAME = "ModernjsRoutePlugin";
6
- class RouterPlugin {
6
+ export class RouterPlugin {
7
7
  apply(compiler) {
8
8
  const { target } = compiler.options;
9
9
  if (target === "node" || Array.isArray(target) && target.includes("node")) {
@@ -25,89 +25,79 @@ class RouterPlugin {
25
25
  return path2;
26
26
  };
27
27
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
28
- compilation.hooks.processAssets.tapPromise(
29
- {
30
- name: PLUGIN_NAME,
31
- stage: PROCESS_ASSETS_STAGE_REPORT
32
- },
33
- async () => {
34
- const stats = compilation.getStats().toJson({
35
- all: false,
36
- publicPath: true,
37
- assets: true,
38
- chunkGroups: true,
39
- chunks: true,
40
- ids: true
28
+ compilation.hooks.processAssets.tapPromise({
29
+ name: PLUGIN_NAME,
30
+ stage: PROCESS_ASSETS_STAGE_REPORT
31
+ }, async () => {
32
+ const stats = compilation.getStats().toJson({
33
+ all: false,
34
+ publicPath: true,
35
+ assets: true,
36
+ chunkGroups: true,
37
+ chunks: true,
38
+ ids: true
39
+ });
40
+ const { publicPath, chunks = [], namedChunkGroups } = stats;
41
+ const routeAssets = {};
42
+ if (!namedChunkGroups) {
43
+ return;
44
+ }
45
+ for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
46
+ const assets = chunkGroup.assets.map((asset) => {
47
+ const filename2 = asset.name;
48
+ return publicPath ? normalizePath(publicPath) + filename2 : filename2;
41
49
  });
42
- const { publicPath, chunks = [], namedChunkGroups } = stats;
43
- const routeAssets = {};
44
- if (!namedChunkGroups) {
45
- return;
46
- }
47
- for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
48
- const assets = chunkGroup.assets.map((asset) => {
49
- const filename2 = asset.name;
50
- return publicPath ? normalizePath(publicPath) + filename2 : filename2;
51
- });
52
- const referenceCssAssets = assets.filter(
53
- (asset) => /\.css$/.test(asset)
54
- );
55
- routeAssets[name] = {
56
- chunkIds: chunkGroup.chunks,
57
- assets,
58
- referenceCssAssets
59
- };
60
- }
61
- const manifest = {
62
- routeAssets
50
+ const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
51
+ routeAssets[name] = {
52
+ chunkIds: chunkGroup.chunks,
53
+ assets,
54
+ referenceCssAssets
63
55
  };
64
- const injectedContent = `
56
+ }
57
+ const manifest = {
58
+ routeAssets
59
+ };
60
+ const injectedContent = `
65
61
  ;(function(){
66
62
  window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
67
- if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
68
- return v.map((item) => {
69
- return item.replace(publicPath, "");
70
- });
71
- }
72
- return v;
73
- })};
63
+ if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
64
+ return v.map((item) => {
65
+ return item.replace(publicPath, "");
66
+ });
67
+ }
68
+ return v;
69
+ })};
74
70
  })();
75
71
  `;
76
- const entrypointsArray = Array.from(
77
- compilation.entrypoints.entries()
78
- );
79
- const entryChunkIds = entrypointsArray.map(
80
- (entrypoint) => entrypoint[0]
81
- );
82
- const entryChunks = [...chunks].filter((chunk) => {
83
- var _a;
84
- return (_a = chunk.names) == null ? void 0 : _a.some((name) => entryChunkIds.includes(name));
85
- });
86
- const entryChunkFiles = entryChunks.map(
87
- (chunk) => [...chunk.files || []].find((fname) => fname.includes(".js"))
88
- );
89
- for (const file of entryChunkFiles) {
90
- const asset = compilation.assets[file];
91
- if (!asset) {
92
- continue;
93
- }
94
- const newContent = `${injectedContent}${asset.source().toString()}`;
95
- newAssetsMap.set(path.join(outputPath, file), newContent);
96
- compilation.updateAsset(
97
- file,
98
- new RawSource(newContent),
99
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
100
- void 0
101
- );
72
+ const entrypointsArray = Array.from(compilation.entrypoints.entries());
73
+ const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
74
+ const entryChunks = [
75
+ ...chunks
76
+ ].filter((chunk) => {
77
+ var _chunk_names;
78
+ return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
79
+ });
80
+ const entryChunkFiles = entryChunks.map((chunk) => [
81
+ ...chunk.files || []
82
+ ].find((fname) => fname.includes(".js")));
83
+ for (const file of entryChunkFiles) {
84
+ const asset = compilation.assets[file];
85
+ if (!asset) {
86
+ continue;
102
87
  }
103
- const filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
104
- await fs.ensureFile(filename);
105
- await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
88
+ const newContent = `${injectedContent}${asset.source().toString()}`;
89
+ newAssetsMap.set(path.join(outputPath, file), newContent);
90
+ compilation.updateAsset(
91
+ file,
92
+ new RawSource(newContent),
93
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
94
+ void 0
95
+ );
106
96
  }
107
- );
97
+ const filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
98
+ await fs.ensureFile(filename);
99
+ await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
100
+ });
108
101
  });
109
102
  }
110
103
  }
111
- export {
112
- RouterPlugin
113
- };
@@ -1,9 +1,6 @@
1
1
  import path from "path";
2
- function createCopyInfo(appContext, config) {
3
- const configDir = path.resolve(
4
- appContext.appDirectory,
5
- config.source.configDir || "./config"
6
- );
2
+ export function createCopyInfo(appContext, config) {
3
+ const configDir = path.resolve(appContext.appDirectory, config.source.configDir || "./config");
7
4
  const uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
8
5
  const publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
9
6
  return {
@@ -12,6 +9,3 @@ function createCopyInfo(appContext, config) {
12
9
  publicDir
13
10
  };
14
11
  }
15
- export {
16
- createCopyInfo
17
- };
@@ -1,7 +1,4 @@
1
1
  function loader() {
2
2
  return `module.exports = {}`;
3
3
  }
4
- var serverModuleLoader_default = loader;
5
- export {
6
- serverModuleLoader_default as default
7
- };
4
+ export default loader;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,8 +2,8 @@ import { ResolvedConfigContext } from "@modern-js/core";
2
2
  import { logger, printBuildError } from "@modern-js/utils";
3
3
  import { generateRoutes } from "../utils/routes";
4
4
  import { buildServerConfig } from "../utils/config";
5
- const build = async (api, options) => {
6
- if (options == null ? void 0 : options.analyze) {
5
+ export const build = async (api, options) => {
6
+ if (options === null || options === void 0 ? void 0 : options.analyze) {
7
7
  process.env.BUNDLE_ANALYZE = "true";
8
8
  }
9
9
  let resolvedConfig = api.useResolvedConfigContext();
@@ -28,7 +28,10 @@ const build = async (api, options) => {
28
28
  });
29
29
  return;
30
30
  }
31
- resolvedConfig = { ...resolvedConfig, cliOptions: options };
31
+ resolvedConfig = {
32
+ ...resolvedConfig,
33
+ cliOptions: options
34
+ };
32
35
  ResolvedConfigContext.set(resolvedConfig);
33
36
  const { distDirectory, appDirectory, serverConfigFile } = appContext;
34
37
  await buildServerConfig({
@@ -39,9 +42,7 @@ const build = async (api, options) => {
39
42
  try {
40
43
  logger.info("Create a production build...\n");
41
44
  if (!appContext.builder) {
42
- throw new Error(
43
- "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
44
- );
45
+ throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
45
46
  }
46
47
  await appContext.builder.build();
47
48
  } catch (error) {
@@ -49,6 +50,3 @@ const build = async (api, options) => {
49
50
  process.exit(1);
50
51
  }
51
52
  };
52
- export {
53
- build
54
- };
@@ -1,8 +1,5 @@
1
- const deploy = async (api, options) => {
1
+ export const deploy = async (api, options) => {
2
2
  const hookRunners = api.useHookRunners();
3
3
  await hookRunners.beforeDeploy(options);
4
4
  await hookRunners.afterDeploy(options);
5
5
  };
6
- export {
7
- deploy
8
- };
@@ -1,23 +1,22 @@
1
1
  import { ResolvedConfigContext } from "@modern-js/core";
2
2
  import { DEFAULT_DEV_HOST } from "@modern-js/utils";
3
3
  import { printInstructions } from "../utils/printInstructions";
4
- import {
5
- setServer,
6
- createServer,
7
- injectDataLoaderPlugin
8
- } from "../utils/createServer";
4
+ import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
9
5
  import { generateRoutes } from "../utils/routes";
10
6
  import { buildServerConfig } from "../utils/config";
11
7
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
12
- const dev = async (api, options) => {
13
- var _a, _b;
8
+ export const dev = async (api, options) => {
9
+ var _normalizedConfig_tools;
14
10
  if (options.analyze) {
15
11
  process.env.BUNDLE_ANALYZE = "true";
16
12
  }
17
13
  let normalizedConfig = api.useResolvedConfigContext();
18
14
  const appContext = api.useAppContext();
19
15
  const hookRunners = api.useHookRunners();
20
- normalizedConfig = { ...normalizedConfig, cliOptions: options };
16
+ normalizedConfig = {
17
+ ...normalizedConfig,
18
+ cliOptions: options
19
+ };
21
20
  ResolvedConfigContext.set(normalizedConfig);
22
21
  const { appDirectory, distDirectory, port, apiOnly, serverConfigFile } = appContext;
23
22
  await buildServerConfig({
@@ -32,9 +31,7 @@ const dev = async (api, options) => {
32
31
  });
33
32
  await hookRunners.beforeDev();
34
33
  if (!appContext.builder && !apiOnly) {
35
- throw new Error(
36
- "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
37
- );
34
+ throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
38
35
  }
39
36
  await generateRoutes(appContext);
40
37
  const serverInternalPlugins = await getServerInternalPlugins(api);
@@ -43,7 +40,7 @@ const dev = async (api, options) => {
43
40
  port,
44
41
  https: normalizedConfig.dev.https,
45
42
  host: normalizedConfig.dev.host,
46
- ...(_a = normalizedConfig.tools) == null ? void 0 : _a.devServer
43
+ ...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
47
44
  },
48
45
  appContext: {
49
46
  appDirectory: appContext.appDirectory,
@@ -57,23 +54,21 @@ const dev = async (api, options) => {
57
54
  internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
58
55
  };
59
56
  if (apiOnly) {
57
+ var _normalizedConfig_dev;
60
58
  const app = await createServer({
61
59
  ...serverOptions,
62
60
  compiler: null
63
61
  });
64
- const host = ((_b = normalizedConfig.dev) == null ? void 0 : _b.host) || DEFAULT_DEV_HOST;
65
- app.listen(
66
- {
67
- port,
68
- host
69
- },
70
- async (err) => {
71
- if (err) {
72
- throw err;
73
- }
74
- printInstructions(hookRunners, appContext, normalizedConfig);
62
+ const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
63
+ app.listen({
64
+ port,
65
+ host
66
+ }, async (err) => {
67
+ if (err) {
68
+ throw err;
75
69
  }
76
- );
70
+ printInstructions(hookRunners, appContext, normalizedConfig);
71
+ });
77
72
  } else {
78
73
  const { server } = await appContext.builder.startDevServer({
79
74
  printURLs: false,
@@ -82,6 +77,3 @@ const dev = async (api, options) => {
82
77
  setServer(server);
83
78
  }
84
79
  };
85
- export {
86
- dev
87
- };
@@ -1,18 +1,13 @@
1
1
  import { join } from "path";
2
- const inspect = async (api, options) => {
2
+ export const inspect = async (api, options) => {
3
3
  const appContext = api.useAppContext();
4
4
  if (!appContext.builder) {
5
- throw new Error(
6
- "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
7
- );
5
+ throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
8
6
  }
9
7
  return appContext.builder.inspectConfig({
10
8
  env: options.env,
11
9
  verbose: options.verbose,
12
- outputPath: join(appContext == null ? void 0 : appContext.builder.context.distPath, options.output),
10
+ outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
13
11
  writeToDisk: true
14
12
  });
15
13
  };
16
- export {
17
- inspect
18
- };
@@ -3,17 +3,14 @@ import server from "@modern-js/prod-server";
3
3
  import { printInstructions } from "../utils/printInstructions";
4
4
  import { injectDataLoaderPlugin } from "../utils/createServer";
5
5
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
6
- const start = async (api) => {
7
- var _a, _b;
6
+ export const start = async (api) => {
7
+ var _userConfig_source, _userConfig_output_distPath;
8
8
  const appContext = api.useAppContext();
9
9
  const userConfig = api.useResolvedConfigContext();
10
10
  const hookRunners = api.useHookRunners();
11
11
  const { appDirectory, port, serverConfigFile } = appContext;
12
12
  logger.log(chalk.cyan(`Starting the modern server...`));
13
- const apiOnly = await isApiOnly(
14
- appContext.appDirectory,
15
- (_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.entriesDir
16
- );
13
+ const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir);
17
14
  const serverInternalPlugins = await getServerInternalPlugins(api);
18
15
  const app = await server({
19
16
  pwd: appDirectory,
@@ -21,26 +18,14 @@ const start = async (api) => {
21
18
  ...userConfig,
22
19
  dev: userConfig.dev,
23
20
  output: {
24
- path: (_b = userConfig.output.distPath) == null ? void 0 : _b.root,
21
+ path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root,
25
22
  ...userConfig.output || {}
26
23
  }
27
24
  },
28
25
  appContext: {
29
- sharedDirectory: getTargetDir(
30
- appContext.sharedDirectory,
31
- appContext.appDirectory,
32
- appContext.distDirectory
33
- ),
34
- apiDirectory: getTargetDir(
35
- appContext.apiDirectory,
36
- appContext.appDirectory,
37
- appContext.distDirectory
38
- ),
39
- lambdaDirectory: getTargetDir(
40
- appContext.lambdaDirectory,
41
- appContext.appDirectory,
42
- appContext.distDirectory
43
- )
26
+ sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
27
+ apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
28
+ lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
44
29
  },
45
30
  serverConfigFile,
46
31
  internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
@@ -53,6 +38,3 @@ const start = async (api) => {
53
38
  await printInstructions(hookRunners, appContext, userConfig);
54
39
  });
55
40
  };
56
- export {
57
- start
58
- };
@@ -1,6 +1,6 @@
1
1
  import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
2
2
  import { getAutoInjectEnv } from "../utils/env";
3
- function createDefaultConfig(appContext, bundler) {
3
+ export function createDefaultConfig(appContext, bundler) {
4
4
  const defaultBuilderConfig = createDefaultBuilderConfig();
5
5
  const dev = {
6
6
  ...defaultBuilderConfig.dev,
@@ -31,9 +31,14 @@ function createDefaultConfig(appContext, bundler) {
31
31
  ...defaultBuilderConfig.html,
32
32
  title: "",
33
33
  meta: {
34
- charset: { charset: "utf-8" },
34
+ charset: {
35
+ charset: "utf-8"
36
+ },
35
37
  viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
36
- "http-equiv": { "http-equiv": "x-ua-compatible", content: "ie=edge" },
38
+ "http-equiv": {
39
+ "http-equiv": "x-ua-compatible",
40
+ content: "ie=edge"
41
+ },
37
42
  renderer: "webkit",
38
43
  layoutmode: "standard",
39
44
  imagemode: "force",
@@ -65,7 +70,7 @@ function createDefaultConfig(appContext, bundler) {
65
70
  runtimeByEntries: {}
66
71
  };
67
72
  }
68
- function createLegacyDefaultConfig(appContext) {
73
+ export function createLegacyDefaultConfig(appContext) {
69
74
  const defaultAlias = appContext ? {
70
75
  [appContext.internalDirAlias]: appContext.internalDirectory,
71
76
  [appContext.internalSrcAlias]: appContext.srcDirectory,
@@ -95,9 +100,14 @@ function createLegacyDefaultConfig(appContext) {
95
100
  title: "",
96
101
  titleByEntries: void 0,
97
102
  meta: {
98
- charset: { charset: "utf-8" },
103
+ charset: {
104
+ charset: "utf-8"
105
+ },
99
106
  viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
100
- "http-equiv": { "http-equiv": "x-ua-compatible", content: "ie=edge" },
107
+ "http-equiv": {
108
+ "http-equiv": "x-ua-compatible",
109
+ content: "ie=edge"
110
+ },
101
111
  renderer: "webkit",
102
112
  layoutmode: "standard",
103
113
  imagemode: "force",
@@ -138,7 +148,10 @@ function createLegacyDefaultConfig(appContext) {
138
148
  baseUrl: "/",
139
149
  port: 8080
140
150
  };
141
- const devDefaults = { assetPrefix: false, https: false };
151
+ const devDefaults = {
152
+ assetPrefix: false,
153
+ https: false
154
+ };
142
155
  const toolsDefaults = {
143
156
  webpack: void 0,
144
157
  babel: void 0,
@@ -160,7 +173,3 @@ function createLegacyDefaultConfig(appContext) {
160
173
  runtimeByEntries: {}
161
174
  };
162
175
  }
163
- export {
164
- createDefaultConfig,
165
- createLegacyDefaultConfig
166
- };
@@ -1,5 +1,5 @@
1
1
  import { initHtmlConfig, initSourceConfig, initToolsConfig } from "./inits";
2
- function initialNormalizedConfig(config, appContext, bundler) {
2
+ export function initialNormalizedConfig(config, appContext, bundler) {
3
3
  initHtmlConfig(config, appContext);
4
4
  initSourceConfig(config, appContext, bundler);
5
5
  if (bundler === "webpack") {
@@ -7,6 +7,3 @@ function initialNormalizedConfig(config, appContext, bundler) {
7
7
  }
8
8
  return config;
9
9
  }
10
- export {
11
- initialNormalizedConfig
12
- };