@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.2

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 (279) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/dist/js/modern/analyze/generateCode.js +30 -38
  3. package/dist/js/modern/analyze/getBundleEntry.js +5 -13
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
  6. package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
  8. package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
  9. package/dist/js/modern/analyze/getServerRoutes.js +25 -38
  10. package/dist/js/modern/analyze/index.js +90 -48
  11. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  12. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  13. package/dist/js/modern/analyze/nestedRoutes.js +8 -33
  14. package/dist/js/modern/analyze/templates.js +22 -37
  15. package/dist/js/modern/analyze/utils.js +0 -7
  16. package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
  17. package/dist/js/modern/builder/index.js +56 -37
  18. package/dist/js/modern/builder/share.js +1 -5
  19. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
  20. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
  21. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  22. package/dist/js/modern/commands/build.js +12 -46
  23. package/dist/js/modern/commands/dev.js +20 -23
  24. package/dist/js/modern/commands/inspect.js +4 -19
  25. package/dist/js/modern/commands/start.js +1 -2
  26. package/dist/js/modern/config/default.js +207 -0
  27. package/dist/js/modern/config/index.js +2 -0
  28. package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
  29. package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +19 -18
  30. package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
  31. package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
  32. package/dist/js/modern/config/initial/index.js +11 -0
  33. package/dist/js/modern/config/initial/inits.js +117 -0
  34. package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
  35. package/dist/js/modern/defineConfig.js +12 -0
  36. package/dist/js/modern/hooks.js +23 -19
  37. package/dist/js/modern/index.js +12 -19
  38. package/dist/js/modern/initialize/index.js +72 -0
  39. package/dist/js/modern/schema/Schema.js +39 -0
  40. package/dist/js/modern/schema/index.js +139 -0
  41. package/dist/js/modern/schema/legacy.js +284 -0
  42. package/dist/js/modern/types/config/deploy.js +0 -0
  43. package/dist/js/modern/types/config/dev.js +0 -0
  44. package/dist/js/modern/types/config/experiments.js +0 -0
  45. package/dist/js/modern/types/config/html.js +0 -0
  46. package/dist/js/modern/types/config/index.js +2 -0
  47. package/dist/js/modern/types/config/output.js +0 -0
  48. package/dist/js/modern/types/config/performance.js +0 -0
  49. package/dist/js/modern/types/config/security.js +0 -0
  50. package/dist/js/modern/types/config/source.js +0 -0
  51. package/dist/js/modern/types/config/tools.js +0 -0
  52. package/dist/js/modern/types/hooks.js +0 -0
  53. package/dist/js/modern/types/index.js +4 -0
  54. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  55. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  56. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  57. package/dist/js/modern/types/legacyConfig/output.js +1 -0
  58. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  59. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  60. package/dist/js/modern/utils/config.js +2 -13
  61. package/dist/js/modern/utils/createFileWatcher.js +82 -0
  62. package/dist/js/modern/utils/createServer.js +0 -5
  63. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  64. package/dist/js/modern/utils/printInstructions.js +2 -1
  65. package/dist/js/modern/utils/restart.js +17 -0
  66. package/dist/js/modern/utils/routes.js +0 -2
  67. package/dist/js/node/analyze/generateCode.js +30 -61
  68. package/dist/js/node/analyze/getBundleEntry.js +5 -19
  69. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
  70. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
  71. package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
  72. package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
  73. package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
  74. package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
  75. package/dist/js/node/analyze/getServerRoutes.js +24 -46
  76. package/dist/js/node/analyze/index.js +91 -70
  77. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  78. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  79. package/dist/js/node/analyze/nestedRoutes.js +8 -41
  80. package/dist/js/node/analyze/templates.js +22 -47
  81. package/dist/js/node/analyze/utils.js +0 -20
  82. package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
  83. package/dist/js/node/builder/index.js +57 -51
  84. package/dist/js/node/builder/share.js +1 -13
  85. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
  86. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
  87. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  88. package/dist/js/node/commands/build.js +10 -57
  89. package/dist/js/node/commands/deploy.js +0 -2
  90. package/dist/js/node/commands/dev.js +19 -34
  91. package/dist/js/node/commands/index.js +0 -6
  92. package/dist/js/node/commands/inspect.js +4 -26
  93. package/dist/js/node/commands/start.js +1 -11
  94. package/dist/js/node/config/default.js +214 -0
  95. package/dist/js/node/config/index.js +31 -0
  96. package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
  97. package/dist/js/node/{builder → config/initial}/createOutputConfig.js +19 -20
  98. package/dist/js/node/config/initial/createSourceConfig.js +38 -0
  99. package/dist/js/node/config/initial/createToolsConfig.js +47 -0
  100. package/dist/js/node/config/initial/index.js +24 -0
  101. package/dist/js/node/config/initial/inits.js +127 -0
  102. package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
  103. package/dist/js/node/defineConfig.js +20 -0
  104. package/dist/js/node/exports/server.js +0 -1
  105. package/dist/js/node/hooks.js +23 -30
  106. package/dist/js/node/index.js +35 -48
  107. package/dist/js/node/initialize/index.js +79 -0
  108. package/dist/js/node/locale/index.js +0 -4
  109. package/dist/js/node/schema/Schema.js +46 -0
  110. package/dist/js/node/schema/index.js +152 -0
  111. package/dist/js/node/schema/legacy.js +291 -0
  112. package/dist/js/node/types/config/deploy.js +0 -0
  113. package/dist/js/node/types/config/dev.js +0 -0
  114. package/dist/js/node/types/config/experiments.js +0 -0
  115. package/dist/js/node/types/config/html.js +0 -0
  116. package/dist/js/node/types/config/index.js +16 -0
  117. package/dist/js/node/types/config/output.js +0 -0
  118. package/dist/js/node/types/config/performance.js +0 -0
  119. package/dist/js/node/types/config/security.js +0 -0
  120. package/dist/js/node/types/config/source.js +0 -0
  121. package/dist/js/node/types/config/tools.js +0 -0
  122. package/dist/js/node/types/hooks.js +0 -0
  123. package/dist/js/node/types/index.js +38 -0
  124. package/dist/js/node/types/legacyConfig/deploy.js +0 -0
  125. package/dist/js/node/types/legacyConfig/dev.js +0 -0
  126. package/dist/js/node/types/legacyConfig/index.js +0 -0
  127. package/dist/js/node/types/legacyConfig/output.js +5 -0
  128. package/dist/js/node/types/legacyConfig/source.js +0 -0
  129. package/dist/js/node/types/legacyConfig/tools.js +0 -0
  130. package/dist/js/node/utils/commands.js +0 -2
  131. package/dist/js/node/utils/config.js +2 -26
  132. package/dist/js/node/utils/createFileWatcher.js +90 -0
  133. package/dist/js/node/utils/createServer.js +0 -15
  134. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  135. package/dist/js/node/utils/language.js +0 -2
  136. package/dist/js/node/utils/printInstructions.js +2 -5
  137. package/dist/js/node/utils/restart.js +23 -0
  138. package/dist/js/node/utils/routes.js +0 -5
  139. package/dist/js/treeshaking/analyze/generateCode.js +58 -101
  140. package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
  141. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
  142. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
  143. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
  144. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
  145. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
  146. package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
  147. package/dist/js/treeshaking/analyze/index.js +195 -91
  148. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
  149. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
  150. package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
  151. package/dist/js/treeshaking/analyze/templates.js +31 -50
  152. package/dist/js/treeshaking/analyze/utils.js +7 -14
  153. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
  154. package/dist/js/treeshaking/builder/index.js +69 -65
  155. package/dist/js/treeshaking/builder/share.js +1 -5
  156. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
  157. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
  158. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  159. package/dist/js/treeshaking/commands/build.js +41 -116
  160. package/dist/js/treeshaking/commands/deploy.js +0 -3
  161. package/dist/js/treeshaking/commands/dev.js +38 -46
  162. package/dist/js/treeshaking/commands/inspect.js +9 -27
  163. package/dist/js/treeshaking/commands/start.js +1 -9
  164. package/dist/js/treeshaking/config/default.js +200 -0
  165. package/dist/js/treeshaking/config/index.js +2 -0
  166. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
  167. package/dist/js/treeshaking/config/initial/createOutputConfig.js +67 -0
  168. package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
  169. package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
  170. package/dist/js/treeshaking/config/initial/index.js +11 -0
  171. package/dist/js/treeshaking/config/initial/inits.js +114 -0
  172. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
  173. package/dist/js/treeshaking/defineConfig.js +14 -0
  174. package/dist/js/treeshaking/hooks.js +23 -19
  175. package/dist/js/treeshaking/index.js +8 -43
  176. package/dist/js/treeshaking/initialize/index.js +121 -0
  177. package/dist/js/treeshaking/schema/Schema.js +75 -0
  178. package/dist/js/treeshaking/schema/index.js +138 -0
  179. package/dist/js/treeshaking/schema/legacy.js +273 -0
  180. package/dist/js/treeshaking/types/config/deploy.js +0 -0
  181. package/dist/js/treeshaking/types/config/dev.js +0 -0
  182. package/dist/js/treeshaking/types/config/experiments.js +0 -0
  183. package/dist/js/treeshaking/types/config/html.js +0 -0
  184. package/dist/js/treeshaking/types/config/index.js +2 -0
  185. package/dist/js/treeshaking/types/config/output.js +0 -0
  186. package/dist/js/treeshaking/types/config/performance.js +0 -0
  187. package/dist/js/treeshaking/types/config/security.js +0 -0
  188. package/dist/js/treeshaking/types/config/source.js +0 -0
  189. package/dist/js/treeshaking/types/config/tools.js +0 -0
  190. package/dist/js/treeshaking/types/hooks.js +0 -0
  191. package/dist/js/treeshaking/types/index.js +4 -0
  192. package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
  193. package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
  194. package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
  195. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  196. package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
  197. package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
  198. package/dist/js/treeshaking/utils/config.js +2 -18
  199. package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
  200. package/dist/js/treeshaking/utils/createServer.js +0 -10
  201. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
  202. package/dist/js/treeshaking/utils/printInstructions.js +0 -5
  203. package/dist/js/treeshaking/utils/restart.js +45 -0
  204. package/dist/js/treeshaking/utils/routes.js +0 -4
  205. package/dist/types/analyze/generateCode.d.ts +3 -2
  206. package/dist/types/analyze/getBundleEntry.d.ts +2 -2
  207. package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
  208. package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
  209. package/dist/types/analyze/getServerRoutes.d.ts +3 -2
  210. package/dist/types/analyze/index.d.ts +3 -42
  211. package/dist/types/analyze/nestedRoutes.d.ts +1 -1
  212. package/dist/types/analyze/templates.d.ts +4 -2
  213. package/dist/types/analyze/utils.d.ts +1 -1
  214. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
  215. package/dist/types/builder/index.d.ts +7 -8
  216. package/dist/types/builder/share.d.ts +2 -2
  217. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  218. package/dist/types/commands/build.d.ts +2 -2
  219. package/dist/types/commands/deploy.d.ts +2 -2
  220. package/dist/types/commands/dev.d.ts +2 -2
  221. package/dist/types/commands/inspect.d.ts +6 -1
  222. package/dist/types/commands/start.d.ts +2 -2
  223. package/dist/types/config/default.d.ts +3 -0
  224. package/dist/types/config/index.d.ts +2 -0
  225. package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
  226. package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
  227. package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
  228. package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
  229. package/dist/types/config/initial/index.d.ts +4 -0
  230. package/dist/types/config/initial/inits.d.ts +4 -0
  231. package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
  232. package/dist/types/defineConfig.d.ts +7 -0
  233. package/dist/types/hooks.d.ts +2 -42
  234. package/dist/types/index.d.ts +5 -7
  235. package/dist/types/initialize/index.d.ts +3 -0
  236. package/dist/types/schema/Schema.d.ts +14 -0
  237. package/dist/types/schema/index.d.ts +4 -0
  238. package/dist/types/schema/legacy.d.ts +3 -0
  239. package/dist/types/types/config/deploy.d.ts +9 -0
  240. package/dist/types/types/config/dev.d.ts +13 -0
  241. package/dist/types/types/config/experiments.d.ts +4 -0
  242. package/dist/types/types/config/html.d.ts +4 -0
  243. package/dist/types/types/config/index.d.ts +62 -0
  244. package/dist/types/types/config/output.d.ts +23 -0
  245. package/dist/types/types/config/performance.d.ts +4 -0
  246. package/dist/types/types/config/security.d.ts +4 -0
  247. package/dist/types/types/config/source.d.ts +22 -0
  248. package/dist/types/types/config/tools.d.ts +15 -0
  249. package/dist/types/types/hooks.d.ts +80 -0
  250. package/dist/types/types/index.d.ts +23 -0
  251. package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
  252. package/dist/types/types/legacyConfig/dev.d.ts +12 -0
  253. package/dist/types/types/legacyConfig/index.d.ts +33 -0
  254. package/dist/types/types/legacyConfig/output.d.ts +51 -0
  255. package/dist/types/types/legacyConfig/source.d.ts +25 -0
  256. package/dist/types/types/legacyConfig/tools.d.ts +16 -0
  257. package/dist/types/utils/config.d.ts +2 -3
  258. package/dist/types/utils/createFileWatcher.d.ts +3 -0
  259. package/dist/types/utils/printInstructions.d.ts +3 -3
  260. package/dist/types/utils/restart.d.ts +3 -0
  261. package/package.json +26 -25
  262. package/dist/js/modern/builder/createHtmlConfig.js +0 -58
  263. package/dist/js/modern/builder/createSourceConfig.js +0 -85
  264. package/dist/js/modern/builder/createToolsConfig.js +0 -94
  265. package/dist/js/modern/utils/createCompiler.js +0 -58
  266. package/dist/js/node/builder/createHtmlConfig.js +0 -76
  267. package/dist/js/node/builder/createSourceConfig.js +0 -99
  268. package/dist/js/node/builder/createToolsConfig.js +0 -103
  269. package/dist/js/node/utils/createCompiler.js +0 -75
  270. package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
  271. package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
  272. package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
  273. package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
  274. package/dist/js/treeshaking/utils/createCompiler.js +0 -117
  275. package/dist/types/builder/createHtmlConfig.d.ts +0 -6
  276. package/dist/types/builder/createOutputConfig.d.ts +0 -3
  277. package/dist/types/builder/createSourceConfig.d.ts +0 -5
  278. package/dist/types/builder/createToolsConfig.d.ts +0 -13
  279. package/dist/types/utils/createCompiler.d.ts +0 -12
