@modern-js/builder 2.26.0 → 2.28.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 (60) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/createBuilder.d.ts +1 -1
  3. package/dist/createBuilder.js +48 -38
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +24 -8
  6. package/dist/plugins/antd.d.ts +1 -1
  7. package/dist/plugins/antd.js +51 -31
  8. package/dist/plugins/arco.d.ts +1 -1
  9. package/dist/plugins/arco.js +41 -34
  10. package/dist/plugins/asset.d.ts +1 -1
  11. package/dist/plugins/asset.js +29 -25
  12. package/dist/plugins/assetsRetry.d.ts +1 -1
  13. package/dist/plugins/assetsRetry.js +34 -51
  14. package/dist/plugins/bundleAnalyzer.d.ts +1 -1
  15. package/dist/plugins/bundleAnalyzer.js +29 -50
  16. package/dist/plugins/cache.d.ts +1 -1
  17. package/dist/plugins/cache.js +68 -87
  18. package/dist/plugins/checkSyntax.d.ts +1 -1
  19. package/dist/plugins/checkSyntax.js +40 -54
  20. package/dist/plugins/cleanOutput.d.ts +1 -1
  21. package/dist/plugins/cleanOutput.js +22 -38
  22. package/dist/plugins/devtool.d.ts +1 -1
  23. package/dist/plugins/devtool.js +23 -21
  24. package/dist/plugins/entry.d.ts +1 -1
  25. package/dist/plugins/entry.js +23 -19
  26. package/dist/plugins/externals.d.ts +1 -1
  27. package/dist/plugins/externals.js +28 -25
  28. package/dist/plugins/fileSize.d.ts +1 -1
  29. package/dist/plugins/fileSize.js +124 -130
  30. package/dist/plugins/html.d.ts +1 -1
  31. package/dist/plugins/html.js +204 -206
  32. package/dist/plugins/index.d.ts +1 -1
  33. package/dist/plugins/index.js +41 -53
  34. package/dist/plugins/inlineChunk.d.ts +1 -1
  35. package/dist/plugins/inlineChunk.js +50 -59
  36. package/dist/plugins/moment.d.ts +1 -1
  37. package/dist/plugins/moment.js +23 -20
  38. package/dist/plugins/nodeAddons.d.ts +2 -0
  39. package/dist/plugins/nodeAddons.js +48 -0
  40. package/dist/plugins/rem.d.ts +1 -1
  41. package/dist/plugins/rem.js +73 -98
  42. package/dist/plugins/sourceBuild.d.ts +8 -14
  43. package/dist/plugins/sourceBuild.js +81 -111
  44. package/dist/plugins/splitChunks.d.ts +1 -1
  45. package/dist/plugins/splitChunks.js +206 -229
  46. package/dist/plugins/startUrl.d.ts +1 -1
  47. package/dist/plugins/startUrl.js +62 -78
  48. package/dist/plugins/svg.d.ts +1 -1
  49. package/dist/plugins/svg.js +64 -81
  50. package/dist/plugins/target.d.ts +1 -1
  51. package/dist/plugins/target.js +52 -31
  52. package/dist/plugins/toml.d.ts +1 -1
  53. package/dist/plugins/toml.js +16 -15
  54. package/dist/plugins/tsChecker.d.ts +1 -1
  55. package/dist/plugins/tsChecker.js +79 -92
  56. package/dist/plugins/wasm.d.ts +1 -1
  57. package/dist/plugins/wasm.js +31 -32
  58. package/dist/plugins/yaml.d.ts +1 -1
  59. package/dist/plugins/yaml.js +16 -15
  60. package/package.json +11 -9
