@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.
- package/CHANGELOG.md +49 -0
- package/dist/createBuilder.d.ts +1 -1
- package/dist/createBuilder.js +48 -38
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -8
- package/dist/plugins/antd.d.ts +1 -1
- package/dist/plugins/antd.js +51 -31
- package/dist/plugins/arco.d.ts +1 -1
- package/dist/plugins/arco.js +41 -34
- package/dist/plugins/asset.d.ts +1 -1
- package/dist/plugins/asset.js +29 -25
- package/dist/plugins/assetsRetry.d.ts +1 -1
- package/dist/plugins/assetsRetry.js +34 -51
- package/dist/plugins/bundleAnalyzer.d.ts +1 -1
- package/dist/plugins/bundleAnalyzer.js +29 -50
- package/dist/plugins/cache.d.ts +1 -1
- package/dist/plugins/cache.js +68 -87
- package/dist/plugins/checkSyntax.d.ts +1 -1
- package/dist/plugins/checkSyntax.js +40 -54
- package/dist/plugins/cleanOutput.d.ts +1 -1
- package/dist/plugins/cleanOutput.js +22 -38
- package/dist/plugins/devtool.d.ts +1 -1
- package/dist/plugins/devtool.js +23 -21
- package/dist/plugins/entry.d.ts +1 -1
- package/dist/plugins/entry.js +23 -19
- package/dist/plugins/externals.d.ts +1 -1
- package/dist/plugins/externals.js +28 -25
- package/dist/plugins/fileSize.d.ts +1 -1
- package/dist/plugins/fileSize.js +124 -130
- package/dist/plugins/html.d.ts +1 -1
- package/dist/plugins/html.js +204 -206
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +41 -53
- package/dist/plugins/inlineChunk.d.ts +1 -1
- package/dist/plugins/inlineChunk.js +50 -59
- package/dist/plugins/moment.d.ts +1 -1
- package/dist/plugins/moment.js +23 -20
- package/dist/plugins/nodeAddons.d.ts +2 -0
- package/dist/plugins/nodeAddons.js +48 -0
- package/dist/plugins/rem.d.ts +1 -1
- package/dist/plugins/rem.js +73 -98
- package/dist/plugins/sourceBuild.d.ts +8 -14
- package/dist/plugins/sourceBuild.js +81 -111
- package/dist/plugins/splitChunks.d.ts +1 -1
- package/dist/plugins/splitChunks.js +206 -229
- package/dist/plugins/startUrl.d.ts +1 -1
- package/dist/plugins/startUrl.js +62 -78
- package/dist/plugins/svg.d.ts +1 -1
- package/dist/plugins/svg.js +64 -81
- package/dist/plugins/target.d.ts +1 -1
- package/dist/plugins/target.js +52 -31
- package/dist/plugins/toml.d.ts +1 -1
- package/dist/plugins/toml.js +16 -15
- package/dist/plugins/tsChecker.d.ts +1 -1
- package/dist/plugins/tsChecker.js +79 -92
- package/dist/plugins/wasm.d.ts +1 -1
- package/dist/plugins/wasm.js +31 -32
- package/dist/plugins/yaml.d.ts +1 -1
- package/dist/plugins/yaml.js +16 -15
- package/package.json +11 -9
|
@@ -1,255 +1,232 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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;
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -1,84 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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;
|
package/dist/plugins/svg.d.ts
CHANGED
|
@@ -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;
|