@@ -1,9 +1,6 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
4
  import { join } from 'path';
8
5
  import { mergeBuilderConfig } from '@modern-js/builder-shared';
9
6
  import { template as lodashTemplate } from '@modern-js/utils/lodash';
@@ -12,13 +9,12 @@ import { getEntryOptions } from '@modern-js/utils';
12
9
  import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
13
10
  import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
14
11
  import { createCopyPattern } from "../share";
15
-
12
+ import RouterPlugin from "../webpackPlugins/routerPlugin";
16
13
  /**
17
14
  * Provides default configuration consistent with `@modern-js/webpack`
18
15
  */
19
16
  export const PluginCompatModern = (appContext, modernConfig, options) => ({
20
17
  name: 'builder-plugin-compat-modern',
21
-
22
18
  setup(api) {
23
19
  api.modifyBuilderConfig(config => {
24
20
  if (isStreamingSSR(modernConfig)) {
@@ -28,7 +24,6 @@ export const PluginCompatModern = (appContext, modernConfig, options) => ({
28
24
  }
29
25
  });
30
26
  }
31
-
32
27
  return config;
33
28
  });
34
29
  api.modifyWebpackChain((chain, {
@@ -36,8 +31,8 @@ export const PluginCompatModern = (appContext, modernConfig, options) => ({
36
31
  CHAIN_ID,
37
32
  isProd
38
33
  }) => {
39
- const builderNormalizedConfig = api.getNormalizedConfig(); // set webpack config name
40
-
34
+ const builderNormalizedConfig = api.getNormalizedConfig();
35
+ // set webpack config name
41
36
  if (target === 'node') {
42
37
  chain.name('server');
43
38
  } else if (target === 'modern-web') {
@@ -45,13 +40,12 @@ export const PluginCompatModern = (appContext, modernConfig, options) => ({
45
40
  } else {
46
41
  chain.name('client');
47
42
  }
43
+ chain.resolve.modules.add('node_modules').add(join(api.context.rootPath, 'node_modules'));
48
44
 
49
- chain.resolve.modules.add('node_modules').add(join(api.context.rootPath, 'node_modules')); // apply node compat
50
-
45
+ // apply node compat
51
46
  if (target === 'node') {
52
47
  applyNodeCompat(chain, modernConfig, isProd);
53
48
  }
54
-
55
49
  if (isHtmlEnabled(builderNormalizedConfig, target)) {
56
50
  applyBottomHtmlWebpackPlugin({
57
51
  api,
@@ -65,36 +59,39 @@ export const PluginCompatModern = (appContext, modernConfig, options) => ({
65
59
  CHAIN_ID,
66
60
  modernConfig
67
61
  });
68
- } // apply copy plugin
69
- // const copyPatterns = createCopyPatterns(chain, appContext, modernConfig);
70
-
71
-
72
- const defaultCopyPattern = createCopyPattern(appContext, modernConfig, 'public', chain);
73
- chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(args => {
74
- var _args$;
75
-
76
- return [{
77
- patterns: [...(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), defaultCopyPattern]
78
- }];
79
- });
62
+ }
80
63
 
64
+ // apply copy plugin
65
+ if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
66
+ const defaultCopyPattern = createCopyPattern(appContext, modernConfig, 'public', chain);
67
+ chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(args => {
68
+ var _args$;
69
+ return [{
70
+ patterns: [...(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), defaultCopyPattern]
71
+ }];
72
+ });
73
+ }
74
+ const {
75
+ entrypoints
76
+ } = appContext;
77
+ const existNestedRoutes = entrypoints.some(entrypoint => entrypoint.nestedRoutesEntry);
78
+ chain.plugin('route-plugin').use(RouterPlugin, [{
79
+ existNestedRoutes
80
+ }]);
81
81
  function isHtmlEnabled(config, target) {
82
82
  var _config$tools;
83
-
84
83
  return ((_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.htmlPlugin) !== false && target !== 'node' && target !== 'web-worker';
85
84
  }
86
85
  });
87
-
88
86
  if (options) {
89
87
  applyCallbacks(api, options);
90
88
  }
91
89
  }
92
-
93
90
  });
91
+
94
92
  /**
95
93
  * register builder hooks callback
96
94
  */
97
-
98
95
  function applyCallbacks(api, options) {
99
96
  options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
100
97
  options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
@@ -105,40 +102,35 @@ function applyCallbacks(api, options) {
105
102
  options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
106
103
  options.onExit && api.onExit(options.onExit);
107
104
  }
105
+
108
106
  /**
109
107
  * compat some config, if target is `node`
110
108
  */
111
-
112
-
113
109
  function applyNodeCompat(chain, modernConfig, isProd) {
114
110
  // apply node resolve extensions
115
111
  for (const ext of ['.node.js', '.node.jsx', '.node.ts', '.node.tsx']) {
116
112
  chain.resolve.extensions.prepend(ext);
117
- } // apply filterEntriesBySSRConfig
118
-
113
+ }
119
114
 
115
+ // apply filterEntriesBySSRConfig
120
116
  filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
121
-
122
117
  function filterEntriesBySSRConfig(isProd, chain, serverConfig, outputConfig) {
123
118
  var _outputConfig$ssg;
124
-
125
- const entries = chain.entryPoints.entries(); // if prod and ssg config is true or function
126
-
119
+ const entries = chain.entryPoints.entries();
120
+ // if prod and ssg config is true or function
127
121
  if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (_outputConfig$ssg = outputConfig.ssg) === null || _outputConfig$ssg === void 0 ? void 0 : _outputConfig$ssg[0]) === 'function')) {
128
122
  return;
129
- } // if single entry has ssg config
130
- // `ssg: {}` is not allowed if multi entry
131
-
123
+ }
132
124
 
125
+ // if single entry has ssg config
126
+ // `ssg: {}` is not allowed if multi entry
133
127
  const entryNames = Object.keys(entries);
134
-
135
128
  if (isProd && entryNames.length === 1 && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
136
129
  return;
137
- } // collect all ssg entries
138
-
130
+ }
139
131
 
132
+ // collect all ssg entries
140
133
  const ssgEntries = [];
141
-
142
134
  if (isProd && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
143
135
  const {
144
136
  ssg
@@ -149,7 +141,6 @@ function applyNodeCompat(chain, modernConfig, isProd) {
149
141
  }
150
142
  });
151
143
  }
