@modern-js/app-tools 2.3.1-alpha.1 → 2.4.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 (168) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +14 -18
  3. package/dist/js/modern/analyze/index.js +45 -48
  4. package/dist/js/modern/analyze/nestedRoutes.js +10 -1
  5. package/dist/js/modern/analyze/templates.js +2 -9
  6. package/dist/js/modern/builder/builder-rspack/index.js +8 -0
  7. package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  8. package/dist/js/modern/builder/builder-webpack/index.js +93 -0
  9. package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +1 -1
  10. package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
  11. package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
  12. package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
  13. package/dist/js/modern/builder/generator/getBuilderTargets.js +12 -0
  14. package/dist/js/modern/builder/generator/index.js +53 -0
  15. package/dist/js/modern/builder/index.js +13 -133
  16. package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +81 -111
  17. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  18. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  19. package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
  20. package/dist/js/modern/builder/shared/index.js +3 -0
  21. package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  22. package/dist/js/modern/builder/shared/types.js +0 -0
  23. package/dist/js/modern/config/default.js +2 -2
  24. package/dist/js/modern/config/index.js +3 -8
  25. package/dist/js/modern/config/initialize/index.js +12 -0
  26. package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
  27. package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
  28. package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
  29. package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
  30. package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
  31. package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
  32. package/dist/js/modern/index.js +18 -8
  33. package/dist/js/modern/initialize/index.js +36 -28
  34. package/dist/js/modern/locale/zh.js +1 -1
  35. package/dist/js/modern/types/utils.js +0 -0
  36. package/dist/js/node/analyze/index.js +46 -49
  37. package/dist/js/node/analyze/nestedRoutes.js +10 -1
  38. package/dist/js/node/analyze/templates.js +2 -9
  39. package/dist/js/node/builder/builder-rspack/index.js +31 -0
  40. package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  41. package/dist/js/node/builder/builder-webpack/index.js +118 -0
  42. package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +7 -5
  43. package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
  44. package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
  45. package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
  46. package/dist/js/node/builder/{loaders/routerLoader.js → generator/getBuilderTargets.js} +13 -16
  47. package/dist/js/node/builder/generator/index.js +82 -0
  48. package/dist/js/node/builder/index.js +14 -123
  49. package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +86 -115
  50. package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
  51. package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
  52. package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
  53. package/dist/js/node/builder/shared/index.js +19 -0
  54. package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  55. package/dist/js/node/builder/shared/types.js +15 -0
  56. package/dist/js/node/config/default.js +2 -2
  57. package/dist/js/node/config/index.js +4 -19
  58. package/dist/js/node/config/{initial → initialize}/index.js +10 -16
  59. package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
  60. package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
  61. package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
  62. package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
  63. package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
  64. package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
  65. package/dist/js/node/index.js +18 -8
  66. package/dist/js/node/initialize/index.js +35 -28
  67. package/dist/js/node/locale/zh.js +1 -1
  68. package/dist/js/node/types/utils.js +15 -0
  69. package/dist/js/treeshaking/analyze/index.js +135 -130
  70. package/dist/js/treeshaking/analyze/nestedRoutes.js +10 -1
  71. package/dist/js/treeshaking/analyze/templates.js +3 -7
  72. package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
  73. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  74. package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
  75. package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +1 -1
  76. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
  77. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
  78. package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
  79. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +12 -0
  80. package/dist/js/treeshaking/builder/generator/index.js +199 -0
  81. package/dist/js/treeshaking/builder/index.js +29 -228
  82. package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +103 -156
  83. package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
  84. package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +0 -0
  85. package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
  86. package/dist/js/treeshaking/builder/shared/index.js +3 -0
  87. package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  88. package/dist/js/treeshaking/builder/shared/types.js +1 -0
  89. package/dist/js/treeshaking/config/default.js +2 -2
  90. package/dist/js/treeshaking/config/index.js +3 -3
  91. package/dist/js/treeshaking/config/initialize/index.js +10 -0
  92. package/dist/js/treeshaking/config/{initial → initialize}/inits.js +4 -2
  93. package/dist/js/treeshaking/config/{initial → legacy}/createHtmlConfig.js +0 -0
  94. package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +0 -0
  95. package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +0 -0
  96. package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +0 -0
  97. package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
  98. package/dist/js/treeshaking/index.js +19 -12
  99. package/dist/js/treeshaking/initialize/index.js +34 -26
  100. package/dist/js/treeshaking/locale/zh.js +1 -1
  101. package/dist/js/treeshaking/types/utils.js +1 -0
  102. package/dist/types/analyze/generateCode.d.ts +1 -1
  103. package/dist/types/analyze/getBundleEntry.d.ts +1 -1
  104. package/dist/types/analyze/getFileSystemEntry.d.ts +1 -1
  105. package/dist/types/analyze/getHtmlTemplate.d.ts +2 -2
  106. package/dist/types/analyze/getServerRoutes.d.ts +1 -1
  107. package/dist/types/analyze/index.d.ts +5 -1
  108. package/dist/types/builder/builder-rspack/index.d.ts +2 -0
  109. package/dist/types/builder/{builderPlugins → builder-webpack/builderPlugins}/compatModern.d.ts +2 -2
  110. package/dist/types/builder/builder-webpack/index.d.ts +4 -0
  111. package/dist/types/builder/{webpackPlugins/routerPlugin.d.ts → builder-webpack/webpackPlugins/RouterPlugin.d.ts} +1 -1
  112. package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +1 -0
  113. package/dist/types/builder/generator/createBuilderOptions.d.ts +3 -0
  114. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +2 -0
  115. package/dist/types/builder/generator/getBuilderTargets.d.ts +3 -0
  116. package/dist/types/builder/generator/index.d.ts +17 -0
  117. package/dist/types/builder/index.d.ts +1 -18
  118. package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +13 -0
  119. package/dist/types/builder/{webpackPlugins/htmlAsyncChunkPlugin.d.ts → shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts} +2 -1
  120. package/dist/types/builder/{webpackPlugins/htmlBottomTemplate.d.ts → shared/bundlerPlugins/HtmlBottomTemplate.d.ts} +2 -1
  121. package/dist/types/builder/{share.d.ts → shared/createCopyPattern.d.ts} +1 -1
  122. package/dist/types/builder/shared/index.d.ts +3 -0
  123. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +4 -0
  124. package/dist/types/builder/shared/types.d.ts +16 -0
  125. package/dist/types/commands/build.d.ts +1 -1
  126. package/dist/types/commands/deploy.d.ts +1 -1
  127. package/dist/types/commands/dev.d.ts +1 -1
  128. package/dist/types/commands/inspect.d.ts +1 -1
  129. package/dist/types/commands/serve.d.ts +1 -1
  130. package/dist/types/config/default.d.ts +1 -1
  131. package/dist/types/config/index.d.ts +3 -2
  132. package/dist/types/config/initialize/index.d.ts +2 -0
  133. package/dist/types/config/{initial → initialize}/inits.d.ts +3 -3
  134. package/dist/types/config/{initial → legacy}/createHtmlConfig.d.ts +1 -1
  135. package/dist/types/config/{initial → legacy}/createOutputConfig.d.ts +1 -1
  136. package/dist/types/config/{initial → legacy}/createSourceConfig.d.ts +1 -1
  137. package/dist/types/config/{initial → legacy}/createToolsConfig.d.ts +1 -1
  138. package/dist/types/config/legacy/index.d.ts +3 -0
  139. package/dist/types/defineConfig.d.ts +3 -2
  140. package/dist/types/index.d.ts +7 -3
  141. package/dist/types/initialize/index.d.ts +6 -2
  142. package/dist/types/types/config/deploy.d.ts +1 -2
  143. package/dist/types/types/config/dev.d.ts +2 -3
  144. package/dist/types/types/config/experiments.d.ts +1 -2
  145. package/dist/types/types/config/html.d.ts +5 -3
  146. package/dist/types/types/config/index.d.ts +41 -48
  147. package/dist/types/types/config/output.d.ts +8 -3
  148. package/dist/types/types/config/performance.d.ts +6 -3
  149. package/dist/types/types/config/security.d.ts +3 -3
  150. package/dist/types/types/config/source.d.ts +7 -3
  151. package/dist/types/types/config/tools.d.ts +10 -4
  152. package/dist/types/types/hooks.d.ts +4 -3
  153. package/dist/types/types/index.d.ts +16 -6
  154. package/dist/types/types/utils.d.ts +7 -0
  155. package/dist/types/utils/config.d.ts +1 -1
  156. package/dist/types/utils/getServerInternalPlugins.d.ts +1 -1
  157. package/dist/types/utils/printInstructions.d.ts +1 -1
  158. package/package.json +34 -25
  159. package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
  160. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
  161. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
  162. package/dist/js/modern/config/initial/index.js +0 -16
  163. package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
  164. package/dist/js/treeshaking/config/initial/index.js +0 -12
  165. package/dist/types/builder/loaders/routerLoader.d.ts +0 -3
  166. package/dist/types/builder/loaders/serverModuleLoader.d.ts +0 -3
  167. package/dist/types/config/initial/index.d.ts +0 -4
  168. package/dist/types/config/initial/transformNormalizedConfig.d.ts +0 -2
