@modern-js/app-tools 2.9.0 → 2.10.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 (266) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/cjs/analyze/generateCode.js +3 -1
  3. package/dist/cjs/analyze/index.js +8 -0
  4. package/dist/cjs/analyze/templates.js +45 -13
  5. package/dist/cjs/builder/builder-rspack/index.js +22 -1
  6. package/dist/cjs/builder/index.js +3 -1
  7. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -3
  8. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +14 -3
  9. package/dist/cjs/commands/serve.js +9 -2
  10. package/dist/esm/analyze/generateCode.js +3 -2
  11. package/dist/esm/analyze/index.js +8 -0
  12. package/dist/esm/analyze/templates.js +53 -15
  13. package/dist/esm/builder/builder-rspack/index.js +169 -1
  14. package/dist/esm/builder/index.js +15 -8
  15. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +10 -3
  16. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +15 -4
  17. package/dist/esm/commands/serve.js +59 -2
  18. package/dist/esm-node/analyze/generateCode.js +3 -1
  19. package/dist/esm-node/analyze/index.js +8 -0
  20. package/dist/esm-node/analyze/templates.js +45 -13
  21. package/dist/esm-node/builder/builder-rspack/index.js +12 -1
  22. package/dist/esm-node/builder/index.js +3 -1
  23. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +7 -4
  24. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +15 -9
  25. package/dist/esm-node/commands/serve.js +9 -2
  26. package/dist/js/modern/analyze/constants.js +54 -0
  27. package/dist/js/modern/analyze/generateCode.js +247 -0
  28. package/dist/js/modern/analyze/getBundleEntry.js +71 -0
  29. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
  30. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
  31. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
  32. package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
  33. package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
  34. package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
  35. package/dist/js/modern/analyze/getServerRoutes.js +175 -0
  36. package/dist/js/modern/analyze/index.js +332 -0
  37. package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
  38. package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
  39. package/dist/js/modern/analyze/nestedRoutes.js +157 -0
  40. package/dist/js/modern/analyze/templates.js +334 -0
  41. package/dist/js/modern/analyze/utils.js +141 -0
  42. package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
  43. package/dist/js/modern/builder/index.js +159 -0
  44. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  45. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  46. package/dist/js/modern/builder/share.js +46 -0
  47. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
  48. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
  49. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
  50. package/dist/js/modern/commands/build.js +91 -0
  51. package/dist/js/modern/commands/deploy.js +28 -0
  52. package/dist/js/modern/commands/dev.js +109 -0
  53. package/dist/js/modern/commands/index.js +3 -0
  54. package/dist/js/modern/commands/inspect.js +38 -0
  55. package/dist/js/modern/commands/serve.js +54 -0
  56. package/dist/js/modern/config/default.js +175 -0
  57. package/dist/js/modern/config/index.js +8 -0
  58. package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
  59. package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
  60. package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
  61. package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
  62. package/dist/js/modern/config/initial/index.js +16 -0
  63. package/dist/js/modern/config/initial/inits.js +152 -0
  64. package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
  65. package/dist/js/modern/defineConfig.js +27 -0
  66. package/dist/js/modern/exports/server.js +4 -0
  67. package/dist/js/modern/hooks.js +35 -0
  68. package/dist/js/modern/index.js +211 -0
  69. package/dist/js/modern/initialize/index.js +124 -0
  70. package/dist/js/modern/locale/en.js +36 -0
  71. package/dist/js/modern/locale/index.js +9 -0
  72. package/dist/js/modern/locale/zh.js +36 -0
  73. package/dist/js/modern/schema/Schema.js +40 -0
  74. package/dist/js/modern/schema/index.js +88 -0
  75. package/dist/js/modern/schema/legacy.js +148 -0
  76. package/dist/js/modern/types/config/deploy.js +0 -0
  77. package/dist/js/modern/types/config/dev.js +0 -0
  78. package/dist/js/modern/types/config/experiments.js +0 -0
  79. package/dist/js/modern/types/config/html.js +0 -0
  80. package/dist/js/modern/types/config/index.js +1 -0
  81. package/dist/js/modern/types/config/output.js +0 -0
  82. package/dist/js/modern/types/config/performance.js +0 -0
  83. package/dist/js/modern/types/config/security.js +0 -0
  84. package/dist/js/modern/types/config/source.js +0 -0
  85. package/dist/js/modern/types/config/tools.js +0 -0
  86. package/dist/js/modern/types/hooks.js +0 -0
  87. package/dist/js/modern/types/index.js +3 -0
  88. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  89. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  90. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  91. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  92. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  93. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  94. package/dist/js/modern/utils/config.js +128 -0
  95. package/dist/js/modern/utils/createServer.js +75 -0
  96. package/dist/js/modern/utils/env.js +15 -0
  97. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  98. package/dist/js/modern/utils/getSelectedEntries.js +58 -0
  99. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  100. package/dist/js/modern/utils/language.js +8 -0
  101. package/dist/js/modern/utils/printInstructions.js +31 -0
  102. package/dist/js/modern/utils/restart.js +44 -0
  103. package/dist/js/modern/utils/routes.js +30 -0
  104. package/dist/js/modern/utils/types.js +0 -0
  105. package/dist/js/node/analyze/constants.js +98 -0
  106. package/dist/js/node/analyze/generateCode.js +271 -0
  107. package/dist/js/node/analyze/getBundleEntry.js +95 -0
  108. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
  109. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
  110. package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
  111. package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
  112. package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
  113. package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
  114. package/dist/js/node/analyze/getServerRoutes.js +194 -0
  115. package/dist/js/node/analyze/index.js +339 -0
  116. package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
  117. package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
  118. package/dist/js/node/analyze/nestedRoutes.js +184 -0
  119. package/dist/js/node/analyze/templates.js +365 -0
  120. package/dist/js/node/analyze/utils.js +172 -0
  121. package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
  122. package/dist/js/node/builder/index.js +177 -0
  123. package/dist/js/node/builder/loaders/routerLoader.js +38 -0
  124. package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
  125. package/dist/js/node/builder/share.js +75 -0
  126. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
  127. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
  128. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
  129. package/dist/js/node/commands/build.js +112 -0
  130. package/dist/js/node/commands/deploy.js +51 -0
  131. package/dist/js/node/commands/dev.js +126 -0
  132. package/dist/js/node/commands/index.js +19 -0
  133. package/dist/js/node/commands/inspect.js +61 -0
  134. package/dist/js/node/commands/serve.js +83 -0
  135. package/dist/js/node/config/default.js +197 -0
  136. package/dist/js/node/config/index.js +34 -0
  137. package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
  138. package/dist/js/node/config/initial/createOutputConfig.js +91 -0
  139. package/dist/js/node/config/initial/createSourceConfig.js +62 -0
  140. package/dist/js/node/config/initial/createToolsConfig.js +65 -0
  141. package/dist/js/node/config/initial/index.js +41 -0
  142. package/dist/js/node/config/initial/inits.js +175 -0
  143. package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
  144. package/dist/js/node/defineConfig.js +49 -0
  145. package/dist/js/node/exports/server.js +27 -0
  146. package/dist/js/node/hooks.js +54 -0
  147. package/dist/js/node/index.js +235 -0
  148. package/dist/js/node/initialize/index.js +134 -0
  149. package/dist/js/node/locale/en.js +59 -0
  150. package/dist/js/node/locale/index.js +33 -0
  151. package/dist/js/node/locale/zh.js +59 -0
  152. package/dist/js/node/schema/Schema.js +63 -0
  153. package/dist/js/node/schema/index.js +118 -0
  154. package/dist/js/node/schema/legacy.js +169 -0
  155. package/dist/js/node/types/config/deploy.js +15 -0
  156. package/dist/js/node/types/config/dev.js +15 -0
  157. package/dist/js/node/types/config/experiments.js +15 -0
  158. package/dist/js/node/types/config/html.js +15 -0
  159. package/dist/js/node/types/config/index.js +17 -0
  160. package/dist/js/node/types/config/output.js +15 -0
  161. package/dist/js/node/types/config/performance.js +15 -0
  162. package/dist/js/node/types/config/security.js +15 -0
  163. package/dist/js/node/types/config/source.js +15 -0
  164. package/dist/js/node/types/config/tools.js +15 -0
  165. package/dist/js/node/types/hooks.js +15 -0
  166. package/dist/js/node/types/index.js +19 -0
  167. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  168. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  169. package/dist/js/node/types/legacyConfig/index.js +15 -0
  170. package/dist/js/node/types/legacyConfig/output.js +15 -0
  171. package/dist/js/node/types/legacyConfig/source.js +15 -0
  172. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  173. package/dist/js/node/utils/config.js +153 -0
  174. package/dist/js/node/utils/createServer.js +106 -0
  175. package/dist/js/node/utils/env.js +38 -0
  176. package/dist/js/node/utils/generateWatchFiles.js +85 -0
  177. package/dist/js/node/utils/getSelectedEntries.js +81 -0
  178. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  179. package/dist/js/node/utils/language.js +31 -0
  180. package/dist/js/node/utils/printInstructions.js +54 -0
  181. package/dist/js/node/utils/restart.js +67 -0
  182. package/dist/js/node/utils/routes.js +59 -0
  183. package/dist/js/node/utils/types.js +15 -0
  184. package/dist/js/treeshaking/analyze/constants.js +40 -0
  185. package/dist/js/treeshaking/analyze/generateCode.js +485 -0
  186. package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
  187. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
  188. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  189. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
  190. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
  191. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
  192. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
  193. package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
  194. package/dist/js/treeshaking/analyze/index.js +697 -0
  195. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
  196. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
  197. package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
  198. package/dist/js/treeshaking/analyze/templates.js +468 -0
  199. package/dist/js/treeshaking/analyze/utils.js +374 -0
  200. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
  201. package/dist/js/treeshaking/builder/index.js +374 -0
  202. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  203. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  204. package/dist/js/treeshaking/builder/share.js +40 -0
  205. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
  206. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
  207. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
  208. package/dist/js/treeshaking/commands/build.js +291 -0
  209. package/dist/js/treeshaking/commands/deploy.js +154 -0
  210. package/dist/js/treeshaking/commands/dev.js +301 -0
  211. package/dist/js/treeshaking/commands/index.js +3 -0
  212. package/dist/js/treeshaking/commands/inspect.js +149 -0
  213. package/dist/js/treeshaking/commands/serve.js +199 -0
  214. package/dist/js/treeshaking/config/default.js +210 -0
  215. package/dist/js/treeshaking/config/index.js +3 -0
  216. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
  217. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
  218. package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
  219. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
  220. package/dist/js/treeshaking/config/initial/index.js +12 -0
  221. package/dist/js/treeshaking/config/initial/inits.js +209 -0
  222. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
  223. package/dist/js/treeshaking/defineConfig.js +61 -0
  224. package/dist/js/treeshaking/exports/server.js +2 -0
  225. package/dist/js/treeshaking/hooks.js +29 -0
  226. package/dist/js/treeshaking/index.js +706 -0
  227. package/dist/js/treeshaking/initialize/index.js +276 -0
  228. package/dist/js/treeshaking/locale/en.js +38 -0
  229. package/dist/js/treeshaking/locale/index.js +9 -0
  230. package/dist/js/treeshaking/locale/zh.js +38 -0
  231. package/dist/js/treeshaking/schema/Schema.js +273 -0
  232. package/dist/js/treeshaking/schema/index.js +181 -0
  233. package/dist/js/treeshaking/schema/legacy.js +337 -0
  234. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  235. package/dist/js/treeshaking/types/config/dev.js +1 -0
  236. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  237. package/dist/js/treeshaking/types/config/html.js +1 -0
  238. package/dist/js/treeshaking/types/config/index.js +1 -0
  239. package/dist/js/treeshaking/types/config/output.js +1 -0
  240. package/dist/js/treeshaking/types/config/performance.js +1 -0
  241. package/dist/js/treeshaking/types/config/security.js +1 -0
  242. package/dist/js/treeshaking/types/config/source.js +1 -0
  243. package/dist/js/treeshaking/types/config/tools.js +1 -0
  244. package/dist/js/treeshaking/types/hooks.js +1 -0
  245. package/dist/js/treeshaking/types/index.js +3 -0
  246. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  247. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  248. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  249. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  250. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  251. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  252. package/dist/js/treeshaking/utils/config.js +302 -0
  253. package/dist/js/treeshaking/utils/createServer.js +258 -0
  254. package/dist/js/treeshaking/utils/env.js +13 -0
  255. package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
  256. package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
  257. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  258. package/dist/js/treeshaking/utils/language.js +6 -0
  259. package/dist/js/treeshaking/utils/printInstructions.js +152 -0
  260. package/dist/js/treeshaking/utils/restart.js +187 -0
  261. package/dist/js/treeshaking/utils/routes.js +153 -0
  262. package/dist/js/treeshaking/utils/types.js +1 -0
  263. package/dist/types/analyze/templates.d.ts +3 -1
  264. package/dist/types/builder/builder-rspack/index.d.ts +2 -1
  265. package/dist/types/types/config/output.d.ts +1 -0
  266. package/package.json +31 -27
