@modern-js/app-tools 2.58.1-alpha.6 → 2.58.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (285) hide show
  1. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +0 -1
  2. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -2
  4. package/dist/cjs/builder/index.js +2 -2
  5. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +13 -4
  6. package/dist/cjs/commands/build.js +19 -0
  7. package/dist/cjs/commands/dev.js +9 -0
  8. package/dist/cjs/commands/index.js +8 -8
  9. package/dist/cjs/commands/inspect.js +1 -1
  10. package/dist/cjs/config/initialize/inits.js +4 -4
  11. package/dist/cjs/esm/esbuild-loader.mjs +20 -0
  12. package/dist/cjs/esm/register-esm.mjs +67 -0
  13. package/dist/cjs/esm/ts-node-loader.mjs +21 -0
  14. package/dist/cjs/esm/utils.mjs +43 -0
  15. package/dist/cjs/index.js +1 -1
  16. package/dist/cjs/plugins/analyze/index.js +3 -3
  17. package/dist/cjs/plugins/deploy/dependencies/index.js +2 -15
  18. package/dist/cjs/plugins/deploy/dependencies/utils.js +13 -78
  19. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +3 -0
  20. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  21. package/dist/cjs/plugins/deploy/platforms/{netlifyEntry.js → netlify-handler.js} +6 -4
  22. package/dist/cjs/plugins/deploy/platforms/netlify.js +14 -5
  23. package/dist/cjs/plugins/deploy/platforms/node.js +13 -4
  24. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +3 -0
  25. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  26. package/dist/cjs/plugins/deploy/platforms/{vercelEntry.js → vercel-handler.js} +4 -1
  27. package/dist/cjs/plugins/deploy/platforms/vercel.js +14 -5
  28. package/dist/cjs/utils/config.js +1 -1
  29. package/dist/cjs/utils/loadPlugins.js +1 -1
  30. package/dist/cjs/utils/register.js +50 -23
  31. package/dist/types/builder/builder-rspack/adapterCopy.d.ts +2 -2
  32. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  33. package/dist/types/builder/builder-webpack/adapterModern.d.ts +2 -2
  34. package/dist/types/builder/builder-webpack/index.d.ts +1 -1
  35. package/dist/types/builder/generator/index.d.ts +2 -2
  36. package/dist/types/builder/index.d.ts +1 -1
  37. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  38. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  39. package/dist/types/builder/shared/createCopyInfo.d.ts +1 -1
  40. package/dist/types/commands/build.d.ts +1 -1
  41. package/dist/types/commands/dev.d.ts +3 -3
  42. package/dist/types/commands/index.d.ts +3 -3
  43. package/dist/types/config/default.d.ts +1 -1
  44. package/dist/types/config/initialize/inits.d.ts +1 -1
  45. package/dist/types/config/legacy/createHtmlConfig.d.ts +1 -1
  46. package/dist/types/config/legacy/createOutputConfig.d.ts +1 -1
  47. package/dist/types/config/legacy/createSourceConfig.d.ts +1 -1
  48. package/dist/types/config/legacy/createToolsConfig.d.ts +1 -1
  49. package/dist/types/esm/esbuild-loader.d.mts +6 -0
  50. package/dist/types/esm/register-esm.d.mts +5 -0
  51. package/dist/types/esm/ts-node-loader.d.mts +6 -0
  52. package/dist/types/esm/utils.d.mts +6 -0
  53. package/dist/types/exports/server.d.ts +1 -1
  54. package/dist/types/hooks.d.ts +1 -1
  55. package/dist/types/index.d.ts +2 -2
  56. package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
  57. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
  58. package/dist/types/plugins/analyze/index.d.ts +1 -1
  59. package/dist/types/plugins/deploy/dependencies/index.d.ts +3 -5
  60. package/dist/types/plugins/deploy/dependencies/utils.d.ts +2 -9
  61. package/dist/types/plugins/deploy/index.d.ts +2 -2
  62. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
  63. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +1 -0
  64. package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +1 -0
  65. package/dist/types/plugins/deploy/platforms/netlify.d.ts +1 -1
  66. package/dist/types/plugins/deploy/platforms/node.d.ts +1 -1
  67. package/dist/types/plugins/deploy/platforms/platform.d.ts +2 -2
  68. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +2 -0
  69. package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +2 -0
  70. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +1 -0
  71. package/dist/types/plugins/deploy/platforms/vercel.d.ts +1 -1
  72. package/dist/types/plugins/deploy/utils.d.ts +1 -1
  73. package/dist/types/plugins/serverBuild.d.ts +1 -1
  74. package/dist/types/types/hooks.d.ts +1 -1
  75. package/dist/types/types/index.d.ts +1 -1
  76. package/dist/types/utils/createServer.d.ts +1 -1
  77. package/dist/types/utils/generateWatchFiles.d.ts +1 -1
  78. package/dist/types/utils/getSelectedEntries.d.ts +1 -1
  79. package/dist/types/utils/loadPlugins.d.ts +3 -3
  80. package/dist/types/utils/register.d.ts +2 -2
  81. package/dist/types/utils/restart.d.ts +2 -2
  82. package/lib/types.d.ts +15 -0
  83. package/package.json +20 -21
  84. package/dist/esm/builder/builder-rspack/adapterCopy.js +0 -166
  85. package/dist/esm/builder/builder-rspack/index.js +0 -34
  86. package/dist/esm/builder/builder-webpack/adapterModern.js +0 -29
  87. package/dist/esm/builder/builder-webpack/createCopyPattern.js +0 -44
  88. package/dist/esm/builder/builder-webpack/index.js +0 -52
  89. package/dist/esm/builder/generator/createBuilderProviderConfig.js +0 -37
  90. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -81
  91. package/dist/esm/builder/generator/index.js +0 -94
  92. package/dist/esm/builder/index.js +0 -45
  93. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +0 -85
  94. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +0 -126
  95. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +0 -270
  96. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +0 -43
  97. package/dist/esm/builder/shared/builderPlugins/index.js +0 -4
  98. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -51
  99. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -37
  100. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +0 -288
  101. package/dist/esm/builder/shared/bundlerPlugins/index.js +0 -3
  102. package/dist/esm/builder/shared/createCopyInfo.js +0 -14
  103. package/dist/esm/builder/shared/index.js +0 -3
  104. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +0 -7
  105. package/dist/esm/builder/shared/types.js +0 -0
  106. package/dist/esm/commands/build.js +0 -117
  107. package/dist/esm/commands/deploy.js +0 -48
  108. package/dist/esm/commands/dev.js +0 -169
  109. package/dist/esm/commands/index.js +0 -411
  110. package/dist/esm/commands/inspect.js +0 -28
  111. package/dist/esm/commands/serve.js +0 -93
  112. package/dist/esm/config/default.js +0 -190
  113. package/dist/esm/config/index.js +0 -3
  114. package/dist/esm/config/initialize/index.js +0 -9
  115. package/dist/esm/config/initialize/inits.js +0 -85
  116. package/dist/esm/config/legacy/createHtmlConfig.js +0 -21
  117. package/dist/esm/config/legacy/createOutputConfig.js +0 -45
  118. package/dist/esm/config/legacy/createSourceConfig.js +0 -46
  119. package/dist/esm/config/legacy/createToolsConfig.js +0 -28
  120. package/dist/esm/config/legacy/index.js +0 -43
  121. package/dist/esm/defineConfig.js +0 -16
  122. package/dist/esm/exports/server.js +0 -4
  123. package/dist/esm/hooks.js +0 -34
  124. package/dist/esm/index.js +0 -239
  125. package/dist/esm/locale/en.js +0 -43
  126. package/dist/esm/locale/index.js +0 -12
  127. package/dist/esm/locale/zh.js +0 -43
  128. package/dist/esm/plugins/analyze/constants.js +0 -14
  129. package/dist/esm/plugins/analyze/getBundleEntry.js +0 -102
  130. package/dist/esm/plugins/analyze/getFileSystemEntry.js +0 -238
  131. package/dist/esm/plugins/analyze/getHtmlTemplate.js +0 -178
  132. package/dist/esm/plugins/analyze/getServerRoutes.js +0 -132
  133. package/dist/esm/plugins/analyze/index.js +0 -380
  134. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +0 -49
  135. package/dist/esm/plugins/analyze/templates.js +0 -6
  136. package/dist/esm/plugins/analyze/utils.js +0 -101
  137. package/dist/esm/plugins/deploy/dependencies/index.js +0 -629
  138. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -643
  139. package/dist/esm/plugins/deploy/exports.js +0 -4
  140. package/dist/esm/plugins/deploy/index.js +0 -135
  141. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -299
  142. package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +0 -203
  143. package/dist/esm/plugins/deploy/platforms/node.js +0 -133
  144. package/dist/esm/plugins/deploy/platforms/nodeEntry.js +0 -108
  145. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  146. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -233
  147. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -203
  148. package/dist/esm/plugins/deploy/utils.js +0 -47
  149. package/dist/esm/plugins/initialize/index.js +0 -119
  150. package/dist/esm/plugins/serverBuild.js +0 -87
  151. package/dist/esm/types/config/deploy.js +0 -0
  152. package/dist/esm/types/config/dev.js +0 -0
  153. package/dist/esm/types/config/experiments.js +0 -0
  154. package/dist/esm/types/config/html.js +0 -0
  155. package/dist/esm/types/config/index.js +0 -1
  156. package/dist/esm/types/config/output.js +0 -0
  157. package/dist/esm/types/config/performance.js +0 -0
  158. package/dist/esm/types/config/security.js +0 -0
  159. package/dist/esm/types/config/source.js +0 -0
  160. package/dist/esm/types/config/testing.js +0 -0
  161. package/dist/esm/types/config/tools.js +0 -0
  162. package/dist/esm/types/hooks.js +0 -0
  163. package/dist/esm/types/index.js +0 -3
  164. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  165. package/dist/esm/types/legacyConfig/dev.js +0 -0
  166. package/dist/esm/types/legacyConfig/index.js +0 -0
  167. package/dist/esm/types/legacyConfig/output.js +0 -0
  168. package/dist/esm/types/legacyConfig/source.js +0 -0
  169. package/dist/esm/types/legacyConfig/testing.js +0 -0
  170. package/dist/esm/types/legacyConfig/tools.js +0 -0
  171. package/dist/esm/types/utils.js +0 -0
  172. package/dist/esm/utils/config.js +0 -122
  173. package/dist/esm/utils/createServer.js +0 -58
  174. package/dist/esm/utils/env.js +0 -16
  175. package/dist/esm/utils/generateWatchFiles.js +0 -71
  176. package/dist/esm/utils/getSelectedEntries.js +0 -67
  177. package/dist/esm/utils/loadPlugins.js +0 -69
  178. package/dist/esm/utils/printInstructions.js +0 -32
  179. package/dist/esm/utils/register.js +0 -129
  180. package/dist/esm/utils/restart.js +0 -67
  181. package/dist/esm/utils/routes.js +0 -42
  182. package/dist/esm/utils/types.js +0 -0
  183. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +0 -67
  184. package/dist/esm-node/builder/builder-rspack/index.js +0 -12
  185. package/dist/esm-node/builder/builder-webpack/adapterModern.js +0 -26
  186. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +0 -42
  187. package/dist/esm-node/builder/builder-webpack/index.js +0 -20
  188. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +0 -44
  189. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +0 -60
  190. package/dist/esm-node/builder/generator/index.js +0 -37
  191. package/dist/esm-node/builder/index.js +0 -11
  192. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +0 -48
  193. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +0 -60
  194. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +0 -156
  195. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +0 -27
  196. package/dist/esm-node/builder/shared/builderPlugins/index.js +0 -4
  197. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -30
  198. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -31
  199. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +0 -219
  200. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +0 -3
  201. package/dist/esm-node/builder/shared/createCopyInfo.js +0 -14
  202. package/dist/esm-node/builder/shared/index.js +0 -3
  203. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +0 -7
  204. package/dist/esm-node/builder/shared/types.js +0 -0
  205. package/dist/esm-node/commands/build.js +0 -55
  206. package/dist/esm-node/commands/deploy.js +0 -12
  207. package/dist/esm-node/commands/dev.js +0 -95
  208. package/dist/esm-node/commands/index.js +0 -92
  209. package/dist/esm-node/commands/inspect.js +0 -15
  210. package/dist/esm-node/commands/serve.js +0 -51
  211. package/dist/esm-node/config/default.js +0 -197
  212. package/dist/esm-node/config/index.js +0 -3
  213. package/dist/esm-node/config/initialize/index.js +0 -9
  214. package/dist/esm-node/config/initialize/inits.js +0 -79
  215. package/dist/esm-node/config/legacy/createHtmlConfig.js +0 -21
  216. package/dist/esm-node/config/legacy/createOutputConfig.js +0 -45
  217. package/dist/esm-node/config/legacy/createSourceConfig.js +0 -29
  218. package/dist/esm-node/config/legacy/createToolsConfig.js +0 -28
  219. package/dist/esm-node/config/legacy/index.js +0 -43
  220. package/dist/esm-node/defineConfig.js +0 -13
  221. package/dist/esm-node/exports/server.js +0 -4
  222. package/dist/esm-node/hooks.js +0 -34
  223. package/dist/esm-node/index.js +0 -124
  224. package/dist/esm-node/locale/en.js +0 -43
  225. package/dist/esm-node/locale/index.js +0 -12
  226. package/dist/esm-node/locale/zh.js +0 -43
  227. package/dist/esm-node/plugins/analyze/constants.js +0 -14
  228. package/dist/esm-node/plugins/analyze/getBundleEntry.js +0 -61
  229. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +0 -100
  230. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +0 -74
  231. package/dist/esm-node/plugins/analyze/getServerRoutes.js +0 -132
  232. package/dist/esm-node/plugins/analyze/index.js +0 -166
  233. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +0 -47
  234. package/dist/esm-node/plugins/analyze/templates.js +0 -24
  235. package/dist/esm-node/plugins/analyze/utils.js +0 -68
  236. package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -215
  237. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -202
  238. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  239. package/dist/esm-node/plugins/deploy/index.js +0 -44
  240. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -108
  241. package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +0 -69
  242. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -63
  243. package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +0 -44
  244. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  245. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -120
  246. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -69
  247. package/dist/esm-node/plugins/deploy/utils.js +0 -44
  248. package/dist/esm-node/plugins/initialize/index.js +0 -84
  249. package/dist/esm-node/plugins/serverBuild.js +0 -58
  250. package/dist/esm-node/types/config/deploy.js +0 -0
  251. package/dist/esm-node/types/config/dev.js +0 -0
  252. package/dist/esm-node/types/config/experiments.js +0 -0
  253. package/dist/esm-node/types/config/html.js +0 -0
  254. package/dist/esm-node/types/config/index.js +0 -1
  255. package/dist/esm-node/types/config/output.js +0 -0
  256. package/dist/esm-node/types/config/performance.js +0 -0
  257. package/dist/esm-node/types/config/security.js +0 -0
  258. package/dist/esm-node/types/config/source.js +0 -0
  259. package/dist/esm-node/types/config/testing.js +0 -0
  260. package/dist/esm-node/types/config/tools.js +0 -0
  261. package/dist/esm-node/types/hooks.js +0 -0
  262. package/dist/esm-node/types/index.js +0 -3
  263. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  264. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  265. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  266. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  267. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  268. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  269. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  270. package/dist/esm-node/types/utils.js +0 -0
  271. package/dist/esm-node/utils/config.js +0 -49
  272. package/dist/esm-node/utils/createServer.js +0 -26
  273. package/dist/esm-node/utils/env.js +0 -16
  274. package/dist/esm-node/utils/generateWatchFiles.js +0 -30
  275. package/dist/esm-node/utils/getSelectedEntries.js +0 -34
  276. package/dist/esm-node/utils/loadPlugins.js +0 -22
  277. package/dist/esm-node/utils/printInstructions.js +0 -11
  278. package/dist/esm-node/utils/register.js +0 -69
  279. package/dist/esm-node/utils/restart.js +0 -22
  280. package/dist/esm-node/utils/routes.js +0 -21
  281. package/dist/esm-node/utils/types.js +0 -0
  282. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +0 -2
  283. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  284. /package/dist/cjs/plugins/deploy/platforms/{nodeEntry.js → node-entry.js} +0 -0
  285. /package/dist/types/plugins/deploy/platforms/{nodeEntry.d.ts → node-entry.d.ts} +0 -0