@@ -1,255 +1,232 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
17
4
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.builderPluginSplitChunks = exports.createDependenciesRegExp = void 0;
30
- const assert_1 = __importDefault(require("assert"));
31
- const builder_shared_1 = require("@modern-js/builder-shared");
32
- function getUserDefinedCacheGroups(forceSplitting) {
33
- const cacheGroups = {};
34
- const pairs = Array.isArray(forceSplitting)
35
- ? forceSplitting.map((regexp, index) => [`force-split-${index}`, regexp])
36
- : Object.entries(forceSplitting);
37
- pairs.forEach(([key, regexp]) => {
38
- cacheGroups[key] = {
39
- test: regexp,
40
- name: key,
41
- chunks: 'all',
42
- // Ignore minimum size, minimum chunks and maximum requests and always create chunks for user defined cache group.
43
- enforce: true,
44
- };
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
45
10
  });
46
- return cacheGroups;
11
+ }
12
+ _export(exports, {
13
+ createDependenciesRegExp: function() {
14
+ return createDependenciesRegExp;
15
+ },
16
+ builderPluginSplitChunks: function() {
17
+ return builderPluginSplitChunks;
18
+ }
19
+ });
20
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
22
+ const _assert = /* @__PURE__ */ _interop_require_default._(require("assert"));
23
+ const _buildershared = require("@modern-js/builder-shared");
24
+ function getUserDefinedCacheGroups(forceSplitting) {
25
+ const cacheGroups = {};
26
+ const pairs = Array.isArray(forceSplitting) ? forceSplitting.map((regexp, index) => [
27
+ `force-split-${index}`,
28
+ regexp
29
+ ]) : Object.entries(forceSplitting);
30
+ pairs.forEach(([key, regexp]) => {
31
+ cacheGroups[key] = {
32
+ test: regexp,
33
+ name: key,
34
+ chunks: "all",
35
+ // Ignore minimum size, minimum chunks and maximum requests and always create chunks for user defined cache group.
36
+ enforce: true
37
+ };
38
+ });
39
+ return cacheGroups;
47
40
  }
48
41
  const DEPENDENCY_MATCH_TEMPL = /[\\/]node_modules[\\/](<SOURCES>)[\\/]/.source;
49
- /** Expect to match path just like "./node_modules/react-router/" */
50
42
  const createDependenciesRegExp = (...dependencies) => {
51
- const sources = dependencies.map(d => (typeof d === 'string' ? d : d.source));
52
- const expr = DEPENDENCY_MATCH_TEMPL.replace('<SOURCES>', sources.join('|'));
53
- return new RegExp(expr);
43
+ const sources = dependencies.map((d) => typeof d === "string" ? d : d.source);
44
+ const expr = DEPENDENCY_MATCH_TEMPL.replace("<SOURCES>", sources.join("|"));
45
+ return new RegExp(expr);
54
46
  };
