@modern-js/app-tools 2.5.1-alpha.0 → 2.5.1-alpha.1

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 (148) hide show
  1. package/dist/cjs/analyze/generateCode.js +19 -13
  2. package/dist/cjs/analyze/getBundleEntry.js +1 -1
  3. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +3 -3
  4. package/dist/cjs/builder/builder-webpack/index.js +11 -5
  5. package/dist/cjs/builder/generator/getBuilderTargets.js +1 -1
  6. package/dist/cjs/commands/dev.js +12 -14
  7. package/dist/cjs/commands/serve.js +17 -0
  8. package/dist/cjs/config/legacy/createToolsConfig.js +1 -4
  9. package/dist/esm/analyze/generateCode.js +37 -26
  10. package/dist/esm/analyze/getBundleEntry.js +2 -2
  11. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
  12. package/dist/esm/builder/builder-webpack/index.js +11 -7
  13. package/dist/esm/builder/generator/getBuilderTargets.js +1 -1
  14. package/dist/esm/commands/dev.js +9 -8
  15. package/dist/esm/commands/serve.js +6 -1
  16. package/dist/esm/config/legacy/createToolsConfig.js +1 -4
  17. package/dist/esm-node/analyze/generateCode.js +20 -14
  18. package/dist/esm-node/analyze/getBundleEntry.js +2 -3
  19. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
  20. package/dist/esm-node/builder/builder-webpack/index.js +12 -6
  21. package/dist/esm-node/builder/generator/getBuilderTargets.js +1 -1
  22. package/dist/esm-node/commands/dev.js +12 -14
  23. package/dist/esm-node/commands/serve.js +18 -1
  24. package/dist/esm-node/config/legacy/createToolsConfig.js +1 -4
  25. package/dist/js/modern/analyze/constants.js +3 -1
  26. package/dist/js/modern/analyze/getServerRoutes.js +5 -2
  27. package/dist/js/modern/analyze/index.js +47 -46
  28. package/dist/js/modern/analyze/nestedRoutes.js +32 -3
  29. package/dist/js/modern/analyze/templates.js +4 -10
  30. package/dist/js/modern/builder/builder-rspack/index.js +8 -0
  31. package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  32. package/dist/js/modern/builder/builder-webpack/index.js +93 -0
  33. package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
  34. package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
  35. package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
  36. package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
  37. package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
  38. package/dist/js/modern/builder/generator/index.js +53 -0
  39. package/dist/js/modern/builder/index.js +13 -133
  40. package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
  41. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  42. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  43. package/dist/js/modern/builder/shared/index.js +3 -0
  44. package/dist/js/modern/builder/shared/types.js +0 -0
  45. package/dist/js/modern/config/default.js +2 -2
  46. package/dist/js/modern/config/index.js +3 -8
  47. package/dist/js/modern/config/initialize/index.js +12 -0
  48. package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
  49. package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
  50. package/dist/js/modern/index.js +18 -8
  51. package/dist/js/modern/initialize/index.js +36 -28
  52. package/dist/js/modern/locale/zh.js +1 -1
  53. package/dist/js/modern/types/utils.js +0 -0
  54. package/dist/js/node/analyze/constants.js +3 -1
  55. package/dist/js/node/analyze/getServerRoutes.js +3 -1
  56. package/dist/js/node/analyze/index.js +48 -47
  57. package/dist/js/node/analyze/nestedRoutes.js +32 -3
  58. package/dist/js/node/analyze/templates.js +4 -10
  59. package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
  60. package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  61. package/dist/js/node/builder/builder-webpack/index.js +118 -0
  62. package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
  63. package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
  64. package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
  65. package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
  66. package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
  67. package/dist/js/node/builder/generator/index.js +82 -0
  68. package/dist/js/node/builder/index.js +14 -123
  69. package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
  70. package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
  71. package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
  72. package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
  73. package/dist/js/node/builder/shared/index.js +19 -0
  74. package/dist/js/node/builder/shared/types.js +15 -0
  75. package/dist/js/node/config/default.js +2 -2
  76. package/dist/js/node/config/index.js +4 -19
  77. package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
  78. package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
  79. package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
  80. package/dist/js/node/index.js +18 -8
  81. package/dist/js/node/initialize/index.js +35 -28
  82. package/dist/js/node/locale/zh.js +1 -1
  83. package/dist/js/node/types/utils.js +15 -0
  84. package/dist/js/treeshaking/analyze/constants.js +3 -1
  85. package/dist/js/treeshaking/analyze/generateCode.js +14 -14
  86. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
  87. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
  88. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  89. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
  90. package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
  91. package/dist/js/treeshaking/analyze/index.js +142 -137
  92. package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
  93. package/dist/js/treeshaking/analyze/templates.js +10 -13
  94. package/dist/js/treeshaking/analyze/utils.js +3 -3
  95. package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
  96. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  97. package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
  98. package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
  99. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
  100. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
  101. package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
  102. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
  103. package/dist/js/treeshaking/builder/generator/index.js +199 -0
  104. package/dist/js/treeshaking/builder/index.js +29 -228
  105. package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
  106. package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
  107. package/dist/js/treeshaking/builder/shared/index.js +3 -0
  108. package/dist/js/treeshaking/builder/shared/types.js +1 -0
  109. package/dist/js/treeshaking/commands/dev.js +2 -2
  110. package/dist/js/treeshaking/commands/serve.js +2 -2
  111. package/dist/js/treeshaking/config/default.js +2 -2
  112. package/dist/js/treeshaking/config/index.js +3 -3
  113. package/dist/js/treeshaking/config/initialize/index.js +10 -0
  114. package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
  115. package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
  116. package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
  117. package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
  118. package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
  119. package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
  120. package/dist/js/treeshaking/index.js +19 -12
  121. package/dist/js/treeshaking/initialize/index.js +36 -28
  122. package/dist/js/treeshaking/locale/zh.js +1 -1
  123. package/dist/js/treeshaking/types/utils.js +1 -0
  124. package/dist/js/treeshaking/utils/config.js +2 -2
  125. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
  126. package/dist/types/builder/builder-webpack/builderPlugins/compatModern.d.ts +7 -1
  127. package/package.json +6 -6
  128. package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
  129. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
  130. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
  131. package/dist/js/modern/config/initial/index.js +0 -16
  132. package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
  133. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
  134. package/dist/js/treeshaking/config/initial/index.js +0 -12
  135. /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
  136. /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  137. /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
  138. /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
  139. /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
  140. /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
  141. /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  142. /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
  143. /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
  144. /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
  145. /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
  146. /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
  147. /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
  148. /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