152
-
153
144
  const {
154
145
  ssr,
155
146
  ssrByEntries
@@ -161,11 +152,10 @@ function applyNodeCompat(chain, modernConfig, isProd) {
161
152
  });
162
153
  }
163
154
  }
155
+
164
156
  /**
165
157
  * inject bottom template
166
158
  */
167
-
168
-
169
159
  function applyBottomHtmlWebpackPlugin({
170
160
  api,
171
161
  chain,
@@ -178,32 +168,27 @@ function applyBottomHtmlWebpackPlugin({
178
168
  // FIXME: the only need necessary
179
169
  const baseTemplateParams = _objectSpread({
180
170
  entryName,
181
- title: getEntryOptions(entryName, modernConfig.output.title, modernConfig.output.titleByEntries, appContext.packageName),
182
- mountId: modernConfig.output.mountId
183
- }, getEntryOptions(entryName, modernConfig.output.templateParameters, modernConfig.output.templateParametersByEntries, appContext.packageName));
184
-
171
+ title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
172
+ mountId: modernConfig.html.mountId
173
+ }, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
185
174
  chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap(args => [_objectSpread(_objectSpread({}, args[0] || {}), {}, {
186
175
  __internal__: true,
187
176
  bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(baseTemplateParams)
188
177
  })]);
189
178
  }
190
-
191
179
  chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
192
180
  }
193
-
194
181
  const isStreamingSSR = userConfig => {
195
182
  const isStreaming = ssr => ssr && typeof ssr === 'object' && ssr.mode === 'stream';
196
-
197
183
  const {
198
184
  server
199
185
  } = userConfig;
200
-
201
186
  if (isStreaming(server.ssr)) {
202
187
  return true;
203
- } // Since we cannot apply different plugins for different entries,
204
- // we regard the whole app as streaming ssr only if one entry meets the requirement.
205
-
188
+ }
206
189
 
190
+ // Since we cannot apply different plugins for different entries,
191
+ // we regard the whole app as streaming ssr only if one entry meets the requirement.
207
192
  if (server !== null && server !== void 0 && server.ssrByEntries && typeof server.ssrByEntries === 'object') {
208
193
  for (const name of Object.keys(server.ssrByEntries)) {
209
194
  if (isStreaming(server.ssrByEntries[name])) {
@@ -211,10 +196,8 @@ const isStreamingSSR = userConfig => {
211
196
  }
212
197
  }
213
198
  }
214
-
215
199
  return false;
216
200
  };
217
-
218
201
  function applyAsyncChunkHtmlPlugin({
219
202
  chain,
220
203
  modernConfig,
@@ -1,59 +1,82 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1
4
  import { createBuilder } from '@modern-js/builder';
2
5
  import { builderWebpackProvider } from '@modern-js/builder-webpack-provider';
3
- import { applyOptionsChain } from '@modern-js/utils';
6
+ import { applyOptionsChain, isUseSSRBundle } from '@modern-js/utils';
4
7
  import { PluginCompatModern } from "./builderPlugins/compatModern";
5
- import { createHtmlConfig } from "./createHtmlConfig";
6
- import { createOutputConfig } from "./createOutputConfig";
7
- import { createSourceConfig } from "./createSourceConfig";
8
- import { createToolsConfig } from "./createToolsConfig";
9
- export default (async ({
10
- target: _target = 'web',
11
- normalizedConfig,
12
- appContext,
13
- compatPluginConfig
14
- }) => {
15
- const targets = Array.isArray(_target) ? _target : [_target];
16
-
8
+ import { createCopyPattern } from "./share";
9
+ function getBuilderTargets(normalizedConfig) {
10
+ const targets = ['web'];
17
11
  if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
18
12
  targets.push('modern-web');
19
13
  }
20
-
21
- const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext); // create webpack provider
22
-
14
+ if (isUseSSRBundle(normalizedConfig)) {
15
+ targets.push('node');
16
+ }
17
+ return targets;
18
+ }
19
+ export async function createBuilderForEdenX({
20
+ normalizedConfig,
21
+ appContext,
22
+ compatPluginConfig
23
+ }) {
24
+ // create webpack provider
25
+ const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
23
26
  const webpackProvider = builderWebpackProvider({
24
27
  builderConfig
25
28
  });
26
- const builderOptions = createBuilderOptions(_target, appContext);
29
+ const target = getBuilderTargets(normalizedConfig);
30
+ const builderOptions = createBuilderOptions(target, appContext);
27
31
  const builder = await createBuilder(webpackProvider, builderOptions);
28
32
  await applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig);
29
33
  return builder;
30
- });
31
-
32
- function createBuilderProviderConfig(normalizedConfig, appContext) {
33
- const source = createSourceConfig(normalizedConfig, appContext);
34
- const html = createHtmlConfig(normalizedConfig, appContext);
34
+ }
35
+ export function createBuilderProviderConfig(normalizedConfig, appContext) {
35
36
  const output = createOutputConfig(normalizedConfig, appContext);
36
- const tools = createToolsConfig(normalizedConfig);
37
- return {
38
- source,
39
- html,
37
+ return _objectSpread(_objectSpread({}, normalizedConfig), {}, {
38
+ source: _objectSpread(_objectSpread({}, normalizedConfig.source), {}, {
39
+ resolveExtensionPrefix: '.web'
40
+ }),
40
41
  output,
41
- tools,
42
- performance: {
42
+ dev: {
43
+ https: normalizedConfig.dev.https,
44
+ assetPrefix: normalizedConfig.dev.assetPrefix
45
+ },
46
+ html: _objectSpread(_objectSpread({}, normalizedConfig.html), {}, {
47
+ templateByEntries: normalizedConfig.html.templateByEntries || appContext.htmlTemplates
48
+ }),
49
+ performance: _objectSpread(_objectSpread({}, normalizedConfig.performance), {}, {
43
50
  // `@modern-js/webpack` used to remove moment locale by default
44
51
  removeMomentLocale: true
45
- }
46
- };
52
+ })
53
+ });
54
+ function createOutputConfig(config, appContext) {
55
+ const defaultCopyPattern = createCopyPattern(appContext, config, 'upload');
56
+ const {
57
+ copy
58
+ } = config.output;
59
+ const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
60
+ const builderCopy = [...(copyOptions || []), defaultCopyPattern];
61
+ return _objectSpread(_objectSpread({}, config.output), {}, {
62
+ copy: builderCopy,
63
+ // We need to do this in the app-tools prepare hook because some files will be generated into the dist directory in the analyze process
64
+ cleanDistPath: false,
65
+ // `@modern-js/webpack` used to generate asset manifest by default
66
+ enableAssetManifest: true,
67
+ // compatible the modern-js with fallback behavior
68
+ enableAssetFallback: true
69
+ });
70
+ }
47
71
  }
48
-
49
72
  export function createBuilderOptions(target, appContext) {
50
73
  // create entries
74
+
51
75
  const entries = {};
52
76
  const {
53
77
  entrypoints = [],
54
78
  checkedEntries
55
79
  } = appContext;
56
-
57
80
  for (const {
58
81
  entryName,
59
82
  entry
@@ -61,14 +84,12 @@ export function createBuilderOptions(target, appContext) {
61
84
  if (checkedEntries && !checkedEntries.includes(entryName)) {
62
85
  continue;
63
86
  }
64
-
65
87
  if (entryName in entries) {
66
88
  entries[entryName].push(entry);
67
89
  } else {
68
90
  entries[entryName] = [entry];
69
91
  }
70
92
  }
71
-
72
93
  return {
73
94
  cwd: appContext.appDirectory,
74
95
  target,
@@ -77,10 +98,10 @@ export function createBuilderOptions(target, appContext) {
77
98
  framework: appContext.metaName
78
99
  };
79
100
  }
101
+
80
102
  /**
81
103
  * register builder Plugin by condition
82
104
  */
83
-
84
105
  async function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
85
106
  if (!normalizedConfig.output.disableNodePolyfill) {
86
107
  const {
@@ -88,7 +109,6 @@ async function applyBuilderPlugins(builder, normalizedConfig, appContext, compat
88
109
  } = await import('@modern-js/builder-plugin-node-polyfill');
89
110
  builder.addPlugins([PluginNodePolyfill()]);
90
111
  }
91
-
92
112
  if (normalizedConfig.tools.esbuild) {
93
113
  const {
94
114
  esbuild: esbuildOptions
@@ -101,6 +121,5 @@ async function applyBuilderPlugins(builder, normalizedConfig, appContext, compat
101
121
  minimize: applyOptionsChain({}, esbuildOptions)
102
122
  })]);
103
123
  }
104
-
105
124
  builder.addPlugins([PluginCompatModern(appContext, normalizedConfig, compatPluginConfig)]);
106
125
  }
@@ -2,23 +2,20 @@ import path from 'path';
2
2
  import { template as lodashTemplate } from '@modern-js/utils/lodash';
3
3
  import { removeTailSlash } from '@modern-js/utils';
4
4
  export function createCopyPattern(appContext, config, patternsType, chain) {
5
- const configDir = path.resolve(appContext.appDirectory, config.source.configDir);
5
+ const configDir = path.resolve(appContext.appDirectory, config.source.configDir || './config');
6
6
  const uploadDir = path.posix.join(configDir.replace(/\\/g, '/'), 'upload');
7
7
  const publicDir = path.posix.join(configDir.replace(/\\/g, '/'), 'public');
8
8
  const minifiedJsRexExp = /\.min\.js/;
9
-
10
9
  const info = file => ({
11
10
  // If the file name ends with `.min.js`, we assume it's a compressed file.
12
11
  // So we don't want copy-webpack-plugin to minify it.
13
12
  // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
14
13
  minimized: minifiedJsRexExp.test(file.sourceFilename)
15
14
  });
16
-
17
15
  if (patternsType === 'public') {
18
16
  if (!chain) {
19
17
  throw new Error("expect get a webpackChain, but receive 'undefined'");
20
18
  }
21
-
22
19
  return {
23
20
  info,
24
21
  from: '**/*',
@@ -30,7 +27,6 @@ export function createCopyPattern(appContext, config, patternsType, chain) {
30
27
  if (!/\.html?$/.test(absoluteFrom)) {
31
28
  return content;
32
29
  }
33
-
34
30
  return lodashTemplate(content.toString('utf8'))({
35
31
  assetPrefix: removeTailSlash(chain.output.get('publicPath'))
36
32
  });
@@ -1,37 +1,29 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
2
  export class HtmlAsyncChunkPlugin {
4
3
  constructor(htmlWebpackPlugin) {
5
4
  _defineProperty(this, "name", void 0);
6
-
7
5
  _defineProperty(this, "htmlWebpackPlugin", void 0);
8
-
9
6
  this.name = 'HtmlAsyncChunkPlugin';
10
7
  this.htmlWebpackPlugin = htmlWebpackPlugin;
11
8
  }
12
-
13
9
  apply(compiler) {
14
10
  compiler.hooks.compilation.tap(this.name, compilation => {
15
11
  const hooks = this.htmlWebpackPlugin.getHooks(compilation);
16
12
  hooks.alterAssetTagGroups.tap(this.name, assets => {
17
13
  const tags = [...assets.headTags, ...assets.bodyTags];
18
-
19
14
  for (const tag of tags) {
20
15
  if (tag.tagName === 'script') {
21
16
  const {
22
17
  attributes
23
18
  } = tag;
24
-
25
19
  if (attributes && attributes.defer === true) {
26
20
  attributes.async = true;
27
21
  delete attributes.defer;
28
22
  }
29
23
  }
30
24
  }
31
-
32
25
  return assets;
33
26
  });
34
27
  });
35
28
  }
36
-
37
29
  }
@@ -1,44 +1,33 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
2
  export class BottomTemplatePlugin {
4
3
  constructor(htmlWebpackPlugin) {
5
4
  _defineProperty(this, "htmlWebpackPlugin", void 0);
6
-
7
5
  _defineProperty(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
8
-
9
6
  _defineProperty(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
10
-
11
7
  _defineProperty(this, "name", void 0);
12
-
13
8
  this.htmlWebpackPlugin = htmlWebpackPlugin;
14
9
  this.name = 'bottom-template';
15
10
  }
16
-
17
11
  apply(compiler) {
18
12
  compiler.hooks.compilation.tap(this.name, compilation => {
19
13
  this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, data => {
20
14
  var _data$plugin$options;
21
-
22
15
  if (!((_data$plugin$options = data.plugin.options) !== null && _data$plugin$options !== void 0 && _data$plugin$options.__internal__)) {
23
16
  return data;
24
- } // 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
25
-
26
-
17
+ }
18
+ // 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
27
19
  if (this.bottomTemplateReg.test(data.html)) {
28
20
  // 清空占位符
29
21
  data.html = data.html.replace(this.bottomTemplateReg, '');
30
22
  const {
31
23
  bottomTemplate
32
24
  } = data.plugin.options;
33
-
34
25
  if (bottomTemplate) {
35
26
  data.html = data.html.replace(this.bodyRegExp, match => `\n${bottomTemplate}\n${match}`);
36
27
  }
37
28
  }
38
-
39
29
  return data;
40
30
  });
41
31
  });
42
32
  }
43
-
44
33
  }
@@ -0,0 +1,97 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ import path from 'path';
3
+ import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from '@modern-js/utils';
4
+ const PLUGIN_NAME = 'ModernjsRoutePlugin';
5
+ export default class RouterPlugin {
6
+ constructor(options) {
7
+ _defineProperty(this, "existNestedRoutes", void 0);
8
+ this.existNestedRoutes = options.existNestedRoutes;
9
+ }
10
+ apply(compiler) {
11
+ const {
12
+ existNestedRoutes
13
+ } = this;
14
+ const {
15
+ target
16
+ } = compiler.options;
17
+ if (target === 'node' || Array.isArray(target) && target.includes('node')) {
18
+ return;
19
+ }
20
+ if (!existNestedRoutes) {
21
+ return;
22
+ }
23
+ const {
24
+ webpack
25
+ } = compiler;
26
+ const {
27
+ Compilation,
28
+ sources
29
+ } = webpack;
30
+ const {
31
+ RawSource
32
+ } = sources;
33
+ const {
34
+ PROCESS_ASSETS_STAGE_REPORT
35
+ } = Compilation;
36
+ const outputPath = compiler.options.output.path;
37
+ const newAssetsMap = new Map();
38
+ const normalizePath = path => {
39
+ if (!path.endsWith('/')) {
40
+ return `${path}/`;
41
+ }
42
+ return path;
43
+ };
44
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
45
+ compilation.hooks.processAssets.tapPromise({
46
+ name: PLUGIN_NAME,
47
+ stage: PROCESS_ASSETS_STAGE_REPORT
48
+ }, async () => {
49
+ const stats = compilation.getStats().toJson({
50
+ chunkGroups: true,
51
+ chunks: true
52
+ });
53
+ const {
54
+ publicPath
55
+ } = stats;
56
+ const routeAssets = {};
57
+ const {
58
+ namedChunkGroups,
59
+ assetsByChunkName
60
+ } = stats;
61
+ if (!namedChunkGroups || !assetsByChunkName) {
62
+ logger.warn('Route manifest does not exist, performance will be affected');
63
+ return;
64
+ }
65
+ for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
66
+ routeAssets[name] = {
67
+ chunkIds: chunkGroup.chunks,
68
+ assets: assetsByChunkName[name].map(item => publicPath ? normalizePath(publicPath) + item : item)
69
+ };
70
+ }
71
+ const manifest = {
72
+ routeAssets
73
+ };
74
+ const injectedContent = `
75
+ ;(function(){
76
+ window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest)};
77
+ })();
78
+ `;
79
+ const entrypointsArray = Array.from(compilation.entrypoints.entries());
80
+ const entryChunkIds = entrypointsArray.map(entrypoint => entrypoint[0]);
81
+ const entryChunks = [...compilation.chunks].filter(chunk => {
82
+ return entryChunkIds.includes(chunk.name);
83
+ });
84
+ const entryChunkFiles = entryChunks.map(chunk => [...chunk.files][0]);
85
+ for (const file of entryChunkFiles) {
86
+ const asset = compilation.assets[file];
87
+ const newContent = `${injectedContent}${asset.source().toString()}`;
88
+ newAssetsMap.set(path.join(outputPath, file), newContent);
89
+ compilation.updateAsset(file, new RawSource(newContent));
90
+ }
91
+ const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
92
+ await fs.ensureFile(filename);
93
+ await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
94
+ });
95
+ });
96
+ }
97
+ }