@@ -15,24 +15,21 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var routerLoader_exports = {};
19
- __export(routerLoader_exports, {
20
- default: () => routerLoader_default
18
+ var getBuilderTargets_exports = {};
19
+ __export(getBuilderTargets_exports, {
20
+ getBuilderTargets: () => getBuilderTargets
21
21
  });
22
- module.exports = __toCommonJS(routerLoader_exports);
22
+ module.exports = __toCommonJS(getBuilderTargets_exports);
23
23
  var import_utils = require("@modern-js/utils");
24
- function loader(source) {
25
- this.cacheable();
26
- const { target } = this._compiler.options;
27
- if (target === "node" || Array.isArray(target) && target.includes("node")) {
28
- return source;
24
+ function getBuilderTargets(normalizedConfig) {
25
+ const targets = ["web"];
26
+ const useNodeTarget = (0, import_utils.isProd)() ? (0, import_utils.isUseSSRBundle)(normalizedConfig) : (0, import_utils.isSSR)(normalizedConfig);
27
+ if (useNodeTarget) {
28
+ targets.push("node");
29
29
  }
30
- const { resourcePath } = this;
31
- const code = `
32
- export { default } from "${(0, import_utils.slash)(resourcePath)}";
33
- `;
34
- return code;
30
+ return targets;
35
31
  }
36
- var routerLoader_default = loader;
37
32
  // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {});
33
+ 0 && (module.exports = {
34
+ getBuilderTargets
35
+ });
@@ -0,0 +1,82 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var __async = (__this, __arguments, generator) => {
25
+ return new Promise((resolve, reject) => {
26
+ var fulfilled = (value) => {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var rejected = (value) => {
34
+ try {
35
+ step(generator.throw(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
+ step((generator = generator.apply(__this, __arguments)).next());
42
+ });
43
+ };
44
+ var generator_exports = {};
45
+ __export(generator_exports, {
46
+ generateBuilder: () => generateBuilder
47
+ });
48
+ module.exports = __toCommonJS(generator_exports);
49
+ var import_builder = require("@modern-js/builder");
50
+ var import_createBuilderProviderConfig = require("./createBuilderProviderConfig");
51
+ var import_getBuilderTargets = require("./getBuilderTargets");
52
+ var import_createBuilderOptions = require("./createBuilderOptions");
53
+ function generateBuilder(options, generateProvider, utils) {
54
+ return __async(this, null, function* () {
55
+ const { normalizedConfig, appContext } = options;
56
+ const { modifyBuilderConfig, modifyBuilderInstance } = utils || {};
57
+ const builderConfig = (0, import_createBuilderProviderConfig.createBuilderProviderConfig)(
58
+ normalizedConfig,
59
+ appContext,
60
+ modifyBuilderConfig
61
+ );
62
+ const provider = generateProvider({
63
+ builderConfig
64
+ });
65
+ const target = (0, import_getBuilderTargets.getBuilderTargets)(normalizedConfig);
66
+ const builderOptions = (0, import_createBuilderOptions.createBuilderOptions)(target, appContext);
67
+ const builder = yield (0, import_builder.createBuilder)(provider, builderOptions);
68
+ yield applyBuilderPlugins(builder, options);
69
+ yield modifyBuilderInstance == null ? void 0 : modifyBuilderInstance(builder);
70
+ return builder;
71
+ });
72
+ }
73
+ function applyBuilderPlugins(builder, options) {
74
+ return __async(this, null, function* () {
75
+ const { builderPluginAdapterModern } = yield Promise.resolve().then(() => __toESM(require("../shared/builderPlugins/adapterModern")));
76
+ builder.addPlugins([builderPluginAdapterModern(options)]);
77
+ });
78
+ }
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ generateBuilder
82
+ });
@@ -1,26 +1,9 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
7
  var __export = (target, all) => {
25
8
  for (var name in all)
26
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -60,118 +43,26 @@ var __async = (__this, __arguments, generator) => {
60
43
  };
61
44
  var builder_exports = {};
62
45
  __export(builder_exports, {
63
- createBuilderForModern: () => createBuilderForModern,
64
- createBuilderOptions: () => createBuilderOptions,
65
- createBuilderProviderConfig: () => createBuilderProviderConfig
46
+ createBuilderGenerator: () => createBuilderGenerator
66
47
  });
67
48
  module.exports = __toCommonJS(builder_exports);
68
- var import_builder = require("@modern-js/builder");
69
- var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
70
- var import_utils = require("@modern-js/utils");
71
- var import_compatModern = require("./builderPlugins/compatModern");
72
- var import_share = require("./share");
73
- function getBuilderTargets(normalizedConfig) {
74
- const targets = ["web"];
75
- const useNodeTarget = (0, import_utils.isProd)() ? (0, import_utils.isUseSSRBundle)(normalizedConfig) : (0, import_utils.isSSR)(normalizedConfig);
76
- if (useNodeTarget) {
77
- targets.push("node");
78
- }
79
- return targets;
80
- }
81
- function createBuilderForModern(_0) {
82
- return __async(this, arguments, function* ({
83
- normalizedConfig,
84
- appContext,
85
- compatPluginConfig
86
- }) {
87
- const builderConfig = createBuilderProviderConfig(
88
- normalizedConfig,
89
- appContext
90
- );
91
- const webpackProvider = (0, import_builder_webpack_provider.builderWebpackProvider)({
92
- builderConfig
93
- });
94
- const target = getBuilderTargets(normalizedConfig);
95
- const builderOptions = createBuilderOptions(target, appContext);
96
- const builder = yield (0, import_builder.createBuilder)(webpackProvider, builderOptions);
97
- yield applyBuilderPlugins(
98
- builder,
99
- normalizedConfig,
100
- appContext,
101
- compatPluginConfig
102
- );
103
- return builder;
104
- });
105
- }
106
- function createBuilderProviderConfig(normalizedConfig, appContext) {
107
- const output = createOutputConfig(normalizedConfig, appContext);
108
- const htmlConfig = __spreadValues({}, normalizedConfig.html);
109
- if (!htmlConfig.template) {
110
- htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
111
- }
112
- return __spreadProps(__spreadValues({}, normalizedConfig), {
113
- output,
114
- dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
115
- port: appContext.port
116
- }),
117
- html: htmlConfig
118
- });
119
- function createOutputConfig(config, appContext2) {
120
- const defaultCopyPattern = (0, import_share.createCopyPattern)(appContext2, config, "upload");
121
- const { copy } = config.output;
122
- const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
123
- const builderCopy = [...copyOptions || [], defaultCopyPattern];
124
- return __spreadProps(__spreadValues({}, config.output), {
125
- copy: builderCopy,
126
- cleanDistPath: false
127
- });
128
- }
129
- }
130
- function createBuilderOptions(target, appContext) {
131
- const entries = {};
132
- const { entrypoints = [], checkedEntries } = appContext;
133
- for (const { entryName, entry } of entrypoints) {
134
- if (checkedEntries && !checkedEntries.includes(entryName)) {
135
- continue;
136
- }
137
- if (entryName in entries) {
138
- entries[entryName].push(entry);
139
- } else {
140
- entries[entryName] = [entry];
141
- }
142
- }
143
- return {
144
- cwd: appContext.appDirectory,
145
- target,
146
- configPath: appContext.configFile || void 0,
147
- entry: entries,
148
- framework: appContext.metaName
149
- };
150
- }
151
- function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
49
+ function createBuilderGenerator(bundler) {
152
50
  return __async(this, null, function* () {
153
- if (!normalizedConfig.output.disableNodePolyfill) {
154
- const { builderPluginNodePolyfill } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
155
- builder.addPlugins([builderPluginNodePolyfill()]);
156
- }
157
- if (normalizedConfig.tools.esbuild) {
158
- const { esbuild: esbuildOptions } = normalizedConfig.tools;
159
- const { builderPluginEsbuild } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
160
- builder.addPlugins([
161
- builderPluginEsbuild({
162
- loader: false,
163
- minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
164
- })
165
- ]);
51
+ if (bundler === "rspack") {
52
+ try {
53
+ const { createRspackBuilderForModern } = yield Promise.resolve().then(() => __toESM(require("./builder-rspack")));
54
+ return createRspackBuilderForModern;
55
+ } catch (_) {
56
+ throw new Error(
57
+ "Failed to use rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
58
+ );
59
+ }
166
60
  }
167
- builder.addPlugins([
168
- (0, import_compatModern.PluginCompatModern)(appContext, normalizedConfig, compatPluginConfig)
169
- ]);
61
+ const { createWebpackBuilderForModern } = yield Promise.resolve().then(() => __toESM(require("./builder-webpack")));
62
+ return createWebpackBuilderForModern;
170
63
  });
171
64
  }
172
65
  // Annotate the CommonJS export names for ESM import in node:
173
66
  0 && (module.exports = {
174
- createBuilderForModern,
175
- createBuilderOptions,
176
- createBuilderProviderConfig
67
+ createBuilderGenerator
177
68
  });
@@ -38,25 +38,39 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
38
38
  mod
39
39
  ));
40
40
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
- var compatModern_exports = {};
42
- __export(compatModern_exports, {
43
- PluginCompatModern: () => PluginCompatModern
41
+ var adapterModern_exports = {};
42
+ __export(adapterModern_exports, {
43
+ applyCallbacks: () => applyCallbacks,
44
+ builderPluginAdapterModern: () => builderPluginAdapterModern
44
45
  });
45
- module.exports = __toCommonJS(compatModern_exports);
46
- var import_path = require("path");
46
+ module.exports = __toCommonJS(adapterModern_exports);
47
47
  var import_builder_shared = require("@modern-js/builder-shared");
48
- var import_lodash = require("@modern-js/utils/lodash");
49
- var import_html_webpack_plugin = __toESM(require("@modern-js/builder-webpack-provider/html-webpack-plugin"));
50
48
  var import_utils = require("@modern-js/utils");
51
- var import_htmlBottomTemplate = require("../webpackPlugins/htmlBottomTemplate");
52
- var import_htmlAsyncChunkPlugin = require("../webpackPlugins/htmlAsyncChunkPlugin");
53
- var import_share = require("../share");
54
- var import_routerPlugin = __toESM(require("../webpackPlugins/routerPlugin"));
55
- const PluginCompatModern = (appContext, modernConfig, options) => ({
56
- name: "builder-plugin-compat-modern",
49
+ var import_html_webpack_plugin = __toESM(require("@modern-js/builder-webpack-provider/html-webpack-plugin"));
50
+ var import_lodash = require("@modern-js/utils/lodash");
51
+ var import_HtmlAsyncChunkPlugin = require("../bundlerPlugins/HtmlAsyncChunkPlugin");
52
+ var import_HtmlBottomTemplate = require("../bundlerPlugins/HtmlBottomTemplate");
53
+ const isStreamingSSR = (userConfig) => {
54
+ const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
55
+ const { server } = userConfig;
56
+ if (isStreaming(server.ssr)) {
57
+ return true;
58
+ }
59
+ if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
60
+ for (const name of Object.keys(server.ssrByEntries)) {
61
+ if (isStreaming(server.ssrByEntries[name])) {
62
+ return true;
63
+ }
64
+ }
65
+ }
66
+ return false;
67
+ };
68
+ const builderPluginAdapterModern = (options) => ({
69
+ name: "builder-plugin-adapter-modern",
57
70
  setup(api) {
71
+ const { normalizedConfig, appContext } = options;
58
72
  api.modifyBuilderConfig((config) => {
59
- if (isStreamingSSR(modernConfig)) {
73
+ if (isStreamingSSR(normalizedConfig)) {
60
74
  return (0, import_builder_shared.mergeBuilderConfig)(config, {
61
75
  html: {
62
76
  inject: "body"
@@ -65,9 +79,8 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
65
79
  }
66
80
  return config;
67
81
  });
68
- api.modifyWebpackChain((chain, { target, CHAIN_ID, isProd }) => {
69
- var _a;
70
- const builderNormalizedConfig = api.getNormalizedConfig();
82
+ api.modifyBundlerChain((chain, { target, CHAIN_ID, isProd }) => {
83
+ const builderConfig = api.getNormalizedConfig();
71
84
  if (target === "node") {
72
85
  chain.name("server");
73
86
  } else if (target === "modern-web") {
@@ -75,61 +88,33 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
75
88
  } else {
76
89
  chain.name("client");
77
90
  }
78
- chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
79
91
  if (target === "node") {
80
- applyNodeCompat(chain, modernConfig, isProd);
92
+ applyNodeCompat(chain, normalizedConfig, isProd);
81
93
  }
82
- if (isHtmlEnabled(builderNormalizedConfig, target)) {
83
- applyBottomHtmlWebpackPlugin({
94
+ if (isHtmlEnabled(builderConfig, target)) {
95
+ applyBottomHtmlPlugin({
84
96
  api,
85
97
  chain,
86
- CHAIN_ID,
98
+ modernConfig: normalizedConfig,
87
99
  appContext,
88
- modernConfig
100
+ CHAIN_ID
89
101
  });
90
102
  applyAsyncChunkHtmlPlugin({
91
103
  chain,
92
- CHAIN_ID,
93
- modernConfig
104
+ modernConfig: normalizedConfig,
105
+ CHAIN_ID
94
106
  });
95
107
  }
96
- if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
97
- const defaultCopyPattern = (0, import_share.createCopyPattern)(
98
- appContext,
99
- modernConfig,
100
- "public",
101
- chain
102
- );
103
- chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
104
- var _a2;
105
- return [
106
- {
107
- patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
108
- }
109
- ];
110
- });
111
- }
112
- const { entrypoints } = appContext;
113
- const existNestedRoutes = entrypoints.some(
114
- (entrypoint) => entrypoint.nestedRoutesEntry
115
- );
116
- const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
117
- const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
118
- if (existNestedRoutes || routerManifest) {
119
- chain.plugin("route-plugin").use(import_routerPlugin.default);
120
- }
121
108
  if (target !== "node") {
122
109
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
123
110
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
124
111
  chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
125
112
  }
126
- function isHtmlEnabled(config, target2) {
127
- var _a2;
128
- return ((_a2 = config.tools) == null ? void 0 : _a2.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
129
- }
130
113
  });
131
- if (options) {
132
- applyCallbacks(api, options);
114
+ applyCallbacks(api, options);
115
+ function isHtmlEnabled(config, target) {
116
+ var _a;
117
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "web-worker";
133
118
  }
134
119
  }
135
120
  });
@@ -143,6 +128,49 @@ function applyCallbacks(api, options) {
143
128
  options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
144
129
  options.onExit && api.onExit(options.onExit);
145
130
  }
131
+ function applyBottomHtmlPlugin({
132
+ api,
133
+ chain,
134
+ modernConfig,
135
+ appContext,
136
+ CHAIN_ID
137
+ }) {
138
+ for (const entryName of Object.keys(api.context.entry)) {
139
+ const baseTemplateParams = __spreadValues({
140
+ entryName,
141
+ title: (0, import_utils.getEntryOptions)(
142
+ entryName,
143
+ modernConfig.html.title,
144
+ modernConfig.html.titleByEntries,
145
+ appContext.packageName
146
+ ),
147
+ mountId: modernConfig.html.mountId
148
+ }, (0, import_utils.getEntryOptions)(
149
+ entryName,
150
+ modernConfig.html.templateParameters,
151
+ modernConfig.html.templateParametersByEntries,
152
+ appContext.packageName
153
+ ));
154
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
155
+ __spreadProps(__spreadValues({}, args[0] || {}), {
156
+ __internal__: true,
157
+ bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
158
+ baseTemplateParams
159
+ )
160
+ })
161
+ ]);
162
+ }
163
+ chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_HtmlBottomTemplate.BottomTemplatePlugin, [import_html_webpack_plugin.default]);
164
+ }
165
+ function applyAsyncChunkHtmlPlugin({
166
+ chain,
167
+ modernConfig,
168
+ CHAIN_ID
169
+ }) {
170
+ if (isStreamingSSR(modernConfig)) {
171
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_HtmlAsyncChunkPlugin.HtmlAsyncChunkPlugin, [import_html_webpack_plugin.default]);
172
+ }
173
+ }
146
174
  function applyNodeCompat(chain, modernConfig, isProd) {
147
175
  for (const ext of [
148
176
  ".node.js",
@@ -194,65 +222,8 @@ function applyNodeCompat(chain, modernConfig, isProd) {
194
222
  });
195
223
  }
196
224
  }
197
- function applyBottomHtmlWebpackPlugin({
198
- api,
199
- chain,
200
- modernConfig,
201
- appContext,
202
- CHAIN_ID
203
- }) {
204
- for (const entryName of Object.keys(api.context.entry)) {
205
- const baseTemplateParams = __spreadValues({
206
- entryName,
207
- title: (0, import_utils.getEntryOptions)(
208
- entryName,
209
- modernConfig.html.title,
210
- modernConfig.html.titleByEntries,
211
- appContext.packageName
212
- ),
213
- mountId: modernConfig.html.mountId
214
- }, (0, import_utils.getEntryOptions)(
215
- entryName,
216
- modernConfig.html.templateParameters,
217
- modernConfig.html.templateParametersByEntries,
218
- appContext.packageName
219
- ));
220
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
221
- __spreadProps(__spreadValues({}, args[0] || {}), {
222
- __internal__: true,
223
- bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
224
- baseTemplateParams
225
- )
226
- })
227
- ]);
228
- }
229
- chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_htmlBottomTemplate.BottomTemplatePlugin, [import_html_webpack_plugin.default]);
230
- }
231
- const isStreamingSSR = (userConfig) => {
232
- const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
233
- const { server } = userConfig;
234
- if (isStreaming(server.ssr)) {
235
- return true;
236
- }
237
- if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
238
- for (const name of Object.keys(server.ssrByEntries)) {
239
- if (isStreaming(server.ssrByEntries[name])) {
240
- return true;
241
- }
242
- }
243
- }
244
- return false;
245
- };
246
- function applyAsyncChunkHtmlPlugin({
247
- chain,
248
- modernConfig,
249
- CHAIN_ID
250
- }) {
251
- if (isStreamingSSR(modernConfig)) {
252
- chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_htmlAsyncChunkPlugin.HtmlAsyncChunkPlugin, [import_html_webpack_plugin.default]);
253
- }
254
- }
255
225
  // Annotate the CommonJS export names for ESM import in node:
256
226
  0 && (module.exports = {
257
- PluginCompatModern
227
+ applyCallbacks,
228
+ builderPluginAdapterModern
258
229
  });
@@ -15,36 +15,33 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var htmlAsyncChunkPlugin_exports = {};
19
- __export(htmlAsyncChunkPlugin_exports, {
18
+ var HtmlAsyncChunkPlugin_exports = {};
19
+ __export(HtmlAsyncChunkPlugin_exports, {
20
20
  HtmlAsyncChunkPlugin: () => HtmlAsyncChunkPlugin
21
21
  });
22
- module.exports = __toCommonJS(htmlAsyncChunkPlugin_exports);
22
+ module.exports = __toCommonJS(HtmlAsyncChunkPlugin_exports);
23
23
  class HtmlAsyncChunkPlugin {
24
24
  constructor(htmlWebpackPlugin) {
25
25
  this.name = "HtmlAsyncChunkPlugin";
26
26
  this.htmlWebpackPlugin = htmlWebpackPlugin;
27
27
  }
28
28
  apply(compiler) {
29
- compiler.hooks.compilation.tap(
30
- this.name,
31
- (compilation) => {
32
- const hooks = this.htmlWebpackPlugin.getHooks(compilation);
33
- hooks.alterAssetTagGroups.tap(this.name, (assets) => {
34
- const tags = [...assets.headTags, ...assets.bodyTags];
35
- for (const tag of tags) {
36
- if (tag.tagName === "script") {
37
- const { attributes } = tag;
38
- if (attributes && attributes.defer === true) {
39
- attributes.async = true;
40
- delete attributes.defer;
41
- }
29
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
30
+ const hooks = this.htmlWebpackPlugin.getHooks(compilation);
31
+ hooks.alterAssetTagGroups.tap(this.name, (assets) => {
32
+ const tags = [...assets.headTags, ...assets.bodyTags];
33
+ for (const tag of tags) {
34
+ if (tag.tagName === "script") {
35
+ const { attributes } = tag;
36
+ if (attributes && attributes.defer === true) {
37
+ attributes.async = true;
38
+ delete attributes.defer;
42
39
  }
43
40
  }
44
- return assets;
45
- });
46
- }
47
- );
41
+ }
42
+ return assets;
43
+ });
44
+ });
48
45
  }
49
46
  }
50
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -15,11 +15,11 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var htmlBottomTemplate_exports = {};
19
- __export(htmlBottomTemplate_exports, {
18
+ var HtmlBottomTemplate_exports = {};
19
+ __export(HtmlBottomTemplate_exports, {
20
20
  BottomTemplatePlugin: () => BottomTemplatePlugin
21
21
  });
22
- module.exports = __toCommonJS(htmlBottomTemplate_exports);
22
+ module.exports = __toCommonJS(HtmlBottomTemplate_exports);
23
23
  class BottomTemplatePlugin {
24
24
  constructor(htmlWebpackPlugin) {
25
25
  this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
@@ -28,30 +28,27 @@ class BottomTemplatePlugin {
28
28
  this.name = "bottom-template";
29
29
  }
30
30
  apply(compiler) {
31
- compiler.hooks.compilation.tap(
32
- this.name,
33
- (compilation) => {
34
- this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
35
- var _a;
36
- if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
37
- return data;
38
- }
39
- if (this.bottomTemplateReg.test(data.html)) {
40
- data.html = data.html.replace(this.bottomTemplateReg, "");
41
- const { bottomTemplate } = data.plugin.options;
42
- if (bottomTemplate) {
43
- data.html = data.html.replace(
44
- this.bodyRegExp,
45
- (match) => `
31
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
32
+ this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
33
+ var _a;
34
+ if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
35
+ return data;
36
+ }
37
+ if (this.bottomTemplateReg.test(data.html)) {
38
+ data.html = data.html.replace(this.bottomTemplateReg, "");
39
+ const { bottomTemplate } = data.plugin.options;
40
+ if (bottomTemplate) {
41
+ data.html = data.html.replace(
42
+ this.bodyRegExp,
43
+ (match) => `
46
44
  ${bottomTemplate}
47
45
  ${match}`
48
- );
49
- }
46
+ );
50
47
  }
51
- return data;
52
- });
53
- }
54
- );
48
+ }
49
+ return data;
50
+ });
51
+ });
55
52
  }
56
53
  }
57
54
  // Annotate the CommonJS export names for ESM import in node:
@@ -21,11 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  mod
22
22
  ));
23
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var share_exports = {};
25
- __export(share_exports, {
24
+ var createCopyPattern_exports = {};
25
+ __export(createCopyPattern_exports, {
26
26
  createCopyPattern: () => createCopyPattern
27
27
  });
28
- module.exports = __toCommonJS(share_exports);
28
+ module.exports = __toCommonJS(createCopyPattern_exports);
29
29
  var import_path = __toESM(require("path"));
30
30
  var import_utils = require("@modern-js/utils");
31
31
  function createCopyPattern(appContext, config, patternsType, chain) {