@@ -0,0 +1,199 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import { createBuilder } from "@modern-js/builder";
126
+ import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
127
+ import { getBuilderTargets } from "./getBuilderTargets";
128
+ import { createBuilderOptions } from "./createBuilderOptions";
129
+ function generateBuilder(options, generateProvider, utils) {
130
+ return _generateBuilder.apply(this, arguments);
131
+ }
132
+ function _generateBuilder() {
133
+ _generateBuilder = _asyncToGenerator(function(options, generateProvider, utils) {
134
+ var normalizedConfig, appContext, _ref, modifyBuilderConfig, modifyBuilderInstance, builderConfig, provider, target, builderOptions, builder;
135
+ return __generator(this, function(_state) {
136
+ switch(_state.label){
137
+ case 0:
138
+ normalizedConfig = options.normalizedConfig, appContext = options.appContext;
139
+ _ref = utils || {}, modifyBuilderConfig = _ref.modifyBuilderConfig, modifyBuilderInstance = _ref.modifyBuilderInstance;
140
+ builderConfig = createBuilderProviderConfig(normalizedConfig, appContext, modifyBuilderConfig);
141
+ provider = generateProvider({
142
+ builderConfig: builderConfig
143
+ });
144
+ target = getBuilderTargets(normalizedConfig);
145
+ builderOptions = createBuilderOptions(target, appContext);
146
+ return [
147
+ 4,
148
+ createBuilder(provider, builderOptions)
149
+ ];
150
+ case 1:
151
+ builder = _state.sent();
152
+ return [
153
+ 4,
154
+ applyBuilderPlugins(builder, options)
155
+ ];
156
+ case 2:
157
+ _state.sent();
158
+ return [
159
+ 4,
160
+ modifyBuilderInstance === null || modifyBuilderInstance === void 0 ? void 0 : modifyBuilderInstance(builder)
161
+ ];
162
+ case 3:
163
+ _state.sent();
164
+ return [
165
+ 2,
166
+ builder
167
+ ];
168
+ }
169
+ });
170
+ });
171
+ return _generateBuilder.apply(this, arguments);
172
+ }
173
+ function applyBuilderPlugins(builder, options) {
174
+ return _applyBuilderPlugins.apply(this, arguments);
175
+ }
176
+ function _applyBuilderPlugins() {
177
+ _applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
178
+ var builderPluginAdapterModern;
179
+ return __generator(this, function(_state) {
180
+ switch(_state.label){
181
+ case 0:
182
+ return [
183
+ 4,
184
+ import("../shared/builderPlugins/adapterModern")
185
+ ];
186
+ case 1:
187
+ builderPluginAdapterModern = _state.sent().builderPluginAdapterModern;
188
+ builder.addPlugins([
189
+ builderPluginAdapterModern(options)
190
+ ]);
191
+ return [
192
+ 2
193
+ ];
194
+ }
195
+ });
196
+ });
197
+ return _applyBuilderPlugins.apply(this, arguments);
198
+ }
199
+ export { generateBuilder };
@@ -1,11 +1,3 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithoutHoles(arr) {
7
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
- }
9
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
2
  try {
11
3
  var info = gen[key](arg);
@@ -35,75 +27,6 @@ function _asyncToGenerator(fn) {
35
27
  });