@@ -1,6 +1,174 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
1
125
  import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
2
126
  import { generateBuilder } from "../generator";
3
127
  function createRspackBuilderForModern(options) {
4
- return generateBuilder(options, builderRspackProvider);
128
+ return generateBuilder(options, builderRspackProvider, {
129
+ modifyBuilderInstance: function modifyBuilderInstance(builder) {
130
+ return _asyncToGenerator(function() {
131
+ return __generator(this, function(_state) {
132
+ applyBuilderPlugins(builder, options);
133
+ return [
134
+ 2
135
+ ];
136
+ });
137
+ })();
138
+ }
139
+ });
140
+ }
141
+ function applyBuilderPlugins(builder, options) {
142
+ return _applyBuilderPlugins.apply(this, arguments);
143
+ }
144
+ function _applyBuilderPlugins() {
145
+ _applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
146
+ var normalizedConfig, builderPluginNodePolyfill;
147
+ return __generator(this, function(_state) {
148
+ switch(_state.label){
149
+ case 0:
150
+ normalizedConfig = options.normalizedConfig;
151
+ if (!!normalizedConfig.output.disableNodePolyfill) return [
152
+ 3,
153
+ 2
154
+ ];
155
+ return [
156
+ 4,
157
+ import("@modern-js/builder-plugin-node-polyfill")
158
+ ];
159
+ case 1:
160
+ builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
161
+ builder.addPlugins([
162
+ builderPluginNodePolyfill()
163
+ ]);
164
+ _state.label = 2;
165
+ case 2:
166
+ return [
167
+ 2
168
+ ];
169
+ }
170
+ });
171
+ });
172
+ return _applyBuilderPlugins.apply(this, arguments);
5
173
  }