55
- exports.createDependenciesRegExp = createDependenciesRegExp;
56
47
  async function splitByExperience(ctx) {
57
- const { isPackageInstalled } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
58
- const { override, polyfill, rootPath, defaultConfig, userDefinedCacheGroups, } = ctx;
59
- const experienceCacheGroup = {};
60
- const packageRegExps = {
61
- react: (0, exports.createDependenciesRegExp)('react', 'react-dom'),
62
- router: (0, exports.createDependenciesRegExp)('react-router', 'react-router-dom', '@remix-run/router', 'history'),
63
- lodash: (0, exports.createDependenciesRegExp)('lodash', 'lodash-es'),
64
- axios: (0, exports.createDependenciesRegExp)('axios', /axios-.+/),
48
+ const { isPackageInstalled } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
49
+ const { override, polyfill, rootPath, defaultConfig, userDefinedCacheGroups } = ctx;
50
+ const experienceCacheGroup = {};
51
+ const packageRegExps = {
52
+ react: createDependenciesRegExp("react", "react-dom"),
53
+ router: createDependenciesRegExp("react-router", "react-router-dom", "@remix-run/router", "history"),
54
+ lodash: createDependenciesRegExp("lodash", "lodash-es"),
55
+ axios: createDependenciesRegExp("axios", /axios-.+/)
56
+ };
57
+ if (isPackageInstalled("antd", rootPath)) {
58
+ packageRegExps.antd = createDependenciesRegExp("antd");
59
+ }
60
+ if (isPackageInstalled("@arco-design/web-react", rootPath)) {
61
+ packageRegExps.arco = createDependenciesRegExp(/@?arco-design/);
62
+ }
63
+ if (isPackageInstalled("@douyinfe/semi-ui", rootPath)) {
64
+ packageRegExps.semi = createDependenciesRegExp(/@(ies|douyinfe)[\\/]semi-.*/);
65
+ }
66
+ if (polyfill === "entry" || polyfill === "usage") {
67
+ packageRegExps.polyfill = createDependenciesRegExp("core-js", "@babel/runtime", "@swc/helpers");
68
+ }
69
+ Object.entries(packageRegExps).forEach(([name, test]) => {
70
+ const key = `lib-${name}`;
71
+ experienceCacheGroup[key] = {
72
+ test,
73
+ priority: 0,
74
+ name: key,
75
+ reuseExistingChunk: true
65
76
  };
66
- // Detect if the package is installed in current project
67
- // If installed, add the package to cache group
68
- if (isPackageInstalled('antd', rootPath)) {
69
- packageRegExps.antd = (0, exports.createDependenciesRegExp)('antd');
70
- }
71
- if (isPackageInstalled('@arco-design/web-react', rootPath)) {
72
- packageRegExps.arco = (0, exports.createDependenciesRegExp)(/@?arco-design/);
73
- }
74
- if (isPackageInstalled('@douyinfe/semi-ui', rootPath)) {
75
- packageRegExps.semi = (0, exports.createDependenciesRegExp)(/@(ies|douyinfe)[\\/]semi-.*/);
77
+ });
78
+ (0, _assert.default)(defaultConfig !== false);
79
+ (0, _assert.default)(override !== false);
80
+ return {
81
+ ...defaultConfig,
82
+ ...override,
83
+ cacheGroups: {
84
+ ...defaultConfig.cacheGroups,
85
+ ...experienceCacheGroup,
86
+ ...userDefinedCacheGroups,
87
+ ...override.cacheGroups
76
88
  }
77
- if (polyfill === 'entry' || polyfill === 'usage') {
78
- packageRegExps.polyfill = (0, exports.createDependenciesRegExp)('core-js', '@babel/runtime', '@swc/helpers');
79
- }
80
- Object.entries(packageRegExps).forEach(([name, test]) => {
81
- const key = `lib-${name}`;
82
- experienceCacheGroup[key] = {
83
- test,
84
- priority: 0,
85
- name: key,
86
- reuseExistingChunk: true,
87
- };
88
- });
89
- (0, assert_1.default)(defaultConfig !== false);
90
- (0, assert_1.default)(override !== false);
91
- return {
92
- ...defaultConfig,
93
- ...override,
94
- cacheGroups: {
95
- ...defaultConfig.cacheGroups,
96
- ...experienceCacheGroup,
97
- ...userDefinedCacheGroups,
98
- ...override.cacheGroups,
99
- },
100
- };
89
+ };
101
90
  }
102
91
  function splitByModule(ctx) {
103
- const { override, userDefinedCacheGroups, defaultConfig } = ctx;
104
- (0, assert_1.default)(defaultConfig !== false);
105
- (0, assert_1.default)(override !== false);
106
- return {
107
- ...defaultConfig,
108
- minSize: 0,
109
- maxInitialRequests: Infinity,
110
- ...override,
111
- cacheGroups: {
112
- ...defaultConfig.cacheGroups,
113
- ...userDefinedCacheGroups,
114
- // Core group
115
- vendors: {
116
- priority: -10,
117
- test: builder_shared_1.NODE_MODULES_REGEX,
118
- // todo: not support in rspack
119
- name(module) {
120
- return (0, builder_shared_1.getPackageNameFromModulePath)(module.context);
121
- },
122
- },
123
- ...override.cacheGroups,
124
- },
125
- };
92
+ const { override, userDefinedCacheGroups, defaultConfig } = ctx;
93
+ (0, _assert.default)(defaultConfig !== false);
94
+ (0, _assert.default)(override !== false);
95
+ return {
96
+ ...defaultConfig,
97
+ minSize: 0,
98
+ maxInitialRequests: Infinity,
99
+ ...override,
100
+ cacheGroups: {
101
+ ...defaultConfig.cacheGroups,
102
+ ...userDefinedCacheGroups,
103
+ // Core group
104
+ vendors: {
105
+ priority: -10,
106
+ test: _buildershared.NODE_MODULES_REGEX,
107
+ // todo: not support in rspack
108
+ name(module) {
109
+ return (0, _buildershared.getPackageNameFromModulePath)(module.context);
110
+ }
111
+ },
112
+ ...override.cacheGroups
113
+ }
114
+ };
126
115
  }
127
116
  function splitBySize(ctx) {
128
- var _a, _b;
129
- const { override, userDefinedCacheGroups, defaultConfig, builderConfig } = ctx;
130
- (0, assert_1.default)(defaultConfig !== false);
131
- (0, assert_1.default)(override !== false);
132
- (0, assert_1.default)(builderConfig.strategy === 'split-by-size');
133
- return {
134
- ...defaultConfig,
135
- minSize: (_a = builderConfig.minSize) !== null && _a !== void 0 ? _a : 0,
136
- maxSize: (_b = builderConfig.maxSize) !== null && _b !== void 0 ? _b : Infinity,
137
- ...override,
138
- cacheGroups: {
139
- ...defaultConfig.cacheGroups,
140
- ...userDefinedCacheGroups,
141
- ...override.cacheGroups,
142
- },
143
- };
117
+ const { override, userDefinedCacheGroups, defaultConfig, builderConfig } = ctx;
118
+ (0, _assert.default)(defaultConfig !== false);
119
+ (0, _assert.default)(override !== false);
120
+ (0, _assert.default)(builderConfig.strategy === "split-by-size");
121
+ var _builderConfig_minSize, _builderConfig_maxSize;
122
+ return {
123
+ ...defaultConfig,
124
+ minSize: (_builderConfig_minSize = builderConfig.minSize) !== null && _builderConfig_minSize !== void 0 ? _builderConfig_minSize : 0,
125
+ maxSize: (_builderConfig_maxSize = builderConfig.maxSize) !== null && _builderConfig_maxSize !== void 0 ? _builderConfig_maxSize : Infinity,
126
+ ...override,
127
+ cacheGroups: {
128
+ ...defaultConfig.cacheGroups,
129
+ ...userDefinedCacheGroups,
130
+ ...override.cacheGroups
131
+ }
132
+ };
144
133
  }
145
134
  function splitCustom(ctx) {
146
- const { override, userDefinedCacheGroups, defaultConfig } = ctx;
147
- (0, assert_1.default)(defaultConfig !== false);
148
- (0, assert_1.default)(override !== false);
149
- return {
150
- ...defaultConfig,
151
- ...override,
152
- cacheGroups: {
153
- ...defaultConfig.cacheGroups,
154
- ...userDefinedCacheGroups,
155
- ...override.cacheGroups,
156
- },
157
- };
135
+ const { override, userDefinedCacheGroups, defaultConfig } = ctx;
136
+ (0, _assert.default)(defaultConfig !== false);
137
+ (0, _assert.default)(override !== false);
138
+ return {
139
+ ...defaultConfig,
140
+ ...override,
141
+ cacheGroups: {
142
+ ...defaultConfig.cacheGroups,
143
+ ...userDefinedCacheGroups,
144
+ ...override.cacheGroups
145
+ }
146
+ };
158
147
  }
159
148
  function allInOne(_ctx) {
160
- // Set false to avoid chunk split.
161
- return false;
149
+ return false;
162
150
  }
163
- // Ignore user defined cache group to get single vendor chunk.
164
151
  function singleVendor(ctx) {
165
- const { override, defaultConfig, userDefinedCacheGroups } = ctx;
166
- (0, assert_1.default)(defaultConfig !== false);
167
- (0, assert_1.default)(override !== false);
168
- const singleVendorCacheGroup = {
169
- singleVendor: {
170
- test: builder_shared_1.NODE_MODULES_REGEX,
171
- priority: 0,
172
- chunks: 'all',
173
- name: 'vendor',
174
- enforce: true,
175
- reuseExistingChunk: true,
176
- },
177
- };
178
- return {
179
- ...defaultConfig,
180
- ...override,
181
- cacheGroups: {
182
- ...defaultConfig.cacheGroups,
183
- ...singleVendorCacheGroup,
184
- ...userDefinedCacheGroups,
185
- ...override.cacheGroups,
186
- },
187
- };
152
+ const { override, defaultConfig, userDefinedCacheGroups } = ctx;
153
+ (0, _assert.default)(defaultConfig !== false);
154
+ (0, _assert.default)(override !== false);
155
+ const singleVendorCacheGroup = {
156
+ singleVendor: {
157
+ test: _buildershared.NODE_MODULES_REGEX,
158
+ priority: 0,
159
+ chunks: "all",
160
+ name: "vendor",
161
+ enforce: true,
162
+ reuseExistingChunk: true
163
+ }
164
+ };
165
+ return {
166
+ ...defaultConfig,
167
+ ...override,
168
+ cacheGroups: {
169
+ ...defaultConfig.cacheGroups,
170
+ ...singleVendorCacheGroup,
171
+ ...userDefinedCacheGroups,
172
+ ...override.cacheGroups
173
+ }
174
+ };
188
175
  }
189
176
  const SPLIT_STRATEGY_DISPATCHER = {
190
- 'split-by-experience': splitByExperience,
191
- 'split-by-module': splitByModule,
192
- 'split-by-size': splitBySize,
193
- custom: splitCustom,
194
- 'all-in-one': allInOne,
195
- 'single-vendor': singleVendor,
177
+ "split-by-experience": splitByExperience,
178
+ "split-by-module": splitByModule,
179
+ "split-by-size": splitBySize,
180
+ custom: splitCustom,
181
+ "all-in-one": allInOne,
182
+ "single-vendor": singleVendor
196
183
  };
197
184
  function builderPluginSplitChunks() {
198
- return {
199
- name: 'builder-plugin-split-chunks',
200
- setup(api) {
201
- api.modifyBundlerChain(async (chain, { isServer, isWebWorker, isServiceWorker }) => {
202
- var _a;
203
- if (isServer || isWebWorker || isServiceWorker) {
204
- chain.optimization.splitChunks(false);
205
- // web worker does not support dynamic imports, dynamicImportMode need set to eager
206
- if (isWebWorker || isServiceWorker) {
207
- // todo: not support in rspack
208
- // @ts-expect-error
209
- chain.module.parser.merge({
210
- javascript: {
211
- dynamicImportMode: 'eager',
212
- },
213
- });
214
- }
215
- return;
216
- }
217
- const config = api.getNormalizedConfig();
218
- const defaultConfig = {
219
- // Optimize both `initial` and `async` chunks
220
- chunks: 'all',
221
- // When chunk size >= 50000 bytes, split it into separate chunk
222
- enforceSizeThreshold: 50000,
223
- cacheGroups: {},
224
- };
225
- const { chunkSplit } = config.performance;
226
- let userDefinedCacheGroups = {};
227
- if (chunkSplit.forceSplitting) {
228
- userDefinedCacheGroups = getUserDefinedCacheGroups(chunkSplit.forceSplitting);
229
- }
230
- // Patch the override config difference between the `custom` strategy and other strategy.
231
- const override = chunkSplit.strategy === 'custom'
232
- ? // `chunkSplit.splitChunks` compat for Eden
233
- (_a = chunkSplit.splitChunks) !== null && _a !== void 0 ? _a : chunkSplit.override
234
- : chunkSplit.override;
235
- // Apply different strategy
236
- const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
237
- defaultConfig,
238
- override: override || {},
239
- userDefinedCacheGroups,
240
- builderConfig: chunkSplit,
241
- rootPath: api.context.rootPath,
242
- polyfill: config.output.polyfill,
243
- });
244
- chain.optimization.splitChunks(splitChunksOptions);
245
- // should not extract runtime chunk when strategy is `all-in-one`
246
- if (chunkSplit.strategy !== 'all-in-one') {
247
- chain.optimization.runtimeChunk({
248
- name: builder_shared_1.RUNTIME_CHUNK_NAME,
249
- });
250
- }
185
+ return {
186
+ name: "builder-plugin-split-chunks",
187
+ setup(api) {
188
+ api.modifyBundlerChain(async (chain, { isServer, isWebWorker, isServiceWorker }) => {
189
+ if (isServer || isWebWorker || isServiceWorker) {
190
+ chain.optimization.splitChunks(false);
191
+ if (isWebWorker || isServiceWorker) {
192
+ chain.module.parser.merge({
193
+ javascript: {
194
+ dynamicImportMode: "eager"
195
+ }
251
196
  });
252
- },
253
- };
197
+ }
198
+ return;
199
+ }
200
+ const config = api.getNormalizedConfig();
201
+ const defaultConfig = {
202
+ // Optimize both `initial` and `async` chunks
203
+ chunks: "all",
204
+ // When chunk size >= 50000 bytes, split it into separate chunk
205
+ enforceSizeThreshold: 5e4,
206
+ cacheGroups: {}
207
+ };
208
+ const { chunkSplit } = config.performance;
209
+ let userDefinedCacheGroups = {};
210
+ if (chunkSplit.forceSplitting) {
211
+ userDefinedCacheGroups = getUserDefinedCacheGroups(chunkSplit.forceSplitting);
212
+ }
213
+ var _chunkSplit_splitChunks;
214
+ const override = chunkSplit.strategy === "custom" ? (_chunkSplit_splitChunks = chunkSplit.splitChunks) !== null && _chunkSplit_splitChunks !== void 0 ? _chunkSplit_splitChunks : chunkSplit.override : chunkSplit.override;
215
+ const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
216
+ defaultConfig,
217
+ override: override || {},
218
+ userDefinedCacheGroups,
219
+ builderConfig: chunkSplit,
220
+ rootPath: api.context.rootPath,
221
+ polyfill: config.output.polyfill
222
+ });
223
+ chain.optimization.splitChunks(splitChunksOptions);
224
+ if (chunkSplit.strategy !== "all-in-one") {
225
+ chain.optimization.runtimeChunk({
226
+ name: _buildershared.RUNTIME_CHUNK_NAME
227
+ });
228
+ }
229
+ });
230
+ }
231
+ };
254
232
  }