36
28
  };
37
29
  }
38
- function _defineProperty(obj, key, value) {
39
- if (key in obj) {
40
- Object.defineProperty(obj, key, {
41
- value: value,
42
- enumerable: true,
43
- configurable: true,
44
- writable: true
45
- });
46
- } else {
47
- obj[key] = value;
48
- }
49
- return obj;
50
- }
51
- function _iterableToArray(iter) {
52
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
- }
54
- function _nonIterableSpread() {
55
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
- }
57
- function _objectSpread(target) {
58
- for(var i = 1; i < arguments.length; i++){
59
- var source = arguments[i] != null ? arguments[i] : {};
60
- var ownKeys = Object.keys(source);
61
- if (typeof Object.getOwnPropertySymbols === "function") {
62
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
- }));
65
- }
66
- ownKeys.forEach(function(key) {
67
- _defineProperty(target, key, source[key]);
68
- });
69
- }
70
- return target;
71
- }
72
- function ownKeys(object, enumerableOnly) {
73
- var keys = Object.keys(object);
74
- if (Object.getOwnPropertySymbols) {
75
- var symbols = Object.getOwnPropertySymbols(object);
76
- if (enumerableOnly) {
77
- symbols = symbols.filter(function(sym) {
78
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
79
- });
80
- }
81
- keys.push.apply(keys, symbols);
82
- }
83
- return keys;
84
- }
85
- function _objectSpreadProps(target, source) {
86
- source = source != null ? source : {};
87
- if (Object.getOwnPropertyDescriptors) {
88
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
89
- } else {
90
- ownKeys(Object(source)).forEach(function(key) {
91
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
- });
93
- }
94
- return target;
95
- }
96
- function _toConsumableArray(arr) {
97
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
98
- }
99
- function _unsupportedIterableToArray(o, minLen) {
100
- if (!o) return;
101
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
102
- var n = Object.prototype.toString.call(o).slice(8, -1);
103
- if (n === "Object" && o.constructor) n = o.constructor.name;
104
- if (n === "Map" || n === "Set") return Array.from(n);
105
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
106
- }
107
30
  var __generator = this && this.__generator || function(thisArg, body) {
108
31
  var f, y, t, g, _ = {
109
32
  label: 0,
@@ -199,176 +122,54 @@ var __generator = this && this.__generator || function(thisArg, body) {
199
122
  };
200
123
  }
201
124
  };
