@modern-js/app-tools 2.58.2 → 2.59.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 (269) hide show
  1. package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
  2. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -3
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
  5. package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
  6. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  7. package/dist/cjs/commands/build.js +2 -2
  8. package/dist/cjs/commands/dev.js +6 -5
  9. package/dist/cjs/commands/index.js +1 -1
  10. package/dist/cjs/commands/serve.js +4 -3
  11. package/dist/cjs/config/legacy/index.js +3 -3
  12. package/dist/cjs/esm/register-esm.mjs +2 -3
  13. package/dist/cjs/esm/utils.mjs +2 -2
  14. package/dist/cjs/index.js +17 -10
  15. package/dist/cjs/locale/index.js +1 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
  17. package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
  18. package/dist/cjs/plugins/analyze/index.js +6 -6
  19. package/dist/cjs/plugins/analyze/utils.js +1 -1
  20. package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
  21. package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
  22. package/dist/cjs/plugins/deploy/index.js +2 -2
  23. package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
  24. package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
  25. package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
  26. package/dist/cjs/plugins/serverBuild.js +2 -2
  27. package/dist/cjs/utils/createServer.js +1 -1
  28. package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
  29. package/dist/esm/builder/builder-rspack/index.js +34 -0
  30. package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
  31. package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
  32. package/dist/esm/builder/builder-webpack/index.js +52 -0
  33. package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
  34. package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
  35. package/dist/esm/builder/generator/index.js +93 -0
  36. package/dist/esm/builder/index.js +45 -0
  37. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
  38. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
  39. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
  40. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  41. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
  42. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
  43. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
  44. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  45. package/dist/esm/builder/shared/createCopyInfo.js +14 -0
  46. package/dist/esm/builder/shared/index.js +3 -0
  47. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
  48. package/dist/esm/builder/shared/types.js +0 -0
  49. package/dist/esm/commands/build.js +140 -0
  50. package/dist/esm/commands/deploy.js +48 -0
  51. package/dist/esm/commands/dev.js +193 -0
  52. package/dist/esm/commands/index.js +411 -0
  53. package/dist/esm/commands/inspect.js +28 -0
  54. package/dist/esm/commands/serve.js +94 -0
  55. package/dist/esm/config/default.js +190 -0
  56. package/dist/esm/config/index.js +3 -0
  57. package/dist/esm/config/initialize/index.js +9 -0
  58. package/dist/esm/config/initialize/inits.js +89 -0
  59. package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
  60. package/dist/esm/config/legacy/createOutputConfig.js +45 -0
  61. package/dist/esm/config/legacy/createSourceConfig.js +46 -0
  62. package/dist/esm/config/legacy/createToolsConfig.js +28 -0
  63. package/dist/esm/config/legacy/index.js +43 -0
  64. package/dist/esm/defineConfig.js +16 -0
  65. package/dist/esm/esm/esbuild-loader.mjs +20 -0
  66. package/dist/esm/esm/register-esm.mjs +66 -0
  67. package/dist/esm/esm/ts-node-loader.mjs +21 -0
  68. package/dist/esm/esm/utils.mjs +43 -0
  69. package/dist/esm/exports/server.js +4 -0
  70. package/dist/esm/hooks.js +34 -0
  71. package/dist/esm/index.js +246 -0
  72. package/dist/esm/locale/en.js +43 -0
  73. package/dist/esm/locale/index.js +12 -0
  74. package/dist/esm/locale/zh.js +43 -0
  75. package/dist/esm/plugins/analyze/constants.js +14 -0
  76. package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
  77. package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
  78. package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
  79. package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
  80. package/dist/esm/plugins/analyze/index.js +380 -0
  81. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
  82. package/dist/esm/plugins/analyze/templates.js +6 -0
  83. package/dist/esm/plugins/analyze/utils.js +101 -0
  84. package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
  85. package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
  86. package/dist/esm/plugins/deploy/exports.js +4 -0
  87. package/dist/esm/plugins/deploy/index.js +135 -0
  88. package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
  89. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  90. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
  91. package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
  92. package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
  93. package/dist/esm/plugins/deploy/platforms/node.js +161 -0
  94. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  95. package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
  96. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  97. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
  98. package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
  99. package/dist/esm/plugins/deploy/utils.js +47 -0
  100. package/dist/esm/plugins/initialize/index.js +119 -0
  101. package/dist/esm/plugins/serverBuild.js +87 -0
  102. package/dist/esm/types/config/deploy.js +0 -0
  103. package/dist/esm/types/config/dev.js +0 -0
  104. package/dist/esm/types/config/experiments.js +0 -0
  105. package/dist/esm/types/config/html.js +0 -0
  106. package/dist/esm/types/config/index.js +1 -0
  107. package/dist/esm/types/config/output.js +0 -0
  108. package/dist/esm/types/config/performance.js +0 -0
  109. package/dist/esm/types/config/security.js +0 -0
  110. package/dist/esm/types/config/source.js +0 -0
  111. package/dist/esm/types/config/testing.js +0 -0
  112. package/dist/esm/types/config/tools.js +0 -0
  113. package/dist/esm/types/hooks.js +0 -0
  114. package/dist/esm/types/index.js +3 -0
  115. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  116. package/dist/esm/types/legacyConfig/dev.js +0 -0
  117. package/dist/esm/types/legacyConfig/index.js +0 -0
  118. package/dist/esm/types/legacyConfig/output.js +0 -0
  119. package/dist/esm/types/legacyConfig/source.js +0 -0
  120. package/dist/esm/types/legacyConfig/testing.js +0 -0
  121. package/dist/esm/types/legacyConfig/tools.js +0 -0
  122. package/dist/esm/types/utils.js +0 -0
  123. package/dist/esm/utils/config.js +122 -0
  124. package/dist/esm/utils/createServer.js +58 -0
  125. package/dist/esm/utils/env.js +16 -0
  126. package/dist/esm/utils/generateWatchFiles.js +71 -0
  127. package/dist/esm/utils/getSelectedEntries.js +67 -0
  128. package/dist/esm/utils/loadPlugins.js +74 -0
  129. package/dist/esm/utils/printInstructions.js +32 -0
  130. package/dist/esm/utils/register.js +188 -0
  131. package/dist/esm/utils/restart.js +67 -0
  132. package/dist/esm/utils/routes.js +42 -0
  133. package/dist/esm/utils/types.js +0 -0
  134. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
  135. package/dist/esm-node/builder/builder-rspack/index.js +12 -0
  136. package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
  137. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
  138. package/dist/esm-node/builder/builder-webpack/index.js +20 -0
  139. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
  140. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  141. package/dist/esm-node/builder/generator/index.js +36 -0
  142. package/dist/esm-node/builder/index.js +11 -0
  143. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
  144. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
  145. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
  146. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  147. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
  148. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
  149. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
  150. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  151. package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
  152. package/dist/esm-node/builder/shared/index.js +3 -0
  153. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
  154. package/dist/esm-node/builder/shared/types.js +0 -0
  155. package/dist/esm-node/commands/build.js +64 -0
  156. package/dist/esm-node/commands/deploy.js +12 -0
  157. package/dist/esm-node/commands/dev.js +105 -0
  158. package/dist/esm-node/commands/index.js +92 -0
  159. package/dist/esm-node/commands/inspect.js +15 -0
  160. package/dist/esm-node/commands/serve.js +52 -0
  161. package/dist/esm-node/config/default.js +197 -0
  162. package/dist/esm-node/config/index.js +3 -0
  163. package/dist/esm-node/config/initialize/index.js +9 -0
  164. package/dist/esm-node/config/initialize/inits.js +79 -0
  165. package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
  166. package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
  167. package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
  168. package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
  169. package/dist/esm-node/config/legacy/index.js +43 -0
  170. package/dist/esm-node/defineConfig.js +13 -0
  171. package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
  172. package/dist/esm-node/esm/register-esm.mjs +66 -0
  173. package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
  174. package/dist/esm-node/esm/utils.mjs +43 -0
  175. package/dist/esm-node/exports/server.js +4 -0
  176. package/dist/esm-node/hooks.js +34 -0
  177. package/dist/esm-node/index.js +131 -0
  178. package/dist/esm-node/locale/en.js +43 -0
  179. package/dist/esm-node/locale/index.js +12 -0
  180. package/dist/esm-node/locale/zh.js +43 -0
  181. package/dist/esm-node/plugins/analyze/constants.js +14 -0
  182. package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
  183. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
  184. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
  185. package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
  186. package/dist/esm-node/plugins/analyze/index.js +166 -0
  187. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
  188. package/dist/esm-node/plugins/analyze/templates.js +24 -0
  189. package/dist/esm-node/plugins/analyze/utils.js +68 -0
  190. package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
  191. package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
  192. package/dist/esm-node/plugins/deploy/exports.js +4 -0
  193. package/dist/esm-node/plugins/deploy/index.js +44 -0
  194. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
  195. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  196. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
  197. package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
  198. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
  199. package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
  200. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  201. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
  202. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  203. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
  204. package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
  205. package/dist/esm-node/plugins/deploy/utils.js +44 -0
  206. package/dist/esm-node/plugins/initialize/index.js +84 -0
  207. package/dist/esm-node/plugins/serverBuild.js +58 -0
  208. package/dist/esm-node/types/config/deploy.js +0 -0
  209. package/dist/esm-node/types/config/dev.js +0 -0
  210. package/dist/esm-node/types/config/experiments.js +0 -0
  211. package/dist/esm-node/types/config/html.js +0 -0
  212. package/dist/esm-node/types/config/index.js +1 -0
  213. package/dist/esm-node/types/config/output.js +0 -0
  214. package/dist/esm-node/types/config/performance.js +0 -0
  215. package/dist/esm-node/types/config/security.js +0 -0
  216. package/dist/esm-node/types/config/source.js +0 -0
  217. package/dist/esm-node/types/config/testing.js +0 -0
  218. package/dist/esm-node/types/config/tools.js +0 -0
  219. package/dist/esm-node/types/hooks.js +0 -0
  220. package/dist/esm-node/types/index.js +3 -0
  221. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  222. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  223. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  224. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  225. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  226. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  227. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  228. package/dist/esm-node/types/utils.js +0 -0
  229. package/dist/esm-node/utils/config.js +49 -0
  230. package/dist/esm-node/utils/createServer.js +26 -0
  231. package/dist/esm-node/utils/env.js +16 -0
  232. package/dist/esm-node/utils/generateWatchFiles.js +30 -0
  233. package/dist/esm-node/utils/getSelectedEntries.js +34 -0
  234. package/dist/esm-node/utils/loadPlugins.js +22 -0
  235. package/dist/esm-node/utils/printInstructions.js +11 -0
  236. package/dist/esm-node/utils/register.js +96 -0
  237. package/dist/esm-node/utils/restart.js +22 -0
  238. package/dist/esm-node/utils/routes.js +21 -0
  239. package/dist/esm-node/utils/types.js +0 -0
  240. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
  241. package/dist/types/builder/generator/index.d.ts +2 -2
  242. package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
  243. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
  244. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
  245. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  246. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
  247. package/dist/types/builder/shared/types.d.ts +1 -1
  248. package/dist/types/commands/build.d.ts +1 -1
  249. package/dist/types/commands/dev.d.ts +1 -1
  250. package/dist/types/commands/inspect.d.ts +1 -1
  251. package/dist/types/config/default.d.ts +1 -1
  252. package/dist/types/index.d.ts +1 -1
  253. package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
  254. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
  255. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
  256. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
  257. package/dist/types/plugins/initialize/index.d.ts +1 -1
  258. package/dist/types/plugins/serverBuild.d.ts +1 -1
  259. package/dist/types/types/config/index.d.ts +8 -8
  260. package/dist/types/types/config/output.d.ts +1 -1
  261. package/dist/types/types/config/tools.d.ts +3 -3
  262. package/dist/types/types/hooks.d.ts +2 -2
  263. package/dist/types/types/index.d.ts +2 -2
  264. package/dist/types/types/legacyConfig/index.d.ts +3 -3
  265. package/dist/types/types/legacyConfig/tools.d.ts +1 -1
  266. package/dist/types/utils/printInstructions.d.ts +1 -1
  267. package/package.json +20 -20
  268. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
  269. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,48 @@
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
+ };
@@ -0,0 +1,60 @@
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
+ };
@@ -0,0 +1,151 @@
1
+ import * as path from "path";
2
+ import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/uni-builder";
3
+ import { fs, isUseSSRBundle } from "@modern-js/utils";
4
+ import { mergeRsbuildConfig } from "@rsbuild/core";
5
+ import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
6
+ import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
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) ? 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
+ const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
28
+ if (target === "node" || isServiceWorker) {
29
+ applyFilterEntriesBySSRConfig({
30
+ isProd,
31
+ chain,
32
+ appNormalizedConfig: normalizedConfig2
33
+ });
34
+ }
35
+ if (isUseSSRBundle(normalizedConfig2)) {
36
+ await applySSRLoaderEntry(chain, options, isServer);
37
+ applySSRDataLoader(chain, options);
38
+ }
39
+ if (!isHtmlDisabled(builderConfig, target)) {
40
+ applyAsyncChunkHtmlPlugin({
41
+ chain,
42
+ modernConfig: options.normalizedConfig,
43
+ HtmlBundlerPlugin
44
+ });
45
+ }
46
+ });
47
+ }
48
+ });
49
+ const isStreamingSSR = (userConfig) => {
50
+ const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
51
+ const { server } = userConfig;
52
+ if (isStreaming(server.ssr)) {
53
+ return true;
54
+ }
55
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
56
+ for (const name of Object.keys(server.ssrByEntries)) {
57
+ if (isStreaming(server.ssrByEntries[name])) {
58
+ return true;
59
+ }
60
+ }
61
+ }
62
+ return false;
63
+ };
64
+ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
65
+ if (isStreamingSSR(modernConfig)) {
66
+ chain.plugin("html-async-chunk").use(HtmlAsyncChunkPlugin, [
67
+ HtmlBundlerPlugin
68
+ ]);
69
+ }
70
+ }
71
+ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
72
+ var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
73
+ const { appContext, normalizedConfig } = options;
74
+ const { entrypoints } = appContext;
75
+ const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
76
+ const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
77
+ const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
78
+ const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
79
+ const { enableInlineRouteManifests, disableInlineRouteManifests } = normalizedConfig.output;
80
+ const inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
81
+ if (existNestedRoutes || routerManifest || workerSSR) {
82
+ var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
83
+ chain.plugin(pluginName).use(RouterPlugin, [
84
+ {
85
+ HtmlBundlerPlugin,
86
+ enableInlineRouteManifests: inlineRouteManifests,
87
+ 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,
88
+ disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
89
+ scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
90
+ nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
91
+ }
92
+ ]);
93
+ }
94
+ }
95
+ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
96
+ var _this;
97
+ const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
98
+ const entries = chain.entryPoints.entries();
99
+ 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")) {
100
+ return;
101
+ }
102
+ if (typeof entries === "undefined") {
103
+ throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
104
+ }
105
+ const entryNames = Object.keys(entries);
106
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
107
+ return;
108
+ }
109
+ const ssgEntries = [];
110
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
111
+ const { ssg } = outputConfig;
112
+ entryNames.forEach((name) => {
113
+ if (ssg[name]) {
114
+ ssgEntries.push(name);
115
+ }
116
+ });
117
+ }
118
+ const { ssr, ssrByEntries } = serverConfig || {};
119
+ entryNames.forEach((name) => {
120
+ 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]))) {
121
+ chain.entryPoints.delete(name);
122
+ }
123
+ });
124
+ }
125
+ async function applySSRLoaderEntry(chain, optinos, isServer) {
126
+ const { appContext } = optinos;
127
+ const { internalDirectory } = appContext;
128
+ const { entrypoints } = appContext;
129
+ await Promise.all(entrypoints.map(async (entrypoint) => {
130
+ const { entryName } = entrypoint;
131
+ const serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
132
+ if (isServer) {
133
+ try {
134
+ await fs.access(serverLoadersFile, fs.constants.F_OK);
135
+ chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
136
+ } catch (err) {
137
+ }
138
+ }
139
+ }));
140
+ }
141
+ function applySSRDataLoader(chain, options) {
142
+ const { normalizedConfig, appContext } = options;
143
+ const { appDirectory } = appContext;
144
+ const { entriesDir = "./src" } = normalizedConfig.source;
145
+ const absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
146
+ const reg = new RegExp(`${absolutePath}.*\\.(loader|data|data.client)\\.[t|j]sx?$`);
147
+ chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
148
+ }
149
+ export {
150
+ builderPluginAdapterSSR
151
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./adapterBasic";
2
+ export * from "./adapterHtml";
3
+ export * from "./adapterSSR";
@@ -0,0 +1,30 @@
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
+ };
@@ -0,0 +1,31 @@
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
+ };
@@ -0,0 +1,228 @@
1
+ import { createHash } from "crypto";
2
+ import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
3
+ import { merge, mergeWith } from "@modern-js/utils/lodash";
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
+ const asyncEntryNames = [];
84
+ for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
85
+ if (name.startsWith("async-")) {
86
+ asyncEntryNames.push(name);
87
+ }
88
+ const assets = chunkGroup.assets.map((asset) => {
89
+ const filename = asset.name;
90
+ return publicPath ? normalizePath(publicPath) + filename : filename;
91
+ });
92
+ const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
93
+ routeAssets[name] = {
94
+ chunkIds: chunkGroup.chunks,
95
+ assets,
96
+ referenceCssAssets
97
+ };
98
+ if (prevManifest.routeAssets[name]) {
99
+ mergeWith(routeAssets[name], prevManifest.routeAssets[name], (obj, source) => {
100
+ if (Array.isArray(obj)) {
101
+ return obj.concat(source);
102
+ }
103
+ return Object.assign(source, obj);
104
+ });
105
+ }
106
+ }
107
+ if (asyncEntryNames.length > 0) {
108
+ for (const asyncEntryName of asyncEntryNames) {
109
+ const syncEntryName = asyncEntryName.replace("async-", "");
110
+ const syncEntry = routeAssets[syncEntryName];
111
+ const asyncEntry = routeAssets[asyncEntryName];
112
+ merge(syncEntry, asyncEntry);
113
+ }
114
+ }
115
+ const manifest = {
116
+ routeAssets
117
+ };
118
+ const entryNames = Array.from(compilation.entrypoints.keys());
119
+ let entryChunks = [];
120
+ if (isRspack) {
121
+ entryChunks = this.getEntryChunks(compilation, chunks);
122
+ } else {
123
+ const orignalEntryIds = Object.keys(compilation.options.entry).map((entryName) => {
124
+ const chunk = compilation.namedChunks.get(entryName);
125
+ if (chunk) {
126
+ return chunk.id;
127
+ }
128
+ return entryName;
129
+ });
130
+ entryChunks = this.getEntryChunks(compilation, chunks).filter((chunk) => orignalEntryIds.includes(chunk.id));
131
+ }
132
+ const entryChunkFiles = this.getEntryChunkFiles(entryChunks);
133
+ const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
134
+ for (let i = 0; i < entryChunkFiles.length; i++) {
135
+ const entryName = entryNames[i];
136
+ const file = entryChunkFiles[i];
137
+ const chunkNames = entryChunks[i].names;
138
+ const chunkId = entryChunkFileIds[i];
139
+ const asset = compilation.assets[file];
140
+ if (!asset || !chunkId) {
141
+ continue;
142
+ }
143
+ let relatedAssets = {};
144
+ if (entryChunkFiles.length > 1) {
145
+ Object.keys(routeAssets).forEach((routeId) => {
146
+ const segments = routeId.split("_");
147
+ const chunkName = segments[0];
148
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
149
+ relatedAssets[routeId] = routeAssets[routeId];
150
+ }
151
+ });
152
+ } else {
153
+ relatedAssets = routeAssets;
154
+ }
155
+ const manifest2 = {
156
+ routeAssets: relatedAssets
157
+ };
158
+ const injectedContent = `
159
+ ;(function(){
160
+ window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest2, (k, v) => {
161
+ if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
162
+ return v.map((item) => {
163
+ return item.replace(publicPath, "");
164
+ });
165
+ }
166
+ return v;
167
+ })};
168
+ })();
169
+ `;
170
+ let htmlName;
171
+ for (const [chunks2, name] of chunksToHtmlName.entries()) {
172
+ if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every((value, index) => value === chunks2[index])) {
173
+ htmlName = name;
174
+ break;
175
+ }
176
+ }
177
+ const oldHtml = compilation.assets[htmlName];
178
+ const { enableInlineRouteManifests, disableFilenameHash, staticJsDir, scriptLoading, nonce } = this;
179
+ const nonceAttr = nonce ? `nonce="${nonce}"` : "";
180
+ if (oldHtml) {
181
+ if (enableInlineRouteManifests) {
182
+ compilation.updateAsset(
183
+ htmlName,
184
+ new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
185
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
186
+ void 0
187
+ );
188
+ } else {
189
+ const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
190
+ const scriptUrl = `${publicPath}${scriptPath}`;
191
+ const scriptLoadingAttr = scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : "";
192
+ const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
193
+ compilation.updateAsset(
194
+ htmlName,
195
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
196
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
197
+ void 0
198
+ );
199
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
200
+ }
201
+ }
202
+ }
203
+ if (prevManifestAsset) {
204
+ compilation.updateAsset(
205
+ ROUTE_MANIFEST_FILE,
206
+ new RawSource(JSON.stringify(manifest, null, 2)),
207
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
208
+ void 0
209
+ );
210
+ } else {
211
+ compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
212
+ }
213
+ });
214
+ });
215
+ }
216
+ constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
217
+ this.name = "RouterPlugin";
218
+ this.HtmlBundlerPlugin = HtmlBundlerPlugin;
219
+ this.enableInlineRouteManifests = enableInlineRouteManifests;
220
+ this.staticJsDir = staticJsDir;
221
+ this.disableFilenameHash = disableFilenameHash;
222
+ this.scriptLoading = scriptLoading;
223
+ this.nonce = nonce;
224
+ }
225
+ }
226
+ export {
227
+ RouterPlugin
228
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./HtmlAsyncChunkPlugin";
2
+ export * from "./HtmlBottomTemplate";
3
+ export * from "./RouterPlugin";
@@ -0,0 +1,14 @@
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
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./builderPlugins";
3
+ export * from "./createCopyInfo";
@@ -0,0 +1,7 @@
1
+ function loader() {
2
+ return `module.exports = {}`;
3
+ }
4
+ var serverModuleLoader_default = loader;
5
+ export {
6
+ serverModuleLoader_default as default
7
+ };
File without changes
@@ -0,0 +1,64 @@
1
+ import { ResolvedConfigContext } from "@modern-js/core";
2
+ import { logger } from "@modern-js/utils";
3
+ import { buildServerConfig } from "../utils/config";
4
+ import { loadServerPlugins } from "../utils/loadPlugins";
5
+ import { registerCompiler } from "../utils/register";
6
+ import { generateRoutes } from "../utils/routes";
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
+ if (appContext.moduleType && appContext.moduleType === "module") {
17
+ var _resolvedConfig_source1;
18
+ const { registerEsm } = await import("../esm/register-esm.mjs");
19
+ await registerEsm({
20
+ appDir: appContext.appDirectory,
21
+ distDir: appContext.distDirectory,
22
+ alias: (_resolvedConfig_source1 = resolvedConfig.source) === null || _resolvedConfig_source1 === void 0 ? void 0 : _resolvedConfig_source1.alias
23
+ });
24
+ }
25
+ 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);
26
+ const { apiOnly } = appContext;
27
+ if (apiOnly) {
28
+ const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
29
+ await hookRunners.beforeBuild({
30
+ // "null" bundlerConfigs
31
+ bundlerConfigs: void 0
32
+ });
33
+ await buildServerConfig({
34
+ appDirectory: appDirectory2,
35
+ distDirectory: distDirectory2,
36
+ configFile: serverConfigFile2
37
+ });
38
+ await generateRoutes(appContext);
39
+ await hookRunners.afterBuild({
40
+ // "null" stats
41
+ stats: void 0
42
+ });
43
+ return;
44
+ }
45
+ resolvedConfig = {
46
+ ...resolvedConfig,
47
+ cliOptions: options
48
+ };
49
+ ResolvedConfigContext.set(resolvedConfig);
50
+ const { distDirectory, appDirectory, serverConfigFile } = appContext;
51
+ await buildServerConfig({
52
+ appDirectory,
53
+ distDirectory,
54
+ configFile: serverConfigFile
55
+ });
56
+ logger.info("Starting production build...");
57
+ if (!appContext.builder) {
58
+ throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
59
+ }
60
+ await appContext.builder.build();
61
+ };
62
+ export {
63
+ build
64
+ };
@@ -0,0 +1,12 @@
1
+ import { getServerPlugins } from "../utils/loadPlugins";
2
+ const deploy = async (api, options) => {
3
+ const hookRunners = api.useHookRunners();
4
+ const { metaName } = api.useAppContext();
5
+ await getServerPlugins(api, metaName);
6
+ await hookRunners.beforeDeploy(options);
7
+ await hookRunners.deploy(options);
8
+ await hookRunners.afterDeploy(options);
9
+ };
10
+ export {
11
+ deploy
12
+ };