255
- exports.builderPluginSplitChunks = builderPluginSplitChunks;
@@ -1,3 +1,3 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
2
  export declare const replacePlaceholder: (url: string, port: number) => string;
3
- export declare function builderPluginStartUrl(): DefaultBuilderPlugin;
3
+ export declare function builderPluginStartUrl(): DefaultBuilderPlugin;
@@ -1,84 +1,68 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ replacePlaceholder: function() {
14
+ return replacePlaceholder;
15
+ },
16
+ builderPluginStartUrl: function() {
17
+ return builderPluginStartUrl;
18
+ }
17
19
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.builderPluginStartUrl = exports.replacePlaceholder = void 0;
30
- const lodash_1 = __importDefault(require("@modern-js/utils/lodash"));
20
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
22
+ const _lodash = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/lodash"));
31
23
  const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
32
- exports.replacePlaceholder = replacePlaceholder;
33
24
  const openedURLs = [];
34
25
  function builderPluginStartUrl() {
35
- return {
36
- name: 'builder-plugin-start-url',
37
- async setup(api) {
38
- let port;
39
- api.onAfterStartDevServer(async (params) => {
40
- ({ port } = params);
41
- });
42
- api.onDevCompileDone(async ({ isFirstCompile }) => {
43
- if (!isFirstCompile || !port) {
44
- return;
45
- }
46
- const config = api.getNormalizedConfig();
47
- const { startUrl, beforeStartUrl } = config.dev;
48
- const { https } = api.context.devServer || {};
49
- if (!startUrl) {
50
- return;
51
- }
52
- const urls = [];
53
- if (startUrl === true) {
54
- const protocol = https ? 'https' : 'http';
55
- urls.push(`${protocol}://localhost:${port}`);
56
- }
57
- else {
58
- urls.push(...lodash_1.default.castArray(startUrl).map(item => (0, exports.replacePlaceholder)(item, port)));
59
- }
60
- const { ensureArray } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
61
- const { openBrowser } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
62
- const openUrls = () => {
63
- for (const url of urls) {
64
- /**
65
- * If a URL has been opened in current process, we will not open it again.
66
- * It can prevent opening the same URL multiple times.
67
- */
68
- if (!openedURLs.includes(url)) {
69
- openBrowser(url);
70
- openedURLs.push(url);
71
- }
72
- }
73
- };
74
- if (beforeStartUrl) {
75
- Promise.all(ensureArray(beforeStartUrl).map(fn => fn())).then(openUrls);
76
- }
77
- else {
78
- openUrls();
79
- }
80
- });
81
- },
82
- };
26
+ return {
27
+ name: "builder-plugin-start-url",
28
+ async setup(api) {
29
+ let port;
30
+ api.onAfterStartDevServer(async (params) => {
31
+ ({ port } = params);
32
+ });
33
+ api.onDevCompileDone(async ({ isFirstCompile }) => {
34
+ if (!isFirstCompile || !port) {
35
+ return;
36
+ }
37
+ const config = api.getNormalizedConfig();
38
+ const { startUrl, beforeStartUrl } = config.dev;
39
+ const { https } = api.context.devServer || {};
40
+ if (!startUrl) {
41
+ return;
42
+ }
43
+ const urls = [];
44
+ if (startUrl === true) {
45
+ const protocol = https ? "https" : "http";
46
+ urls.push(`${protocol}://localhost:${port}`);
47
+ } else {
48
+ urls.push(..._lodash.default.castArray(startUrl).map((item) => replacePlaceholder(item, port)));
49
+ }
50
+ const { ensureArray } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
51
+ const { openBrowser } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/builder-shared")));
52
+ const openUrls = () => {
53
+ for (const url of urls) {
54
+ if (!openedURLs.includes(url)) {
55
+ openBrowser(url);
56
+ openedURLs.push(url);
57
+ }
58
+ }
59
+ };
60
+ if (beforeStartUrl) {
61
+ Promise.all(ensureArray(beforeStartUrl).map((fn) => fn())).then(openUrls);
62
+ } else {
63
+ openUrls();
64
+ }
65
+ });
66
+ }
67
+ };
83
68
  }
84
- exports.builderPluginStartUrl = builderPluginStartUrl;
@@ -1,2 +1,2 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const builderPluginSvg: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginSvg: () => DefaultBuilderPlugin;