@modern-js/app-tools 2.15.0 → 2.16.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 +45 -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,48 +1,64 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var adapterSSR_exports = {};
29
- __export(adapterSSR_exports, {
30
- builderPluginAdapterSSR: () => builderPluginAdapterSSR
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
31
4
  });
32
- module.exports = __toCommonJS(adapterSSR_exports);
33
- var path = __toESM(require("path"));
34
- var import_builder_shared = require("@modern-js/builder-shared");
35
- var import_utils = require("@modern-js/utils");
36
- var import_bundlerPlugins = require("../bundlerPlugins");
37
- var import_utils2 = require("../../../analyze/utils");
38
- var import_adapterHtml = require("./adapterHtml");
5
+ Object.defineProperty(exports, "builderPluginAdapterSSR", {
6
+ enumerable: true,
7
+ get: () => builderPluginAdapterSSR
8
+ });
9
+ const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
10
+ const _buildershared = require("@modern-js/builder-shared");
11
+ const _utils = require("@modern-js/utils");
12
+ const _bundlerPlugins = require("../bundlerPlugins");
13
+ const _utils1 = require("../../../analyze/utils");
14
+ const _adapterHtml = require("./adapterHtml");
15
+ function _getRequireWildcardCache(nodeInterop) {
16
+ if (typeof WeakMap !== "function")
17
+ return null;
18
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
19
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
20
+ return (_getRequireWildcardCache = function(nodeInterop2) {
21
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
22
+ })(nodeInterop);
23
+ }
24
+ function _interop_require_wildcard(obj, nodeInterop) {
25
+ if (!nodeInterop && obj && obj.__esModule) {
26
+ return obj;
27
+ }
28
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
29
+ return {
30
+ default: obj
31
+ };
32
+ }
33
+ var cache = _getRequireWildcardCache(nodeInterop);
34
+ if (cache && cache.has(obj)) {
35
+ return cache.get(obj);
36
+ }
37
+ var newObj = {};
38
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
39
+ for (var key in obj) {
40
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
41
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
42
+ if (desc && (desc.get || desc.set)) {
43
+ Object.defineProperty(newObj, key, desc);
44
+ } else {
45
+ newObj[key] = obj[key];
46
+ }
47
+ }
48
+ }
49
+ newObj.default = obj;
50
+ if (cache) {
51
+ cache.set(obj, newObj);
52
+ }
53
+ return newObj;
54
+ }
39
55
  const builderPluginAdapterSSR = (options) => ({
40
56
  name: "builder-plugin-adapter-modern-ssr",
41
57
  setup(api) {
42
58
  const { normalizedConfig } = options;
43
59
  api.modifyBuilderConfig((config) => {
44
60
  if (isStreamingSSR(normalizedConfig)) {
45
- return (0, import_builder_shared.mergeBuilderConfig)(config, {
61
+ return (0, _buildershared.mergeBuilderConfig)(config, {
46
62
  html: {
47
63
  inject: "body"
48
64
  }
@@ -50,32 +66,33 @@ const builderPluginAdapterSSR = (options) => ({
50
66
  }
51
67
  return config;
52
68
  });
53
- api.modifyBundlerChain(
54
- async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
55
- const builderConfig = api.getNormalizedConfig();
56
- const { normalizedConfig: normalizedConfig2 } = options;
57
- applyRouterPlugin(chain, options);
58
- if ((0, import_utils.isSSR)(normalizedConfig2)) {
59
- await applySSRLoaderEntry(chain, options, isServer);
60
- applySSRDataLoader(chain, options);
61
- }
62
- if (["node", "service-worker"].includes(target)) {
63
- applyFilterEntriesBySSRConfig({
64
- isProd,
65
- chain,
66
- appNormalizedConfig: normalizedConfig2
67
- });
68
- }
69
- if ((0, import_adapterHtml.isHtmlEnabled)(builderConfig, target)) {
70
- applyAsyncChunkHtmlPlugin({
71
- chain,
72
- modernConfig: options.normalizedConfig,
73
- CHAIN_ID,
74
- HtmlBundlerPlugin
75
- });
76
- }
69
+ api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
70
+ const builderConfig = api.getNormalizedConfig();
71
+ const { normalizedConfig: normalizedConfig2 } = options;
72
+ applyRouterPlugin(chain, options);
73
+ if ((0, _utils.isSSR)(normalizedConfig2)) {
74
+ await applySSRLoaderEntry(chain, options, isServer);
75
+ applySSRDataLoader(chain, options);
76
+ }
77
+ if ([
78
+ "node",
79
+ "service-worker"
80
+ ].includes(target)) {
81
+ applyFilterEntriesBySSRConfig({
82
+ isProd,
83
+ chain,
84
+ appNormalizedConfig: normalizedConfig2
85
+ });
77
86
  }
78
- );
87
+ if ((0, _adapterHtml.isHtmlEnabled)(builderConfig, target)) {
88
+ applyAsyncChunkHtmlPlugin({
89
+ chain,
90
+ modernConfig: options.normalizedConfig,
91
+ CHAIN_ID,
92
+ HtmlBundlerPlugin
93
+ });
94
+ }
95
+ });
79
96
  }
80
97
  });
81
98
  const isStreamingSSR = (userConfig) => {
@@ -84,7 +101,7 @@ const isStreamingSSR = (userConfig) => {
84
101
  if (isStreaming(server.ssr)) {
85
102
  return true;
86
103
  }
87
- if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
104
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
88
105
  for (const name of Object.keys(server.ssrByEntries)) {
89
106
  if (isStreaming(server.ssrByEntries[name])) {
90
107
  return true;
@@ -93,51 +110,40 @@ const isStreamingSSR = (userConfig) => {
93
110
  }
94
111
  return false;
95
112
  };
96
- function applyAsyncChunkHtmlPlugin({
97
- chain,
98
- modernConfig,
99
- CHAIN_ID,
100
- HtmlBundlerPlugin
101
- }) {
113
+ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerPlugin }) {
102
114
  if (isStreamingSSR(modernConfig)) {
103
- chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_bundlerPlugins.HtmlAsyncChunkPlugin, [HtmlBundlerPlugin]);
115
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(_bundlerPlugins.HtmlAsyncChunkPlugin, [
116
+ HtmlBundlerPlugin
117
+ ]);
104
118
  }
105
119
  }
106
120
  function applyRouterPlugin(chain, options) {
107
- var _a;
121
+ var _normalizedConfig_runtime;
108
122
  const { appContext, normalizedConfig } = options;
109
123
  const { entrypoints } = appContext;
110
- const existNestedRoutes = entrypoints.some(
111
- (entrypoint) => entrypoint.nestedRoutesEntry
112
- );
113
- const routerConfig = (_a = normalizedConfig == null ? void 0 : normalizedConfig.runtime) == null ? void 0 : _a.router;
114
- const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
124
+ const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
125
+ const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
126
+ const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
115
127
  if (existNestedRoutes || routerManifest) {
116
- chain.plugin("route-plugin").use(import_bundlerPlugins.RouterPlugin);
128
+ chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin);
117
129
  }
118
130
  }
119
- function applyFilterEntriesBySSRConfig({
120
- isProd,
121
- chain,
122
- appNormalizedConfig
123
- }) {
124
- var _a;
131
+ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
132
+ var _ref;
125
133
  const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
126
134
  const entries = chain.entryPoints.entries();
127
- if (isProd && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
135
+ if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_ref = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _ref === void 0 ? void 0 : _ref[0]) === "function")) {
128
136
  return;
129
137
  }
130
138
  if (typeof entries === "undefined") {
131
- throw new Error(
132
- "No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
133
- );
139
+ throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
134
140
  }
135
141
  const entryNames = Object.keys(entries);
136
- if (isProd && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
142
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
137
143
  return;
138
144
  }
139
145
  const ssgEntries = [];
140
- if (isProd && (outputConfig == null ? void 0 : outputConfig.ssg)) {
146
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
141
147
  const { ssg } = outputConfig;
142
148
  entryNames.forEach((name) => {
143
149
  if (ssg[name]) {
@@ -147,7 +153,7 @@ function applyFilterEntriesBySSRConfig({
147
153
  }
148
154
  const { ssr, ssrByEntries } = serverConfig || {};
149
155
  entryNames.forEach((name) => {
150
- if (!ssgEntries.includes(name) && (ssr && (ssrByEntries == null ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries == null ? void 0 : ssrByEntries[name]))) {
156
+ if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
151
157
  chain.entryPoints.delete(name);
152
158
  }
153
159
  });
@@ -156,32 +162,23 @@ async function applySSRLoaderEntry(chain, optinos, isServer) {
156
162
  const { appContext } = optinos;
157
163
  const { internalDirectory } = appContext;
158
164
  const { entrypoints } = appContext;
159
- await Promise.all(
160
- entrypoints.map(async (entrypoint) => {
161
- const { entryName } = entrypoint;
162
- const serverLoadersFile = (0, import_utils2.getServerCombinedModueFile)(
163
- internalDirectory,
164
- entryName
165
- );
166
- if (isServer) {
167
- try {
168
- await import_utils.fs.access(serverLoadersFile, import_utils.fs.constants.F_OK);
169
- chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
170
- } catch (err) {
171
- }
165
+ await Promise.all(entrypoints.map(async (entrypoint) => {
166
+ const { entryName } = entrypoint;
167
+ const serverLoadersFile = (0, _utils1.getServerCombinedModueFile)(internalDirectory, entryName);
168
+ if (isServer) {
169
+ try {
170
+ await _utils.fs.access(serverLoadersFile, _utils.fs.constants.F_OK);
171
+ chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
172
+ } catch (err) {
172
173
  }
173
- })
174
- );
174
+ }
175
+ }));
175
176
  }
176
177
  function applySSRDataLoader(chain, options) {
177
178
  const { normalizedConfig, appContext } = options;
178
179
  const { appDirectory } = appContext;
179
180
  const { entriesDir = "./src" } = normalizedConfig.source;
180
- const absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
181
+ const absolutePath = _path.resolve(appDirectory, entriesDir).split(_path.sep).join("(\\\\|/)");
181
182
  const reg = new RegExp(`${absolutePath}.*\\.loader\\.[t|j]s$`);
182
183
  chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
183
184
  }
184
- // Annotate the CommonJS export names for ESM import in node:
185
- 0 && (module.exports = {
186
- builderPluginAdapterSSR
187
- });
@@ -1,19 +1,20 @@
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 builderPlugins_exports = {};
16
- module.exports = __toCommonJS(builderPlugins_exports);
17
- __reExport(builderPlugins_exports, require("./adapterBasic"), module.exports);
18
- __reExport(builderPlugins_exports, require("./adapterHtml"), module.exports);
19
- __reExport(builderPlugins_exports, require("./adapterSSR"), module.exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./adapterBasic"), exports);
6
+ _export_star(require("./adapterHtml"), exports);
7
+ _export_star(require("./adapterSSR"), exports);
8
+ function _export_star(from, to) {
9
+ Object.keys(from).forEach(function(k) {
10
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
+ Object.defineProperty(to, k, {
12
+ enumerable: true,
13
+ get: function() {
14
+ return from[k];
15
+ }
16
+ });
17
+ }
18
+ });
19
+ return from;
20
+ }
@@ -1,35 +1,33 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var HtmlAsyncChunkPlugin_exports = {};
19
- __export(HtmlAsyncChunkPlugin_exports, {
20
- HtmlAsyncChunkPlugin: () => HtmlAsyncChunkPlugin
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
21
4
  });
22
- module.exports = __toCommonJS(HtmlAsyncChunkPlugin_exports);
23
- class HtmlAsyncChunkPlugin {
24
- constructor(htmlWebpackPlugin) {
25
- this.name = "HtmlAsyncChunkPlugin";
26
- this.htmlWebpackPlugin = htmlWebpackPlugin;
5
+ Object.defineProperty(exports, "HtmlAsyncChunkPlugin", {
6
+ enumerable: true,
7
+ get: () => HtmlAsyncChunkPlugin
8
+ });
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
27
19
  }
20
+ return obj;
21
+ }
22
+ class HtmlAsyncChunkPlugin {
28
23
  apply(compiler) {
29
24
  compiler.hooks.compilation.tap(this.name, (compilation) => {
30
25
  const hooks = this.htmlWebpackPlugin.getHooks(compilation);
31
26
  hooks.alterAssetTagGroups.tap(this.name, (assets) => {
32
- const tags = [...assets.headTags, ...assets.bodyTags];
27
+ const tags = [
28
+ ...assets.headTags,
29
+ ...assets.bodyTags
30
+ ];
33
31
  for (const tag of tags) {
34
32
  if (tag.tagName === "script") {
35
33
  const { attributes } = tag;
@@ -43,8 +41,10 @@ class HtmlAsyncChunkPlugin {
43
41
  });
44
42
  });
45
43
  }
44
+ constructor(htmlWebpackPlugin) {
45
+ _define_property(this, "name", void 0);
46
+ _define_property(this, "htmlWebpackPlugin", void 0);
47
+ this.name = "HtmlAsyncChunkPlugin";
48
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
49
+ }
46
50
  }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- HtmlAsyncChunkPlugin
50
- });
@@ -1,57 +1,51 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var HtmlBottomTemplate_exports = {};
19
- __export(HtmlBottomTemplate_exports, {
20
- BottomTemplatePlugin: () => BottomTemplatePlugin
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
21
4
  });
22
- module.exports = __toCommonJS(HtmlBottomTemplate_exports);
23
- class BottomTemplatePlugin {
24
- constructor(htmlWebpackPlugin) {
25
- this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
26
- this.bodyRegExp = /(<\/\s*body\s*>)/i;
27
- this.htmlWebpackPlugin = htmlWebpackPlugin;
28
- this.name = "bottom-template";
5
+ Object.defineProperty(exports, "BottomTemplatePlugin", {
6
+ enumerable: true,
7
+ get: () => BottomTemplatePlugin
8
+ });
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
29
19
  }
20
+ return obj;
21
+ }
22
+ class BottomTemplatePlugin {
30
23
  apply(compiler) {
31
24
  compiler.hooks.compilation.tap(this.name, (compilation) => {
32
25
  this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
33
- var _a;
34
- if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
26
+ var _data_plugin_options;
27
+ if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
35
28
  return data;
36
29
  }
37
30
  if (this.bottomTemplateReg.test(data.html)) {
38
31
  data.html = data.html.replace(this.bottomTemplateReg, "");
39
32
  const { bottomTemplate } = data.plugin.options;
40
33
  if (bottomTemplate) {
41
- data.html = data.html.replace(
42
- this.bodyRegExp,
43
- (match) => `
34
+ data.html = data.html.replace(this.bodyRegExp, (match) => `
44
35
  ${bottomTemplate}
45
- ${match}`
46
- );
36
+ ${match}`);
47
37
  }
48
38
  }
49
39
  return data;
50
40
  });
51
41
  });
52
42
  }
43
+ constructor(htmlWebpackPlugin) {
44
+ _define_property(this, "htmlWebpackPlugin", void 0);
45
+ _define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
46
+ _define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
47
+ _define_property(this, "name", void 0);
48
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
49
+ this.name = "bottom-template";
50
+ }
53
51
  }
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
56
- BottomTemplatePlugin
57
- });