@@ -1,48 +0,0 @@
1
- import path from "path";
2
- import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
3
- const builderPluginAdapterBasic = () => ({
4
- name: "builder-plugin-adapter-modern-basic",
5
- setup(api) {
6
- api.modifyBundlerChain((chain, { target, CHAIN_ID, environment }) => {
7
- const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
8
- if (target === "node" || isServiceWorker) {
9
- applyNodeCompat(isServiceWorker, chain);
10
- }
11
- if (target === "web") {
12
- const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
13
- chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
14
- chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
15
- }
16
- chain.resolve.modules.add("node_modules").add(path.join(api.context.rootPath, "node_modules"));
17
- });
18
- }
19
- });
20
- function applyNodeCompat(isServiceWorker, chain) {
21
- const nodeExts = [
22
- ".node.js",
23
- ".node.jsx",
24
- ".node.ts",
25
- ".node.tsx",
26
- ".server.js",
27
- ".server.jsx",
28
- ".server.ts",
29
- ".server.tsx"
30
- ];
31
- const webWorkerExts = [
32
- ".worker.js",
33
- ".worker.jsx",
34
- ".worker.ts",
35
- ".worker.tsx"
36
- ];
37
- for (const ext of nodeExts) {
38
- chain.resolve.extensions.prepend(ext);
39
- }
40
- if (isServiceWorker) {
41
- for (const ext of webWorkerExts) {
42
- chain.resolve.extensions.prepend(ext);
43
- }
44
- }
45
- }
46
- export {
47
- builderPluginAdapterBasic
48
- };
@@ -1,60 +0,0 @@
1
- import { isHtmlDisabled } from "@modern-js/uni-builder";
2
- import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
3
- import { template as lodashTemplate } from "@modern-js/utils/lodash";
4
- import { BottomTemplatePlugin } from "../bundlerPlugins";
5
- const createVirtualModule = (content) => `data:text/javascript,${content}`;
6
- const builderPluginAdapterHtml = (options) => ({
7
- name: "builder-plugin-adapter-modern-html",
8
- setup(api) {
9
- api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin, environment }) => {
10
- const builderConfig = environment.config;
11
- if (!isHtmlDisabled(builderConfig, target)) {
12
- applyBottomHtmlPlugin({
13
- options,
14
- chain,
15
- CHAIN_ID,
16
- HtmlBundlerPlugin,
17
- htmlPaths: environment.htmlPaths
18
- });
19
- await injectAssetPrefix({
20
- chain
21
- });
22
- }
23
- });
24
- }
25
- });
26
- async function injectAssetPrefix({ chain }) {
27
- const entries = chain.entryPoints.entries() || {};
28
- const entryNames = Object.keys(entries);
29
- const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
30
- const code = `window.__assetPrefix__ = '${assetPrefix}';`;
31
- entryNames.forEach((entryName) => {
32
- entries[entryName].prepend(createVirtualModule(code));
33
- });
34
- }
35
- function applyBottomHtmlPlugin({ chain, options, CHAIN_ID, HtmlBundlerPlugin, htmlPaths }) {
36
- const { normalizedConfig: modernConfig, appContext } = options;
37
- for (const entryName of Object.keys(htmlPaths)) {
38
- const { source: { mainEntryName } } = modernConfig;
39
- const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
40
- const baseTemplateParams = {
41
- entryName,
42
- title: getEntryOptions(entryName, isMainEntry, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
43
- mountId: modernConfig.html.mountId,
44
- ...getEntryOptions(entryName, isMainEntry, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName)
45
- };
46
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
47
- {
48
- ...args[0] || {},
49
- __internal__: true,
50
- bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(baseTemplateParams)
51
- }
52
- ]);
53
- }
54
- chain.plugin("bottom-template").use(BottomTemplatePlugin, [
55
- HtmlBundlerPlugin
56
- ]);
57
- }
58
- export {
59
- builderPluginAdapterHtml
60
- };
@@ -1,156 +0,0 @@
1
- import * as path from "path";
2
- import { mergeRsbuildConfig } from "@rsbuild/core";
3
- import { fs, isUseSSRBundle } from "@modern-js/utils";
4
- import { isHtmlDisabled, SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
5
- import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
6
- import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
7
- const builderPluginAdapterSSR = (options) => ({
8
- name: "builder-plugin-adapter-modern-ssr",
9
- setup(api) {
10
- const { normalizedConfig } = options;
11
- api.modifyRsbuildConfig((config) => {
12
- return mergeRsbuildConfig(config, {
13
- html: {
14
- inject: isStreamingSSR(normalizedConfig) ? "body" : void 0
15
- },
16
- server: {
17
- // the http-compression can't handler stream http.
18
- // so we disable compress when user use stream ssr temporarily.
19
- compress: isStreamingSSR(normalizedConfig) || isSSRPreload(normalizedConfig) ? false : void 0
20
- }
21
- });
22
- });
23
- api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment }) => {
24
- const builderConfig = environment.config;
25
- const { normalizedConfig: normalizedConfig2 } = options;
26
- applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
27
- if (isUseSSRBundle(normalizedConfig2)) {
28
- await applySSRLoaderEntry(chain, options, isServer);
29
- applySSRDataLoader(chain, options);
30
- }
31
- const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
32
- if (target === "node" || isServiceWorker) {
33
- applyFilterEntriesBySSRConfig({
34
- isProd,
35
- chain,
36
- appNormalizedConfig: normalizedConfig2
37
- });
38
- }
39
- if (!isHtmlDisabled(builderConfig, target)) {
40
- applyAsyncChunkHtmlPlugin({
41
- chain,
42
- modernConfig: options.normalizedConfig,
43
- HtmlBundlerPlugin
44
- });
45
- }
46
- });
47
- }
48
- });
49
- const isSSRPreload = (userConfig) => {
50
- const { server: { ssr, ssrByEntries } } = userConfig;
51
- const checkUsePreload = (ssr2) => typeof ssr2 === "object" && Boolean(ssr2.preload);
52
- return checkUsePreload(ssr) || Object.values(ssrByEntries || {}).some((ssr2) => checkUsePreload(ssr2));
53
- };
54
- const isStreamingSSR = (userConfig) => {
55
- const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
56
- const { server } = userConfig;
57
- if (isStreaming(server.ssr)) {
58
- return true;
59
- }
60
- if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
61
- for (const name of Object.keys(server.ssrByEntries)) {
62
- if (isStreaming(server.ssrByEntries[name])) {
63
- return true;
64
- }
65
- }
66
- }
67
- return false;
68
- };
69
- function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
70
- if (isStreamingSSR(modernConfig)) {
71
- chain.plugin("html-async-chunk").use(HtmlAsyncChunkPlugin, [
72
- HtmlBundlerPlugin
73
- ]);
74
- }
75
- }
76
- function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
77
- var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
78
- const { appContext, normalizedConfig } = options;
79
- const { entrypoints } = appContext;
80
- const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
81
- const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
82
- const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
83
- const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
84
- const { enableInlineRouteManifests, disableInlineRouteManifests } = normalizedConfig.output;
85
- const inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
86
- if (existNestedRoutes || routerManifest || workerSSR) {
87
- var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
88
- chain.plugin(pluginName).use(RouterPlugin, [
89
- {
90
- HtmlBundlerPlugin,
91
- enableInlineRouteManifests: inlineRouteManifests,
92
- staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
93
- disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
94
- scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
95
- nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
96
- }
97
- ]);
98
- }
99
- }
100
- function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
101
- var _this;
102
- const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
103
- const entries = chain.entryPoints.entries();
104
- if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_this = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
105
- return;
106
- }
107
- if (typeof entries === "undefined") {
108
- throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
109
- }
110
- const entryNames = Object.keys(entries);
111
- if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
112
- return;
113
- }
114
- const ssgEntries = [];
115
- if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
116
- const { ssg } = outputConfig;
117
- entryNames.forEach((name) => {
118
- if (ssg[name]) {
119
- ssgEntries.push(name);
120
- }
121
- });
122
- }
123
- const { ssr, ssrByEntries } = serverConfig || {};
124
- entryNames.forEach((name) => {
125
- if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
126
- chain.entryPoints.delete(name);
127
- }
128
- });
129
- }
130
- async function applySSRLoaderEntry(chain, optinos, isServer) {
131
- const { appContext } = optinos;
132
- const { internalDirectory } = appContext;
133
- const { entrypoints } = appContext;
134
- await Promise.all(entrypoints.map(async (entrypoint) => {
135
- const { entryName } = entrypoint;
136
- const serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
137
- if (isServer) {
138
- try {
139
- await fs.access(serverLoadersFile, fs.constants.F_OK);
140
- chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
141
- } catch (err) {
142
- }
143
- }
144
- }));
145
- }
146
- function applySSRDataLoader(chain, options) {
147
- const { normalizedConfig, appContext } = options;
148
- const { appDirectory } = appContext;
149
- const { entriesDir = "./src" } = normalizedConfig.source;
150
- const absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
151
- const reg = new RegExp(`${absolutePath}.*\\.(loader|data|data.client)\\.[t|j]sx?$`);
152
- chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
153
- }
154
- export {
155
- builderPluginAdapterSSR
156
- };
@@ -1,27 +0,0 @@
1
- import { posix } from "path";
2
- import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
3
- const getDistPath = (outputConfig, type) => {
4
- const { distPath } = outputConfig;
5
- const ret = distPath[type];
6
- if (typeof ret !== "string") {
7
- throw new Error(`unknown key ${type} in "output.distPath"`);
8
- }
9
- return ret;
10
- };
11
- const builderPluginAdapterWorker = () => ({
12
- name: "builder-plugin-adapter-worker",
13
- setup(api) {
14
- api.modifyBundlerChain(async (chain, { environment }) => {
15
- const { config, name } = environment;
16
- const isServiceWorker = name === SERVICE_WORKER_ENVIRONMENT_NAME;
17
- if (isServiceWorker) {
18
- const workerPath = getDistPath(config.output, "root");
19
- const filename = posix.join(workerPath, `[name].js`);
20
- chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
21
- }
22
- });
23
- }
24
- });
25
- export {
26
- builderPluginAdapterWorker
27
- };
@@ -1,4 +0,0 @@
1
- export * from "./adapterBasic";
2
- export * from "./adapterHtml";
3
- export * from "./adapterSSR";
4
- export * from "./adapterWorker";
@@ -1,30 +0,0 @@
1
- class HtmlAsyncChunkPlugin {
2
- apply(compiler) {
3
- compiler.hooks.compilation.tap(this.name, (compilation) => {
4
- const hooks = this.htmlWebpackPlugin.getHooks(compilation);
5
- hooks.alterAssetTagGroups.tap(this.name, (assets) => {
6
- const tags = [
7
- ...assets.headTags,
8
- ...assets.bodyTags
9
- ];
10
- for (const tag of tags) {
11
- if (tag.tagName === "script") {
12
- const { attributes } = tag;
13
- if (attributes && attributes.defer === true) {
14
- attributes.async = true;
15
- delete attributes.defer;
16
- }
17
- }
18
- }
19
- return assets;
20
- });
21
- });
22
- }
23
- constructor(htmlWebpackPlugin) {
24
- this.name = "HtmlAsyncChunkPlugin";
25
- this.htmlWebpackPlugin = htmlWebpackPlugin;
26
- }
27
- }
28
- export {
29
- HtmlAsyncChunkPlugin
30
- };
@@ -1,31 +0,0 @@
1
- class BottomTemplatePlugin {
2
- apply(compiler) {
3
- compiler.hooks.compilation.tap(this.name, (compilation) => {
4
- this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
5
- var _data_plugin_options;
6
- if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
7
- return data;
8
- }
9
- if (this.bottomTemplateReg.test(data.html)) {
10
- data.html = data.html.replace(this.bottomTemplateReg, "");
11
- const { bottomTemplate } = data.plugin.options;
12
- if (bottomTemplate) {
13
- data.html = data.html.replace(this.bodyRegExp, (match) => `
14
- ${bottomTemplate}
15
- ${match}`);
16
- }
17
- }
18
- return data;
19
- });
20
- });
21
- }
22
- constructor(htmlWebpackPlugin) {
23
- this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
24
- this.bodyRegExp = /(<\/\s*body\s*>)/i;
25
- this.htmlWebpackPlugin = htmlWebpackPlugin;
26
- this.name = "bottom-template";
27
- }
28
- }
29
- export {
30
- BottomTemplatePlugin
31
- };
@@ -1,219 +0,0 @@
1
- import { createHash } from "crypto";
2
- import { mergeWith } from "@modern-js/utils/lodash";
3
- import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
4
- import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
5
- const PLUGIN_NAME = "ModernjsRoutePlugin";
6
- const generateContentHash = (content) => {
7
- return createHash("md5").update(content).digest("hex").slice(0, 8);
8
- };
9
- class RouterPlugin {
10
- isTargetNodeOrWebWorker(target) {
11
- if (target === "node" || Array.isArray(target) && target.includes("node")) {
12
- return true;
13
- }
14
- if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
15
- return true;
16
- }
17
- return false;
18
- }
19
- getEntryChunks(compilation, chunks) {
20
- const entrypointsArray = Array.from(compilation.entrypoints.entries());
21
- const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
22
- const entryChunks = [
23
- ...chunks
24
- ].filter((chunk) => {
25
- var _chunk_names;
26
- return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
27
- });
28
- return entryChunks;
29
- }
30
- getEntryChunkFiles(entryChunks) {
31
- return entryChunks.map((chunk) => [
32
- ...chunk.files || []
33
- ].find((fname) => fname.includes(".js")));
34
- }
35
- apply(compiler) {
36
- const { target } = compiler.options;
37
- if (this.isTargetNodeOrWebWorker(target)) {
38
- return;
39
- }
40
- const { webpack } = compiler;
41
- const isRspack = "rspackVersion" in webpack;
42
- const { Compilation, sources } = webpack;
43
- const { RawSource } = sources;
44
- const normalizePath = (path) => {
45
- if (!path.endsWith("/")) {
46
- return `${path}/`;
47
- }
48
- return path;
49
- };
50
- const chunksToHtmlName = /* @__PURE__ */ new Map();
51
- const ROUTE_MANIFEST_HOLDER = `route-manifest`;
52
- const placeholder = `<!--<?- ${ROUTE_MANIFEST_HOLDER} ?>-->`;
53
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
54
- this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", (data, callback) => {
55
- const { outputName } = data;
56
- const { chunks } = data.plugin.options;
57
- chunksToHtmlName.set(chunks, outputName);
58
- data.html = data.html.replace("</script>", `</script>${placeholder}`);
59
- callback(null, data);
60
- });
61
- compilation.hooks.processAssets.tapPromise({
62
- name: PLUGIN_NAME,
63
- stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
64
- }, async () => {
65
- const stats = compilation.getStats().toJson({
66
- all: false,
67
- publicPath: true,
68
- assets: true,
69
- chunkGroups: true,
70
- chunks: true,
71
- ids: true
72
- });
73
- const { publicPath, chunks = [], namedChunkGroups } = stats;
74
- const routeAssets = {};
75
- if (!namedChunkGroups) {
76
- return;
77
- }
78
- const prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
79
- const prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
80
- routeAssets: {}
81
- });
82
- const prevManifest = JSON.parse(prevManifestStr);
83
- for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
84
- const assets = chunkGroup.assets.map((asset) => {
85
- const filename = asset.name;
86
- return publicPath ? normalizePath(publicPath) + filename : filename;
87
- });
88
- const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
89
- routeAssets[name] = {
90
- chunkIds: chunkGroup.chunks,
91
- assets,
92
- referenceCssAssets
93
- };
94
- if (prevManifest.routeAssets[name]) {
95
- mergeWith(routeAssets[name], prevManifest.routeAssets[name], (obj, source) => {
96
- if (Array.isArray(obj)) {
97
- return obj.concat(source);
98
- }
99
- return Object.assign(source, obj);
100
- });
101
- }
102
- }
103
- const manifest = {
104
- routeAssets
105
- };
106
- const entryNames = Array.from(compilation.entrypoints.keys());
107
- let entryChunks = [];
108
- if (isRspack) {
109
- entryChunks = this.getEntryChunks(compilation, chunks);
110
- } else {
111
- const orignalEntryIds = Object.keys(compilation.options.entry).map((entryName) => {
112
- const chunk = compilation.namedChunks.get(entryName);
113
- if (chunk) {
114
- return chunk.id;
115
- }
116
- return entryName;
117
- });
118
- entryChunks = this.getEntryChunks(compilation, chunks).filter((chunk) => orignalEntryIds.includes(chunk.id));
119
- }
120
- const entryChunkFiles = this.getEntryChunkFiles(entryChunks);
121
- const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
122
- for (let i = 0; i < entryChunkFiles.length; i++) {
123
- const entryName = entryNames[i];
124
- const file = entryChunkFiles[i];
125
- const chunkNames = entryChunks[i].names;
126
- const chunkId = entryChunkFileIds[i];
127
- const asset = compilation.assets[file];
128
- if (!asset || !chunkId) {
129
- continue;
130
- }
131
- let relatedAssets = {};
132
- if (entryChunkFiles.length > 1) {
133
- Object.keys(routeAssets).forEach((routeId) => {
134
- const segments = routeId.split("_");
135
- const chunkName = segments[0];
136
- if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
137
- relatedAssets[routeId] = routeAssets[routeId];
138
- }
139
- });
140
- } else {
141
- relatedAssets = routeAssets;
142
- }
143
- const manifest2 = {
144
- routeAssets: relatedAssets
145
- };
146
- const injectedContent = `
147
- ;(function(){
148
- window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest2, (k, v) => {
149
- if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
150
- return v.map((item) => {
151
- return item.replace(publicPath, "");
152
- });
153
- }
154
- return v;
155
- })};
156
- })();
157
- `;
158
- let htmlName;
159
- for (const [chunks2, name] of chunksToHtmlName.entries()) {
160
- if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every((value, index) => value === chunks2[index])) {
161
- htmlName = name;
162
- break;
163
- }
164
- }
165
- const oldHtml = compilation.assets[htmlName];
166
- const { enableInlineRouteManifests, disableFilenameHash, staticJsDir, scriptLoading, nonce } = this;
167
- const nonceAttr = nonce ? `nonce="${nonce}"` : "";
168
- if (oldHtml) {
169
- if (enableInlineRouteManifests) {
170
- compilation.updateAsset(
171
- htmlName,
172
- new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
173
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
174
- void 0
175
- );
176
- } else {
177
- const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
178
- const scriptUrl = `${publicPath}${scriptPath}`;
179
- const scriptLoadingAttr = (
180
- // eslint-disable-next-line no-nested-ternary
181
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
182
- );
183
- const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
184
- compilation.updateAsset(
185
- htmlName,
186
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
187
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
188
- void 0
189
- );
190
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
191
- }
192
- }
193
- }
194
- if (prevManifestAsset) {
195
- compilation.updateAsset(
196
- ROUTE_MANIFEST_FILE,
197
- new RawSource(JSON.stringify(manifest, null, 2)),
198
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
199
- void 0
200
- );
201
- } else {
202
- compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
203
- }
204
- });
205
- });
206
- }
207
- constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
208
- this.name = "RouterPlugin";
209
- this.HtmlBundlerPlugin = HtmlBundlerPlugin;
210
- this.enableInlineRouteManifests = enableInlineRouteManifests;
211
- this.staticJsDir = staticJsDir;
212
- this.disableFilenameHash = disableFilenameHash;
213
- this.scriptLoading = scriptLoading;
214
- this.nonce = nonce;
215
- }
216
- }
217
- export {
218
- RouterPlugin
219
- };
@@ -1,3 +0,0 @@
1
- export * from "./HtmlAsyncChunkPlugin";
2
- export * from "./HtmlBottomTemplate";
3
- export * from "./RouterPlugin";
@@ -1,14 +0,0 @@
1
- import path from "path";
2
- function createCopyInfo(appContext, config) {
3
- const configDir = path.resolve(appContext.appDirectory, config.source.configDir || "./config");
4
- const uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
5
- const publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
6
- return {
7
- configDir,
8
- uploadDir,
9
- publicDir
10
- };
11
- }
12
- export {
13
- createCopyInfo
14
- };
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./builderPlugins";
3
- export * from "./createCopyInfo";
@@ -1,7 +0,0 @@
1
- function loader() {
2
- return `module.exports = {}`;
3
- }
4
- var serverModuleLoader_default = loader;
5
- export {
6
- serverModuleLoader_default as default
7
- };
File without changes
@@ -1,55 +0,0 @@
1
- import { ResolvedConfigContext } from "@modern-js/core";
2
- import { logger } from "@modern-js/utils";
3
- import { loadServerPlugins } from "../utils/loadPlugins";
4
- import { generateRoutes } from "../utils/routes";
5
- import { buildServerConfig } from "../utils/config";
6
- import { registerCompiler } from "../utils/register";
7
- const build = async (api, options) => {
8
- var _resolvedConfig_source;
9
- if (options === null || options === void 0 ? void 0 : options.analyze) {
10
- process.env.BUNDLE_ANALYZE = "true";
11
- }
12
- let resolvedConfig = api.useResolvedConfigContext();
13
- const appContext = api.useAppContext();
14
- const hookRunners = api.useHookRunners();
15
- await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
16
- await registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
17
- const { apiOnly } = appContext;
18
- if (apiOnly) {
19
- const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
20
- await hookRunners.beforeBuild({
21
- // "null" bundlerConfigs
22
- bundlerConfigs: void 0
23
- });
24
- await buildServerConfig({
25
- appDirectory: appDirectory2,
26
- distDirectory: distDirectory2,
27
- configFile: serverConfigFile2
28
- });
29
- await generateRoutes(appContext);
30
- await hookRunners.afterBuild({
31
- // "null" stats
32
- stats: void 0
33
- });
34
- return;
35
- }
36
- resolvedConfig = {
37
- ...resolvedConfig,
38
- cliOptions: options
39
- };
40
- ResolvedConfigContext.set(resolvedConfig);
41
- const { distDirectory, appDirectory, serverConfigFile } = appContext;
42
- await buildServerConfig({
43
- appDirectory,
44
- distDirectory,
45
- configFile: serverConfigFile
46
- });
47
- logger.info("Starting production build...");
48
- if (!appContext.builder) {
49
- throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
50
- }
51
- await appContext.builder.build();
52
- };
53
- export {
54
- build
55
- };