6
174
  export { createRspackBuilderForModern };
@@ -123,26 +123,27 @@ var __generator = this && this.__generator || function(thisArg, body) {
123
123
  }
124
124
  };
125
125
  import { logger } from "@modern-js/utils";
126
+ import { getRspackVersion } from "@modern-js/builder-rspack-provider";
126
127
  function createBuilderGenerator(bundler) {
127
128
  return _createBuilderGenerator.apply(this, arguments);
128
129
  }
129
130
  function _createBuilderGenerator() {
130
131
  _createBuilderGenerator = _asyncToGenerator(function(bundler) {
131
- var createRspackBuilderForModern, _, createWebpackBuilderForModern;
132
+ var createRspackBuilderForModern, version, _, createWebpackBuilderForModern;
132
133
  return __generator(this, function(_state) {
133
134
  switch(_state.label){
134
135
  case 0:
135
136
  if (!(bundler === "rspack")) return [
136
137
  3,
137
- 4
138
+ 5
138
139
  ];
139
140
  _state.label = 1;
140
141
  case 1:
141
142
  _state.trys.push([
142
143
  1,
143
- 3,
144
+ 4,
144
145
  ,
145
- 4
146
+ 5
146
147
  ]);
147
148
  return [
148
149
  4,
@@ -150,20 +151,26 @@ function _createBuilderGenerator() {
150
151
  ];
151
152
  case 2:
152
153
  createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
153
- logger.info("Using Rspack ✨");
154
+ return [
155
+ 4,
156
+ getRspackVersion()
157
+ ];
158
+ case 3:
159
+ version = _state.sent();
160
+ logger.info("Using Rspack v".concat(version, " \uD83E\uDD80"));
154
161
  return [
155
162
  2,
156
163
  createRspackBuilderForModern
157
164
  ];
158
- case 3:
165
+ case 4:
159
166
  _ = _state.sent();
160
167
  throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
161
- case 4:
168
+ case 5:
162
169
  return [
163
170
  4,
164
171
  import("./builder-webpack")
165
172
  ];
166
- case 5:
173
+ case 6:
167
174
  createWebpackBuilderForModern = _state.sent().createWebpackBuilderForModern;
168
175
  return [
169
176
  2,
@@ -123,7 +123,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
123
123
  }
124
124
  };
125
125
  import { mergeBuilderConfig } from "@modern-js/builder-shared";
126
- import { fs } from "@modern-js/utils";
126
+ import { isSSR, fs } from "@modern-js/utils";
127
127
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
128
128
  import { getServerCombinedModueFile } from "../../../analyze/utils";
129
129
  import { isHtmlEnabled } from "./adapterHtml";
@@ -144,12 +144,17 @@ var builderPluginAdapterSSR = function(options) {
144
144
  });
145
145
  api.modifyBundlerChain(function() {
146
146
  var _ref = _asyncToGenerator(function(chain, param) {
147
- var target, CHAIN_ID, isProd, HtmlBundlerPlugin, isServer, builderConfig;
147
+ var target, CHAIN_ID, isProd, HtmlBundlerPlugin, isServer, builderConfig, normalizedConfig2;
148
148
  return __generator(this, function(_state) {
149
149
  switch(_state.label){
150
150
  case 0:
151
151
  target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
152
152
  builderConfig = api.getNormalizedConfig();
153
+ normalizedConfig2 = options.normalizedConfig;
154
+ if (!isSSR(normalizedConfig2)) return [
155
+ 3,
156
+ 2
157
+ ];
153
158
  applyRouterPlugin(chain, options);
154
159
  return [
155
160
  4,
@@ -157,6 +162,8 @@ var builderPluginAdapterSSR = function(options) {
157
162
  ];
158
163
  case 1:
159
164
  _state.sent();
165
+ _state.label = 2;
166
+ case 2:
160
167
  if ([
161
168
  "node",
162
169
  "service-worker"
@@ -164,7 +171,7 @@ var builderPluginAdapterSSR = function(options) {
164
171
  applyFilterEntriesBySSRConfig({
165
172
  isProd: isProd,
166
173
  chain: chain,
167
- appNormalizedConfig: options.normalizedConfig
174
+ appNormalizedConfig: normalizedConfig2
168
175
  });
169
176
  }
170
177
  if (isHtmlEnabled(builderConfig, target)) {
@@ -200,7 +200,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
200
200
  }
201
201
  };
202
202
  import path from "path";
203
- import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from "@modern-js/utils";
203
+ import { fs, logger } from "@modern-js/utils";
204
+ import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
205
+ import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
204
206
  var PLUGIN_NAME = "ModernjsRoutePlugin";
205
207
  var RouterPlugin = /*#__PURE__*/ function() {
206
208
  "use strict";
@@ -240,8 +242,12 @@ var RouterPlugin = /*#__PURE__*/ function() {
240
242
  switch(_state.label){
241
243
  case 0:
242
244
  stats = compilation.getStats().toJson({
245
+ all: false,
246
+ publicPath: true,
247
+ assets: true,
243
248
  chunkGroups: true,
244
- chunks: true
249
+ chunks: true,
250
+ ids: true
245
251
  });
246
252
  publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks;
247
253
  routeAssets = {};
@@ -282,7 +288,12 @@ var RouterPlugin = /*#__PURE__*/ function() {
282
288
  manifest = {
283
289
  routeAssets: routeAssets
284
290
  };
285
- injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest), ";\n })();\n ");
291
+ injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest, function(k, v) {
292
+ if (k === "assets") {
293
+ return void 0;
294
+ }
295
+ return v;
296
+ }), ";\n })();\n ");
286
297
  entrypointsArray = Array.from(compilation.entrypoints.entries());
287
298
  entryChunkIds = entrypointsArray.map(function(entrypoint) {
288
299
  return entrypoint[0];
@@ -325,7 +336,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
325
336
  }
326
337
  }
327
338
  }
328
- filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
339
+ filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
329
340
  return [
330
341
  4,
331
342
  fs.ensureFile(filename)
@@ -27,6 +27,58 @@ function _asyncToGenerator(fn) {
27
27
  });
28
28
  };
29
29
  }
30
+ function _defineProperty(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _objectSpread(target) {
44
+ for(var i = 1; i < arguments.length; i++){
45
+ var source = arguments[i] != null ? arguments[i] : {};
46
+ var ownKeys = Object.keys(source);
47
+ if (typeof Object.getOwnPropertySymbols === "function") {
48
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
+ }));
51
+ }
52
+ ownKeys.forEach(function(key) {
53
+ _defineProperty(target, key, source[key]);
54
+ });
55
+ }
56
+ return target;
57
+ }
58
+ function ownKeys(object, enumerableOnly) {
59
+ var keys = Object.keys(object);
60
+ if (Object.getOwnPropertySymbols) {
61
+ var symbols = Object.getOwnPropertySymbols(object);
62
+ if (enumerableOnly) {
63
+ symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ });
66
+ }
67
+ keys.push.apply(keys, symbols);
68
+ }
69
+ return keys;
70
+ }
71
+ function _objectSpreadProps(target, source) {
72
+ source = source != null ? source : {};
73
+ if (Object.getOwnPropertyDescriptors) {
74
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
+ } else {
76
+ ownKeys(Object(source)).forEach(function(key) {
77
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
+ });
79
+ }
80
+ return target;
81
+ }
30
82
  var __generator = this && this.__generator || function(thisArg, body) {
31
83
  var f, y, t, g, _ = {
32
84
  label: 0,
@@ -129,7 +181,7 @@ import { injectDataLoaderPlugin } from "../utils/createServer";
129
181
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
130
182
  var start = function() {
131
183
  var _ref = _asyncToGenerator(function(api) {
132
- var _userConfig_source, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
184
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
133
185
  return __generator(this, function(_state) {
134
186
  switch(_state.label){
135
187
  case 0:
@@ -154,7 +206,12 @@ var start = function() {
154
206
  4,
155
207
  server({
156
208
  pwd: appDirectory,
157
- config: userConfig,
209
+ config: _objectSpreadProps(_objectSpread({}, userConfig), {
210
+ dev: userConfig.dev,
211
+ output: _objectSpread({
212
+ path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
213
+ }, userConfig.output || {})
214
+ }),
158
215
  appContext: {
159
216
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
160
217
  apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
@@ -81,6 +81,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
81
81
  const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
82
82
  await Promise.all(entrypoints.map(generateEntryCode));
83
83
  async function generateEntryCode(entrypoint) {
84
+ var _a;
84
85
  const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
85
86
  if (isAutoMount) {
86
87
  if (fileSystemRoutes) {
@@ -143,7 +144,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
143
144
  ssrMode: useSSG ? "string" : mode,
144
145
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
145
146
  entryName: entrypoint.entryName,
146
- internalDirectory
147
+ internalDirectory,
148
+ splitRouteChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRouteChunks
147
149
  })
148
150
  });
149
151
  if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
@@ -227,6 +227,14 @@ var analyze_default = ({
227
227
  imports
228
228
  };
229
229
  },
230
+ validateSchema() {
231
+ return {
232
+ target: "output.splitRouteChunks",
233
+ schema: {
234
+ type: "boolean"
235
+ }
236
+ };
237
+ },
230
238
  async fileChange(e) {
231
239
  const appContext = api.useAppContext();
232
240
  const { appDirectory } = appContext;
@@ -139,13 +139,16 @@ const routesForServer = ({
139
139
  ${routesCode}
140
140
  `;
141
141
  };
142
+ const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^,]+)"`, "g");
142
143
  const fileSystemRoutes = async ({
143
144
  routes,
144
145
  ssrMode,
145
146
  nestedRoutesEntry,
146
147
  entryName,
147
- internalDirectory
148
+ internalDirectory,
149
+ splitRouteChunks = true
148
150
  }) => {
151
+ const components = [];
149
152
  const loadings = [];
150
153
  const errors = [];
151
154
  const loaders = [];
@@ -204,20 +207,30 @@ const fileSystemRoutes = async ({
204
207
  };
205
208
  }
206
209
  if (route._component) {
207
- if (route.isRoot) {
208
- rootLayoutCode = `import RootLayout from '${route._component}'`;
209
- component = `RootLayout`;
210
- } else if (ssrMode === "string") {
211
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
212
- component = `loadable(${lazyImport})`;
210
+ if (splitRouteChunks) {
211
+ if (route.isRoot) {
212
+ rootLayoutCode = `import RootLayout from '${route._component}'`;
213
+ component = `RootLayout`;
214
+ } else if (ssrMode === "string") {
215
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
216
+ component = `loadable(${lazyImport})`;
217
+ } else {
218
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
219
+ component = `lazy(${lazyImport})`;
220
+ }
213
221
  } else {
214
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
215
- component = `lazy(${lazyImport})`;
222
+ components.push(route._component);
223
+ component = `component_${components.length - 1}`;
216
224
  }
217
225
  }
218
226
  } else if (route._component) {
219
- lazyImport = `() => import('${route._component}')`;
220
- component = `loadable(${lazyImport})`;
227
+ if (splitRouteChunks) {
228
+ lazyImport = `() => import('${route._component}')`;
229
+ component = `loadable(${lazyImport})`;
230
+ } else {
231
+ components.push(route._component);
232
+ component = `component_${components.length - 1}`;
233
+ }
221
234
  }
222
235
  const finalRoute = {
223
236
  ...route,
@@ -238,20 +251,38 @@ const fileSystemRoutes = async ({
238
251
  for (const route of routes) {
239
252
  if ("type" in route) {
240
253
  const newRoute = traverseRouteTree(route);
241
- routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"]+)"/g, "$1").replace(/"(loader_[^"]+)"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"]+)"/g, "$1").replace(/\\"/g, '"')},`;
254
+ const routeStr = JSON.stringify(newRoute, null, 2);
255
+ const keywords = [
256
+ "component",
257
+ "lazyImport",
258
+ "loader",
259
+ "loading",
260
+ "error"
261
+ ];
262
+ const regs = keywords.map(createMatchReg);
263
+ const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
264
+ routeComponentsCode += `${newRouteStr},`;
242
265
  } else {
243
266
  const component = `loadable(() => import('${route._component}'))`;
244
267
  const finalRoute = {
245
268
  ...route,
246
269
  component
247
270
  };
248
- routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
271
+ const keywords = ["component", "lazyImport"];
272
+ const routeStr = JSON.stringify(finalRoute, null, 2);
273
+ const regs = keywords.map(createMatchReg);
274
+ const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/\\"/g, '"');
275
+ routeComponentsCode += `${newRouteStr},`;
249
276
  }
250
277
  }
251
278
  routeComponentsCode += `
252
279
  ];`;
253
280
  const importLoadingCode = loadings.map((loading, index2) => {
254
281
  return `import loading_${index2} from '${loading}';
282
+ `;
283
+ }).join("");
284
+ const importComponentsCode = components.map((component, index2) => {
285
+ return `import component_${index2} from '${component}';
255
286
  `;
256
287
  }).join("");
257
288
  const importErrorComponentsCode = errors.map((error, index2) => {
@@ -276,6 +307,7 @@ const fileSystemRoutes = async ({
276
307
  await fs.writeJSON(loadersMapFile, loadersMap);
277
308
  return `
278
309
  ${importLazyCode}
310
+ ${importComponentsCode}
279
311
  ${rootLayoutCode}
280
312
  ${importLoadingCode}
281
313
  ${importErrorComponentsCode}
@@ -1,7 +1,18 @@
1
1
  import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
2
2
  import { generateBuilder } from "../generator";
3
3
  function createRspackBuilderForModern(options) {
4
- return generateBuilder(options, builderRspackProvider);
4
+ return generateBuilder(options, builderRspackProvider, {
5
+ async modifyBuilderInstance(builder) {
6
+ applyBuilderPlugins(builder, options);
7
+ }
8
+ });
9
+ }
10
+ async function applyBuilderPlugins(builder, options) {
11
+ const { normalizedConfig } = options;
12
+ if (!normalizedConfig.output.disableNodePolyfill) {
13
+ const { builderPluginNodePolyfill } = await import("@modern-js/builder-plugin-node-polyfill");
14
+ builder.addPlugins([builderPluginNodePolyfill()]);
15
+ }
5
16
  }
6
17
  export {
7
18
  createRspackBuilderForModern
@@ -1,9 +1,11 @@
1
1
  import { logger } from "@modern-js/utils";
2
+ import { getRspackVersion } from "@modern-js/builder-rspack-provider";
2
3
  async function createBuilderGenerator(bundler) {
3
4
  if (bundler === "rspack") {
4
5
  try {
5
6
  const { createRspackBuilderForModern } = await import("./builder-rspack");
6
- logger.info("Using Rspack ✨");
7
+ const version = await getRspackVersion();
8
+ logger.info(`Using Rspack v${version} 🦀`);
7
9
  return createRspackBuilderForModern;
8
10
  } catch (_) {
9
11
  throw new Error(
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mergeBuilderConfig
3
3
  } from "@modern-js/builder-shared";
4
- import { fs } from "@modern-js/utils";
4
+ import { isSSR, fs } from "@modern-js/utils";
5
5
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
6
6
  import { getServerCombinedModueFile } from "../../../analyze/utils";
7
7
  import { isHtmlEnabled } from "./adapterHtml";
@@ -22,13 +22,16 @@ const builderPluginAdapterSSR = (options) => ({
22
22
  api.modifyBundlerChain(
23
23
  async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
24
24
  const builderConfig = api.getNormalizedConfig();
25
- applyRouterPlugin(chain, options);
26
- await applySSRLoaderEntry(chain, options, isServer);
25
+ const { normalizedConfig: normalizedConfig2 } = options;
26
+ if (isSSR(normalizedConfig2)) {
27
+ applyRouterPlugin(chain, options);
28
+ await applySSRLoaderEntry(chain, options, isServer);
29
+ }
27
30
  if (["node", "service-worker"].includes(target)) {
28
31
  applyFilterEntriesBySSRConfig({
29
32
  isProd,
30
33
  chain,
31
- appNormalizedConfig: options.normalizedConfig
34
+ appNormalizedConfig: normalizedConfig2
32
35
  });
33
36
  }
34
37
  if (isHtmlEnabled(builderConfig, target)) {
@@ -1,10 +1,7 @@
1
1
  import path from "path";
2
- import {
3
- fs,
4
- ROUTE_MANIFEST,
5
- logger,
6
- ROUTE_MINIFEST_FILE
7
- } from "@modern-js/utils";
2
+ import { fs, logger } from "@modern-js/utils";
3
+ import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
4
+ import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
8
5
  const PLUGIN_NAME = "ModernjsRoutePlugin";
9
6
  class RouterPlugin {
10
7
  apply(compiler) {
@@ -35,8 +32,12 @@ class RouterPlugin {
35
32
  },
36
33
  async () => {
37
34
  const stats = compilation.getStats().toJson({
35
+ all: false,
36
+ publicPath: true,
37
+ assets: true,
38
38
  chunkGroups: true,
39
- chunks: true
39
+ chunks: true,
40
+ ids: true
40
41
  });
41
42
  const { publicPath, chunks = [] } = stats;
42
43
  const routeAssets = {};
@@ -62,7 +63,12 @@ class RouterPlugin {
62
63
  };
63
64
  const injectedContent = `
64
65
  ;(function(){
65
- window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest)};
66
+ window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
67
+ if (k === "assets") {
68
+ return void 0;
69
+ }
70
+ return v;
71
+ })};
66
72
  })();
67
73
  `;
68
74
  const entrypointsArray = Array.from(
@@ -92,7 +98,7 @@ class RouterPlugin {
92
98
  void 0
93
99
  );
94
100
  }
95
- const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
101
+ const filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
96
102
  await fs.ensureFile(filename);
97
103
  await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
98
104
  }