202
- import { createBuilder } from "@modern-js/builder";
203
- import { builderWebpackProvider } from "@modern-js/builder-webpack-provider";
204
- import { applyOptionsChain, isProd, isSSR, isUseSSRBundle } from "@modern-js/utils";
205
- import { PluginCompatModern } from "./builderPlugins/compatModern";
206
- import { createCopyPattern } from "./share";
207
- function getBuilderTargets(normalizedConfig) {
208
- var targets = [
209
- "web"
210
- ];
211
- var useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
212
- if (useNodeTarget) {
213
- targets.push("node");
214
- }
215
- return targets;
125
+ function createBuilderGenerator(bundler) {
126
+ return _createBuilderGenerator.apply(this, arguments);
216
127
  }
217
- function createBuilderForModern(_) {
218
- return _createBuilderForModern.apply(this, arguments);
219
- }
220
- function _createBuilderForModern() {
221
- _createBuilderForModern = _asyncToGenerator(function(param) {
222
- var normalizedConfig, appContext, compatPluginConfig, builderConfig, webpackProvider, target, builderOptions, builder;
128
+ function _createBuilderGenerator() {
129
+ _createBuilderGenerator = _asyncToGenerator(function(bundler) {
130
+ var createRspackBuilderForModern, _, createWebpackBuilderForModern;
223
131
  return __generator(this, function(_state) {
224
132
  switch(_state.label){
225
133
  case 0:
226
- normalizedConfig = param.normalizedConfig, appContext = param.appContext, compatPluginConfig = param.compatPluginConfig;
227
- builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
228
- webpackProvider = builderWebpackProvider({
229
- builderConfig: builderConfig
230
- });
231
- target = getBuilderTargets(normalizedConfig);
232
- builderOptions = createBuilderOptions(target, appContext);
233
- return [
234
- 4,
235
- createBuilder(webpackProvider, builderOptions)
134
+ if (!(bundler === "rspack")) return [
135
+ 3,
136
+ 4
236
137
  ];
138
+ _state.label = 1;
237
139
  case 1:
238
- builder = _state.sent();
140
+ _state.trys.push([
141
+ 1,
142
+ 3,
143
+ ,
144
+ 4
145
+ ]);
239
146
  return [
240
147
  4,
241
- applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig)
148
+ import("./builder-rspack")
242
149
  ];
243
150
  case 2:
244
- _state.sent();
151
+ createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
245
152
  return [
246
153
  2,
247
- builder
154
+ createRspackBuilderForModern
248
155
  ];
249
- }
250
- });
251
- });
252
- return _createBuilderForModern.apply(this, arguments);
253
- }
254
- function createBuilderProviderConfig(normalizedConfig, appContext) {
255
- var createOutputConfig = function createOutputConfig(config, appContext2) {
256
- var defaultCopyPattern = createCopyPattern(appContext2, config, "upload");
257
- var copy = config.output.copy;
258
- var copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
259
- var builderCopy = _toConsumableArray(copyOptions || []).concat([
260
- defaultCopyPattern
261
- ]);
262
- return _objectSpreadProps(_objectSpread({}, config.output), {
263
- copy: builderCopy,
264
- cleanDistPath: false
265
- });
266
- };
267
- var output = createOutputConfig(normalizedConfig, appContext);
268
- var htmlConfig = _objectSpread({}, normalizedConfig.html);
269
- if (!htmlConfig.template) {
270
- htmlConfig.templateByEntries = _objectSpread({}, htmlConfig.templateByEntries, appContext.htmlTemplates);
271
- }
272
- return _objectSpreadProps(_objectSpread({}, normalizedConfig), {
273
- output: output,
274
- dev: _objectSpreadProps(_objectSpread({}, normalizedConfig.dev), {
275
- port: appContext.port
276
- }),
277
- html: htmlConfig
278
- });
279
- }
280
- function createBuilderOptions(target, appContext) {
281
- var entries = {};
282
- var _entrypoints = appContext.entrypoints, entrypoints = _entrypoints === void 0 ? [] : _entrypoints, checkedEntries = appContext.checkedEntries;
283
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
284
- try {
285
- for(var _iterator = entrypoints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
286
- var _value = _step.value, entryName = _value.entryName, entry = _value.entry;
287
- if (checkedEntries && !checkedEntries.includes(entryName)) {
288
- continue;
289
- }
290
- if (entryName in entries) {
291
- entries[entryName].push(entry);
292
- } else {
293
- entries[entryName] = [
294
- entry
295
- ];
296
- }
297
- }
298
- } catch (err) {
299
- _didIteratorError = true;
300
- _iteratorError = err;
301
- } finally{
302
- try {
303
- if (!_iteratorNormalCompletion && _iterator.return != null) {
304
- _iterator.return();
305
- }
306
- } finally{
307
- if (_didIteratorError) {
308
- throw _iteratorError;
309
- }
310
- }
311
- }
312
- return {
313
- cwd: appContext.appDirectory,
314
- target: target,
315
- configPath: appContext.configFile || void 0,
316
- entry: entries,
317
- framework: appContext.metaName
318
- };
319
- }
320
- function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
321
- return _applyBuilderPlugins.apply(this, arguments);
322
- }
323
- function _applyBuilderPlugins() {
324
- _applyBuilderPlugins = _asyncToGenerator(function(builder, normalizedConfig, appContext, compatPluginConfig) {
325
- var builderPluginNodePolyfill, _tools, esbuildOptions, builderPluginEsbuild;
326
- return __generator(this, function(_state) {
327
- switch(_state.label){
328
- case 0:
329
- if (!!normalizedConfig.output.disableNodePolyfill) return [
330
- 3,
331
- 2
332
- ];
333
- return [
334
- 4,
335
- import("@modern-js/builder-plugin-node-polyfill")
336
- ];
337
- case 1:
338
- builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
339
- builder.addPlugins([
340
- builderPluginNodePolyfill()
341
- ]);
342
- _state.label = 2;
343
- case 2:
344
- if (!normalizedConfig.tools.esbuild) return [
345
- 3,
346
- 4
347
- ];
348
- _tools = normalizedConfig.tools, esbuildOptions = _tools.esbuild;
156
+ case 3:
157
+ _ = _state.sent();
158
+ throw new Error("Failed to use rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
159
+ case 4:
349
160
  return [
350
161
  4,
351
- import("@modern-js/builder-plugin-esbuild")
162
+ import("./builder-webpack")
352
163
  ];
353
- case 3:
354
- builderPluginEsbuild = _state.sent().builderPluginEsbuild;
355
- builder.addPlugins([
356
- builderPluginEsbuild({
357
- loader: false,
358
- minimize: applyOptionsChain({}, esbuildOptions)
359
- })
360
- ]);
361
- _state.label = 4;
362
- case 4:
363
- builder.addPlugins([
364
- PluginCompatModern(appContext, normalizedConfig, compatPluginConfig)
365
- ]);
164
+ case 5:
165
+ createWebpackBuilderForModern = _state.sent().createWebpackBuilderForModern;
366
166
  return [
367
- 2
167
+ 2,
168
+ createWebpackBuilderForModern
368
169
  ];
369
170
  }
370
171
  });
371
172
  });
372
- return _applyBuilderPlugins.apply(this, arguments);
173
+ return _createBuilderGenerator.apply(this, arguments);
373
174
  }
374
- export { createBuilderForModern, createBuilderOptions, createBuilderProviderConfig };
175
+ export { createBuilderGenerator };