@rsbuild/core 1.3.0-beta.2 → 1.3.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/compiled/cors/index.d.ts +56 -1
- package/compiled/css-loader/index.js +18 -18
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/index.cjs +693 -750
- package/dist/index.js +616 -676
- package/dist/transformLoader.mjs +3 -1
- package/dist/transformRawLoader.mjs +3 -1
- package/dist-types/config.d.ts +7 -0
- package/dist-types/helpers/index.d.ts +0 -2
- package/dist-types/provider/createCompiler.d.ts +1 -23
- package/dist-types/server/{compilerDevMiddleware.d.ts → compilationManager.d.ts} +9 -10
- package/dist-types/server/compilationMiddleware.d.ts +37 -0
- package/dist-types/server/devMiddlewares.d.ts +22 -0
- package/dist-types/server/middlewares.d.ts +4 -5
- package/dist-types/server/socketServer.d.ts +1 -1
- package/dist-types/server/watchFiles.d.ts +2 -2
- package/dist-types/types/config.d.ts +2 -2
- package/dist-types/types/plugin.d.ts +13 -0
- package/package.json +4 -3
- package/types.d.ts +69 -52
- package/dist-types/plugins/lazyCompilation.d.ts +0 -2
- package/dist-types/server/devMiddleware.d.ts +0 -27
- package/dist-types/server/getDevMiddlewares.d.ts +0 -30
package/dist/index.js
CHANGED
|
@@ -33,21 +33,19 @@ var EsmMode, __webpack_modules__ = {
|
|
|
33
33
|
module.exports = function cloneDeep(val, instanceClone) {
|
|
34
34
|
switch(typeOf(val)){
|
|
35
35
|
case 'object':
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return res;
|
|
42
|
-
}
|
|
43
|
-
return val;
|
|
44
|
-
}(val, instanceClone);
|
|
45
|
-
case 'array':
|
|
46
|
-
return function(val, instanceClone) {
|
|
47
|
-
let res = new val.constructor(val.length);
|
|
48
|
-
for(let i = 0; i < val.length; i++)res[i] = cloneDeep(val[i], instanceClone);
|
|
36
|
+
var val1 = val, instanceClone1 = instanceClone;
|
|
37
|
+
if ('function' == typeof instanceClone1) return instanceClone1(val1);
|
|
38
|
+
if (instanceClone1 || isPlainObject(val1)) {
|
|
39
|
+
let res = new val1.constructor();
|
|
40
|
+
for(let key in val1)res[key] = cloneDeep(val1[key], instanceClone1);
|
|
49
41
|
return res;
|
|
50
|
-
}
|
|
42
|
+
}
|
|
43
|
+
return val1;
|
|
44
|
+
case 'array':
|
|
45
|
+
var val2 = val, instanceClone2 = instanceClone;
|
|
46
|
+
let res = new val2.constructor(val2.length);
|
|
47
|
+
for(let i = 0; i < val2.length; i++)res[i] = cloneDeep(val2[i], instanceClone2);
|
|
48
|
+
return res;
|
|
51
49
|
default:
|
|
52
50
|
return clone(val);
|
|
53
51
|
}
|
|
@@ -84,7 +82,7 @@ var EsmMode, __webpack_modules__ = {
|
|
|
84
82
|
return sourceIsArray !== Array.isArray(target) ? cloneUnlessOtherwiseSpecified(source, options) : sourceIsArray ? options.arrayMerge(target, source, options) : (destination = {}, (options1 = options).isMergeableObject(target) && getKeys(target).forEach(function(key) {
|
|
85
83
|
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options1);
|
|
86
84
|
}), getKeys(source).forEach(function(key) {
|
|
87
|
-
|
|
85
|
+
propertyIsOnObject(target, key) && !(Object.hasOwnProperty.call(target, key) && Object.propertyIsEnumerable.call(target, key)) || (propertyIsOnObject(target, key) && options1.isMergeableObject(source[key]) ? destination[key] = (function(key, options) {
|
|
88
86
|
if (!options.customMerge) return deepmerge;
|
|
89
87
|
var customMerge = options.customMerge(key);
|
|
90
88
|
return 'function' == typeof customMerge ? customMerge : deepmerge;
|
|
@@ -107,8 +105,7 @@ var EsmMode, __webpack_modules__ = {
|
|
|
107
105
|
for(let key in options && null != options.processEnv && (processEnv = options.processEnv), options.parsed){
|
|
108
106
|
let value = options.parsed[key];
|
|
109
107
|
value = processEnv[key] && processEnv[key] !== value ? processEnv[key] : function(value, processEnv, runningParsed) {
|
|
110
|
-
let match
|
|
111
|
-
let env = {
|
|
108
|
+
let match, env = {
|
|
112
109
|
...runningParsed,
|
|
113
110
|
...processEnv
|
|
114
111
|
}, regex = /(?<!\\)\${([^{}]+)}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g, result = value, seen = new Set();
|
|
@@ -139,10 +136,9 @@ var EsmMode, __webpack_modules__ = {
|
|
|
139
136
|
}
|
|
140
137
|
function _vaultPath(options) {
|
|
141
138
|
let possibleVaultPath = null;
|
|
142
|
-
if (options && options.path && options.path.length > 0) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} else possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
|
|
139
|
+
if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) for (let filepath of options.path)fs.existsSync(filepath) && (possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`);
|
|
140
|
+
else possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
|
|
141
|
+
else possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
|
|
146
142
|
return fs.existsSync(possibleVaultPath) ? possibleVaultPath : null;
|
|
147
143
|
}
|
|
148
144
|
function _resolveHome(envPath) {
|
|
@@ -150,18 +146,15 @@ var EsmMode, __webpack_modules__ = {
|
|
|
150
146
|
}
|
|
151
147
|
let DotenvModule = {
|
|
152
148
|
configDotenv: function(options) {
|
|
153
|
-
let lastError;
|
|
154
|
-
let dotenvPath = path.resolve(process.cwd(), '.env'), encoding = 'utf8', debug = !!(options && options.debug);
|
|
149
|
+
let lastError, dotenvPath = path.resolve(process.cwd(), '.env'), encoding = 'utf8', debug = !!(options && options.debug);
|
|
155
150
|
options && options.encoding ? encoding = options.encoding : debug && _debug('No encoding is specified. UTF-8 is used by default');
|
|
156
151
|
let optionPaths = [
|
|
157
152
|
dotenvPath
|
|
158
153
|
];
|
|
159
|
-
if (options && options.path)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
];
|
|
164
|
-
}
|
|
154
|
+
if (options && options.path) if (Array.isArray(options.path)) for (let filepath of (optionPaths = [], options.path))optionPaths.push(_resolveHome(filepath));
|
|
155
|
+
else optionPaths = [
|
|
156
|
+
_resolveHome(options.path)
|
|
157
|
+
];
|
|
165
158
|
let parsedAll = {};
|
|
166
159
|
for (let path of optionPaths)try {
|
|
167
160
|
let parsed = DotenvModule.parse(fs.readFileSync(path, {
|
|
@@ -187,8 +180,7 @@ var EsmMode, __webpack_modules__ = {
|
|
|
187
180
|
};
|
|
188
181
|
},
|
|
189
182
|
_parseVault: function(options) {
|
|
190
|
-
let decrypted
|
|
191
|
-
let vaultPath = _vaultPath(options), result = DotenvModule.configDotenv({
|
|
183
|
+
let decrypted, vaultPath = _vaultPath(options), result = DotenvModule.configDotenv({
|
|
192
184
|
path: vaultPath
|
|
193
185
|
});
|
|
194
186
|
if (!result.parsed) {
|
|
@@ -264,8 +256,7 @@ var EsmMode, __webpack_modules__ = {
|
|
|
264
256
|
}
|
|
265
257
|
},
|
|
266
258
|
parse: function(src) {
|
|
267
|
-
let match;
|
|
268
|
-
let obj = {}, lines = src.toString();
|
|
259
|
+
let match, obj = {}, lines = src.toString();
|
|
269
260
|
for(lines = lines.replace(/\r\n?/mg, '\n'); null != (match = LINE.exec(lines));){
|
|
270
261
|
let key = match[1], value = match[2] || '', maybeQuote = (value = value.trim())[0];
|
|
271
262
|
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2'), '"' === maybeQuote && (value = (value = value.replace(/\\n/g, '\n')).replace(/\\r/g, '\r')), obj[key] = value;
|
|
@@ -423,7 +414,6 @@ var EsmMode, __webpack_modules__ = {
|
|
|
423
414
|
"../../node_modules/.pnpm/shallow-clone@3.0.1/node_modules/shallow-clone/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
424
415
|
let valueOf = Symbol.prototype.valueOf, typeOf = __webpack_require__("../../node_modules/.pnpm/kind-of@6.0.3/node_modules/kind-of/index.js");
|
|
425
416
|
module.exports = function(val, deep) {
|
|
426
|
-
var val1, val2, deep1;
|
|
427
417
|
switch(typeOf(val)){
|
|
428
418
|
case 'array':
|
|
429
419
|
return val.slice();
|
|
@@ -436,17 +426,15 @@ var EsmMode, __webpack_modules__ = {
|
|
|
436
426
|
case 'set':
|
|
437
427
|
return new Set(val);
|
|
438
428
|
case 'buffer':
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}(val);
|
|
429
|
+
var val1, val2, deep1, val3 = val;
|
|
430
|
+
let len = val3.length, buf = Buffer.allocUnsafe ? Buffer.allocUnsafe(len) : Buffer.from(len);
|
|
431
|
+
return val3.copy(buf), buf;
|
|
443
432
|
case 'symbol':
|
|
444
433
|
return val1 = val, valueOf ? Object(valueOf.call(val1)) : {};
|
|
445
434
|
case 'arraybuffer':
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}(val);
|
|
435
|
+
var val4 = val;
|
|
436
|
+
let res = new val4.constructor(val4.byteLength);
|
|
437
|
+
return new Uint8Array(res).set(new Uint8Array(val4)), res;
|
|
450
438
|
case 'float32array':
|
|
451
439
|
case 'float64array':
|
|
452
440
|
case 'int16array':
|
|
@@ -458,10 +446,9 @@ var EsmMode, __webpack_modules__ = {
|
|
|
458
446
|
case 'uint8array':
|
|
459
447
|
return new (val2 = val).constructor(val2.buffer, val2.byteOffset, val2.length);
|
|
460
448
|
case 'regexp':
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}(val);
|
|
449
|
+
var val5 = val;
|
|
450
|
+
let flags = void 0 !== val5.flags ? val5.flags : /\w+$/.exec(val5) || void 0, re = new val5.constructor(val5.source, flags);
|
|
451
|
+
return re.lastIndex = val5.lastIndex, re;
|
|
465
452
|
case 'error':
|
|
466
453
|
return Object.create(val);
|
|
467
454
|
default:
|
|
@@ -499,8 +486,8 @@ var EsmMode, __webpack_modules__ = {
|
|
|
499
486
|
Object.defineProperty(exports, "__esModule", {
|
|
500
487
|
value: !0
|
|
501
488
|
}), exports.unique = exports.mergeWithRules = exports.mergeWithCustomize = exports.default = exports.merge = exports.CustomizeRule = exports.customizeObject = exports.customizeArray = void 0;
|
|
502
|
-
var wildcard_1 = __importDefault(__webpack_require__("../../node_modules/.pnpm/wildcard@2.0.1/node_modules/wildcard/index.js")), merge_with_1 = __importDefault(__webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/merge-with.js")), join_arrays_1 = __importDefault(__webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/join-arrays.js"))
|
|
503
|
-
exports.unique =
|
|
489
|
+
var wildcard_1 = __importDefault(__webpack_require__("../../node_modules/.pnpm/wildcard@2.0.1/node_modules/wildcard/index.js")), merge_with_1 = __importDefault(__webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/merge-with.js")), join_arrays_1 = __importDefault(__webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/join-arrays.js"));
|
|
490
|
+
exports.unique = __importDefault(__webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/unique.js")).default;
|
|
504
491
|
var types_1 = __webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/types.js");
|
|
505
492
|
Object.defineProperty(exports, "CustomizeRule", {
|
|
506
493
|
enumerable: !0,
|
|
@@ -877,12 +864,12 @@ var EsmMode, __webpack_modules__ = {
|
|
|
877
864
|
}
|
|
878
865
|
WildcardMatcher.prototype.match = function(input) {
|
|
879
866
|
var ii, testParts, matches = !0, parts = this.parts, partsCount = parts.length;
|
|
880
|
-
if ('string' == typeof input || input instanceof String) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
867
|
+
if ('string' == typeof input || input instanceof String) if (this.hasWild || this.text == input) {
|
|
868
|
+
for(ii = 0, testParts = (input || '').split(this.separator); matches && ii < partsCount; ii++)if ('*' === parts[ii]) continue;
|
|
869
|
+
else matches = ii < testParts.length && (parts[ii] instanceof RegExp ? parts[ii].test(testParts[ii]) : parts[ii] === testParts[ii]);
|
|
870
|
+
matches = matches && testParts;
|
|
871
|
+
} else matches = !1;
|
|
872
|
+
else if ('function' == typeof input.splice) for(matches = [], ii = input.length; ii--;)this.match(input[ii]) && (matches[matches.length] = input[ii]);
|
|
886
873
|
else if ('object' == typeof input) for(var key in matches = {}, input)this.match(key) && (matches[key] = input[key]);
|
|
887
874
|
return matches;
|
|
888
875
|
}, WildcardMatcher.prototype.classifyPart = function(part) {
|
|
@@ -1273,12 +1260,6 @@ let rspackMinVersion = '1.0.0', getNodeEnv = ()=>process.env.NODE_ENV, setNodeEn
|
|
|
1273
1260
|
} catch {
|
|
1274
1261
|
return !1;
|
|
1275
1262
|
}
|
|
1276
|
-
}, parseUrl = (url)=>{
|
|
1277
|
-
try {
|
|
1278
|
-
return new __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.URL(url);
|
|
1279
|
-
} catch {
|
|
1280
|
-
return null;
|
|
1281
|
-
}
|
|
1282
1263
|
}, ensureAssetPrefix = (url, assetPrefix = DEFAULT_ASSET_PREFIX)=>url.startsWith('//') || canParse(url) || 'auto' === assetPrefix || 'function' == typeof assetPrefix ? url : assetPrefix.startsWith('http') ? urlJoin(assetPrefix, url) : assetPrefix.startsWith('//') ? urlJoin(`https:${assetPrefix}`, url).replace('https:', '') : __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.posix.join(assetPrefix, url);
|
|
1283
1264
|
function getFilename(config, type, isProd, isServer) {
|
|
1284
1265
|
let { filename, filenameHash } = config.output, hash = 'string' == typeof filenameHash ? filenameHash ? `.[${filenameHash}]` : '' : filenameHash ? '.[contenthash:8]' : '';
|
|
@@ -1376,12 +1357,13 @@ function parsePackage(file) {
|
|
|
1376
1357
|
let list = config.browserslist;
|
|
1377
1358
|
for(let i in Array.isArray(list) && (list = {
|
|
1378
1359
|
defaults: list
|
|
1379
|
-
}), 'string' == typeof list && (list = parseConfig(list)), list)
|
|
1360
|
+
}), 'string' == typeof list && (list = parseConfig(list)), list){
|
|
1361
|
+
var section = list[i];
|
|
1380
1362
|
let FORMAT = 'Browserslist config should be a string or an array of strings with browser queries';
|
|
1381
1363
|
if (Array.isArray(section)) {
|
|
1382
1364
|
for(let i = 0; i < section.length; i++)if ('string' != typeof section[i]) throw new BrowserslistError(FORMAT);
|
|
1383
1365
|
} else if ('string' != typeof section) throw new BrowserslistError(FORMAT);
|
|
1384
|
-
}
|
|
1366
|
+
}
|
|
1385
1367
|
return list;
|
|
1386
1368
|
}
|
|
1387
1369
|
let IS_SECTION = /^\s*\[(.+)]\s*$/;
|
|
@@ -1402,10 +1384,9 @@ function parseConfig(string) {
|
|
|
1402
1384
|
}), result;
|
|
1403
1385
|
}
|
|
1404
1386
|
function parsePackageOrReadConfig(file) {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
}(file);
|
|
1387
|
+
if ('package.json' === __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.basename(file)) return parsePackage(file);
|
|
1388
|
+
if (!isFile(file)) throw new BrowserslistError(`Can't read ${file} config`);
|
|
1389
|
+
return parseConfig(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.readFileSync(file, 'utf-8'));
|
|
1409
1390
|
}
|
|
1410
1391
|
function pickEnv(config, opts) {
|
|
1411
1392
|
let name;
|
|
@@ -1475,7 +1456,7 @@ let configCache = {}, OVERRIDE_PATHS = [
|
|
|
1475
1456
|
overlay: !0,
|
|
1476
1457
|
reconnect: 100
|
|
1477
1458
|
}
|
|
1478
|
-
}), getDefaultServerConfig = ()=>({
|
|
1459
|
+
}), LOCAL_ORIGINS_REGEX = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, getDefaultServerConfig = ()=>({
|
|
1479
1460
|
port: 3000,
|
|
1480
1461
|
host: DEFAULT_DEV_HOST,
|
|
1481
1462
|
open: !1,
|
|
@@ -1484,7 +1465,9 @@ let configCache = {}, OVERRIDE_PATHS = [
|
|
|
1484
1465
|
compress: !0,
|
|
1485
1466
|
printUrls: !0,
|
|
1486
1467
|
strictPort: !1,
|
|
1487
|
-
cors:
|
|
1468
|
+
cors: {
|
|
1469
|
+
origin: LOCAL_ORIGINS_REGEX
|
|
1470
|
+
},
|
|
1488
1471
|
middlewareMode: !1
|
|
1489
1472
|
}), getDefaultSourceConfig = ()=>({
|
|
1490
1473
|
alias: {},
|
|
@@ -1632,8 +1615,7 @@ let resolveConfigPath = (root, customConfig)=>{
|
|
|
1632
1615
|
return null;
|
|
1633
1616
|
};
|
|
1634
1617
|
async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader = 'jiti' } = {}) {
|
|
1635
|
-
let configExport;
|
|
1636
|
-
let configFilePath = resolveConfigPath(cwd, path);
|
|
1618
|
+
let configExport, configFilePath = resolveConfigPath(cwd, path);
|
|
1637
1619
|
if (!configFilePath) return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('no config file found.'), {
|
|
1638
1620
|
content: {},
|
|
1639
1621
|
filePath: configFilePath
|
|
@@ -1886,8 +1868,7 @@ function createAsyncHook() {
|
|
|
1886
1868
|
let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isWatch })=>{
|
|
1887
1869
|
let name = 'rsbuild:beforeCompile';
|
|
1888
1870
|
if (helpers_isMultiCompiler(compiler)) {
|
|
1889
|
-
let waitBeforeCompileDone;
|
|
1890
|
-
let { compilers } = compiler, doneCompilers = 0;
|
|
1871
|
+
let waitBeforeCompileDone, { compilers } = compiler, doneCompilers = 0;
|
|
1891
1872
|
for(let index = 0; index < compilers.length; index++){
|
|
1892
1873
|
let compiler = compilers[index], compilerDone = !1;
|
|
1893
1874
|
(isWatch ? compiler.hooks.watchRun : compiler.hooks.run).tapPromise(name, async ()=>{
|
|
@@ -2050,12 +2031,10 @@ async function getBrowserslist(path) {
|
|
|
2050
2031
|
if (opts.config) return pickEnv(parsePackageOrReadConfig(opts.config), opts);
|
|
2051
2032
|
if (opts.path) {
|
|
2052
2033
|
let config = function(from) {
|
|
2053
|
-
let resolved;
|
|
2054
|
-
let fromDir = isFile(from = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.resolve(from)) ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(from) : from;
|
|
2034
|
+
let resolved, fromDir = isFile(from = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.resolve(from)) ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(from) : from;
|
|
2055
2035
|
if (fromDir in configCache) return configCache[fromDir];
|
|
2056
2036
|
let configFile = eachParent(from, (dir)=>{
|
|
2057
|
-
let pkgBrowserslist;
|
|
2058
|
-
let config = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(dir, 'browserslist'), pkg = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(dir, 'package.json'), rc = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(dir, '.browserslistrc');
|
|
2037
|
+
let pkgBrowserslist, config = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(dir, 'browserslist'), pkg = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(dir, 'package.json'), rc = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(dir, '.browserslistrc');
|
|
2059
2038
|
if (isFile(pkg)) try {
|
|
2060
2039
|
pkgBrowserslist = parsePackage(pkg);
|
|
2061
2040
|
} catch (e) {
|
|
@@ -2107,7 +2086,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
2107
2086
|
name,
|
|
2108
2087
|
distPath: function(cwd, config) {
|
|
2109
2088
|
var _config_output_distPath, _config_output;
|
|
2110
|
-
return getAbsolutePath(cwd, (null === (_config_output = config.output) || void 0 === _config_output
|
|
2089
|
+
return getAbsolutePath(cwd, (null === (_config_output = config.output) || void 0 === _config_output || null === (_config_output_distPath = _config_output.distPath) || void 0 === _config_output_distPath ? void 0 : _config_output_distPath.root) ?? ROOT_DIST_DIR);
|
|
2111
2090
|
}(context.rootPath, config),
|
|
2112
2091
|
entry,
|
|
2113
2092
|
browserslist,
|
|
@@ -2124,7 +2103,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
2124
2103
|
async function createContext(options, userConfig) {
|
|
2125
2104
|
let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
2126
2105
|
return {
|
|
2127
|
-
version: "1.3.0
|
|
2106
|
+
version: "1.3.0",
|
|
2128
2107
|
rootPath,
|
|
2129
2108
|
distPath: '',
|
|
2130
2109
|
cachePath,
|
|
@@ -2363,7 +2342,7 @@ let configChain_CHAIN_ID = {
|
|
|
2363
2342
|
let generatorOptions = {
|
|
2364
2343
|
filename
|
|
2365
2344
|
};
|
|
2366
|
-
!1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/(__inline=false|url)/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(/inline/), rule.oneOf(`${assetType}-asset`).type('asset').parser({
|
|
2345
|
+
!1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/(__inline=false|url)/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(/inline/), rule.oneOf(`${assetType}-asset-raw`).type('asset/source').resourceQuery(/raw/), rule.oneOf(`${assetType}-asset`).type('asset').parser({
|
|
2367
2346
|
dataUrlCondition: {
|
|
2368
2347
|
maxSize
|
|
2369
2348
|
}
|
|
@@ -2562,7 +2541,7 @@ let pluginCache = ()=>({
|
|
|
2562
2541
|
return 'auto' === enable ? isDev && !config.dev.writeToDisk ? void 0 : isStrictSubdir(rootPath, distPath) ? {
|
|
2563
2542
|
path: distPath,
|
|
2564
2543
|
keep
|
|
2565
|
-
} : (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Please set ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('`output.cleanDistPath`')} config manually.`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current root path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(rootPath)}`),
|
|
2544
|
+
} : void (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Please set ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('`output.cleanDistPath`')} config manually.`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current root path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(rootPath)}`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current dist path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(distPath)}`)) : !0 === enable ? {
|
|
2566
2545
|
path: distPath,
|
|
2567
2546
|
keep
|
|
2568
2547
|
} : void 0;
|
|
@@ -2798,15 +2777,14 @@ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plu
|
|
|
2798
2777
|
not: /raw|inline/
|
|
2799
2778
|
}), inlineRule.test(CSS_REGEX).type("javascript/auto").resourceQuery(/inline/), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(/raw/);
|
|
2800
2779
|
let emitCss = config.output.emitCss ?? 'web' === target;
|
|
2801
|
-
if (emitCss) {
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
} else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(LOADER_PATH, 'ignoreCssLoader.mjs'));
|
|
2780
|
+
if (emitCss) if (config.output.injectStyles) {
|
|
2781
|
+
let styleLoaderOptions = reduceConfigs({
|
|
2782
|
+
initial: {},
|
|
2783
|
+
config: config.tools.styleLoader
|
|
2784
|
+
});
|
|
2785
|
+
rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
|
|
2786
|
+
} else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions);
|
|
2787
|
+
else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(LOADER_PATH, 'ignoreCssLoader.mjs'));
|
|
2810
2788
|
let importLoaders = 0, updateRules = (callback)=>{
|
|
2811
2789
|
callback(rule, 'normal'), callback(inlineRule, 'inline');
|
|
2812
2790
|
}, cssLoaderPath = getCompiledPath('css-loader');
|
|
@@ -2827,7 +2805,7 @@ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plu
|
|
|
2827
2805
|
root: api.context.rootPath,
|
|
2828
2806
|
postcssrcCache
|
|
2829
2807
|
});
|
|
2830
|
-
if ('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions
|
|
2808
|
+
if ('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions || null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) {
|
|
2831
2809
|
importLoaders++;
|
|
2832
2810
|
let postcssLoaderPath = getCompiledPath('postcss-loader');
|
|
2833
2811
|
updateRules((rule)=>{
|
|
@@ -2873,13 +2851,15 @@ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plu
|
|
|
2873
2851
|
setup (api) {
|
|
2874
2852
|
api.modifyBundlerChain((chain, { CHAIN_ID, bundler, environment })=>{
|
|
2875
2853
|
let { config } = environment, baseUrl = JSON.stringify(config.server.base), assetPrefix = JSON.stringify(getPublicPathFromChain(chain, !1)), mergedDefine = {
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2854
|
+
...{
|
|
2855
|
+
'import.meta.env.MODE': JSON.stringify(config.mode),
|
|
2856
|
+
'import.meta.env.DEV': 'development' === config.mode,
|
|
2857
|
+
'import.meta.env.PROD': 'production' === config.mode,
|
|
2858
|
+
'import.meta.env.BASE_URL': baseUrl,
|
|
2859
|
+
'import.meta.env.ASSET_PREFIX': assetPrefix,
|
|
2860
|
+
'process.env.BASE_URL': baseUrl,
|
|
2861
|
+
'process.env.ASSET_PREFIX': assetPrefix
|
|
2862
|
+
},
|
|
2883
2863
|
...config.source.define
|
|
2884
2864
|
};
|
|
2885
2865
|
!function(define) {
|
|
@@ -3131,8 +3111,7 @@ let VOID_TAGS = [
|
|
|
3131
3111
|
class RsbuildHtmlPlugin {
|
|
3132
3112
|
apply(compiler) {
|
|
3133
3113
|
let emitFavicon = async (compilation, favicon)=>{
|
|
3134
|
-
let buffer;
|
|
3135
|
-
let name = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.basename(favicon);
|
|
3114
|
+
let buffer, name = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.basename(favicon);
|
|
3136
3115
|
if (compilation.assets[name]) return name;
|
|
3137
3116
|
if (!compilation.inputFileSystem) return addCompilationError(compilation, '[rsbuild:html] Failed to read the favicon file as "compilation.inputFileSystem" is not available.'), null;
|
|
3138
3117
|
let filename = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.isAbsolute(favicon) ? favicon : __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(compilation.compiler.context, favicon);
|
|
@@ -3244,7 +3223,29 @@ let getTagConfig = (config)=>{
|
|
|
3244
3223
|
ctx: {
|
|
3245
3224
|
entryName: entryName
|
|
3246
3225
|
}
|
|
3247
|
-
}), filename = htmlPaths[entryName], { templatePath, templateContent } = await getTemplate(entryName, config, api.context.rootPath),
|
|
3226
|
+
}), filename = htmlPaths[entryName], { templatePath, templateContent } = await getTemplate(entryName, config, api.context.rootPath), templateParameters = (compilation, assets, assetTags, pluginOptions)=>{
|
|
3227
|
+
let { mountId, templateParameters } = config.html, rspackConfig = compilation.options, htmlPlugin = {
|
|
3228
|
+
tags: assetTags,
|
|
3229
|
+
files: assets,
|
|
3230
|
+
options: pluginOptions
|
|
3231
|
+
};
|
|
3232
|
+
return reduceConfigsWithContext({
|
|
3233
|
+
initial: {
|
|
3234
|
+
mountId,
|
|
3235
|
+
entryName: entryName,
|
|
3236
|
+
assetPrefix: assetPrefix,
|
|
3237
|
+
compilation,
|
|
3238
|
+
htmlPlugin,
|
|
3239
|
+
rspackConfig,
|
|
3240
|
+
webpackConfig: rspackConfig,
|
|
3241
|
+
htmlWebpackPlugin: htmlPlugin
|
|
3242
|
+
},
|
|
3243
|
+
config: templateParameters,
|
|
3244
|
+
ctx: {
|
|
3245
|
+
entryName: entryName
|
|
3246
|
+
}
|
|
3247
|
+
});
|
|
3248
|
+
}, pluginOptions = {
|
|
3248
3249
|
meta: function(entryName, config, templateContent) {
|
|
3249
3250
|
let metaTags = reduceConfigsMergeContext({
|
|
3250
3251
|
initial: {},
|
|
@@ -3259,29 +3260,7 @@ let getTagConfig = (config)=>{
|
|
|
3259
3260
|
inject,
|
|
3260
3261
|
filename,
|
|
3261
3262
|
entryName,
|
|
3262
|
-
templateParameters
|
|
3263
|
-
let { mountId, templateParameters } = config.html, rspackConfig = compilation.options, htmlPlugin = {
|
|
3264
|
-
tags: assetTags,
|
|
3265
|
-
files: assets,
|
|
3266
|
-
options: pluginOptions
|
|
3267
|
-
};
|
|
3268
|
-
return reduceConfigsWithContext({
|
|
3269
|
-
initial: {
|
|
3270
|
-
mountId,
|
|
3271
|
-
entryName: entryName,
|
|
3272
|
-
assetPrefix: assetPrefix,
|
|
3273
|
-
compilation,
|
|
3274
|
-
htmlPlugin,
|
|
3275
|
-
rspackConfig,
|
|
3276
|
-
webpackConfig: rspackConfig,
|
|
3277
|
-
htmlWebpackPlugin: htmlPlugin
|
|
3278
|
-
},
|
|
3279
|
-
config: templateParameters,
|
|
3280
|
-
ctx: {
|
|
3281
|
-
entryName: entryName
|
|
3282
|
-
}
|
|
3283
|
-
});
|
|
3284
|
-
},
|
|
3263
|
+
templateParameters,
|
|
3285
3264
|
scriptLoading: config.html.scriptLoading
|
|
3286
3265
|
};
|
|
3287
3266
|
templatePath && (pluginOptions.template = templatePath), chunks.length > 1 && (pluginOptions.chunksSortMode = 'manual');
|
|
@@ -3431,19 +3410,6 @@ let pluginInlineChunk = ()=>({
|
|
|
3431
3410
|
};
|
|
3432
3411
|
});
|
|
3433
3412
|
}
|
|
3434
|
-
}), pluginLazyCompilation = ()=>({
|
|
3435
|
-
name: 'rsbuild:lazy-compilation',
|
|
3436
|
-
setup (api) {
|
|
3437
|
-
api.modifyBundlerChain((chain, { environment, isProd, target })=>{
|
|
3438
|
-
var _config_dev;
|
|
3439
|
-
if (isProd || 'web' !== target) return;
|
|
3440
|
-
let { config } = environment, options = null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.lazyCompilation;
|
|
3441
|
-
options && chain.experiments({
|
|
3442
|
-
...chain.get('experiments'),
|
|
3443
|
-
lazyCompilation: options
|
|
3444
|
-
});
|
|
3445
|
-
});
|
|
3446
|
-
}
|
|
3447
3413
|
});
|
|
3448
3414
|
function isAsync(chunk) {
|
|
3449
3415
|
return 'canBeInitial' in chunk ? !chunk.canBeInitial() : 'isInitial' in chunk && !chunk.isInitial();
|
|
@@ -4173,7 +4139,7 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
|
4173
4139
|
if ('true' !== process.env.RSDOCTOR) return;
|
|
4174
4140
|
let isRspack = 'rspack' === api.context.bundlerType, pluginName = isRspack ? 'RsdoctorRspackPlugin' : 'RsdoctorWebpackPlugin', isRsdoctorPlugin = (plugin)=>{
|
|
4175
4141
|
var _plugin_constructor;
|
|
4176
|
-
return (null == plugin ? void 0 : plugin.isRsdoctorPlugin) === !0 || (null == plugin
|
|
4142
|
+
return (null == plugin ? void 0 : plugin.isRsdoctorPlugin) === !0 || (null == plugin || null === (_plugin_constructor = plugin.constructor) || void 0 === _plugin_constructor ? void 0 : _plugin_constructor.name) === pluginName;
|
|
4177
4143
|
};
|
|
4178
4144
|
for (let config of bundlerConfigs){
|
|
4179
4145
|
var _config_plugins;
|
|
@@ -4390,7 +4356,7 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
|
4390
4356
|
return;
|
|
4391
4357
|
}
|
|
4392
4358
|
let { config } = environment, defaultConfig = {
|
|
4393
|
-
chunks: (null === (_config_moduleFederation = config.moduleFederation) || void 0 === _config_moduleFederation
|
|
4359
|
+
chunks: (null === (_config_moduleFederation = config.moduleFederation) || void 0 === _config_moduleFederation || null === (_config_moduleFederation_options = _config_moduleFederation.options) || void 0 === _config_moduleFederation_options ? void 0 : _config_moduleFederation_options.exposes) ? 'async' : 'all',
|
|
4394
4360
|
cacheGroups: {}
|
|
4395
4361
|
};
|
|
4396
4362
|
'webpack' === api.context.bundlerType && (defaultConfig.enforceSizeThreshold = 50000);
|
|
@@ -4696,15 +4662,14 @@ async function generateRspackConfig({ target, context, environment }) {
|
|
|
4696
4662
|
HotModuleReplacementPlugin
|
|
4697
4663
|
}
|
|
4698
4664
|
})).toConfig();
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
}
|
|
4665
|
+
var config = rspackConfig = await modifyRspackConfig(context, rspackConfig, chainUtils);
|
|
4666
|
+
if (config.plugins) {
|
|
4667
|
+
for (let plugin of config.plugins)if (plugin && void 0 === plugin.apply && 'name' in plugin && 'setup' in plugin) {
|
|
4668
|
+
let name = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.bold(__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(plugin.name));
|
|
4669
|
+
throw Error(`[rsbuild:plugin] "${name}" appears to be an Rsbuild plugin. It cannot be used as an Rspack plugin.`);
|
|
4705
4670
|
}
|
|
4706
|
-
|
|
4707
|
-
|
|
4671
|
+
}
|
|
4672
|
+
return config.devServer && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`[rsbuild:config] Find invalid Rspack config: "${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`), rspackConfig;
|
|
4708
4673
|
}
|
|
4709
4674
|
async function modifyRsbuildConfig(context) {
|
|
4710
4675
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('modify Rsbuild config');
|
|
@@ -4728,8 +4693,7 @@ async function modifyEnvironmentConfig(context, config, name) {
|
|
|
4728
4693
|
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`modify Rsbuild environment(${name}) config done`), modified;
|
|
4729
4694
|
}
|
|
4730
4695
|
let initEnvironmentConfigs = (normalizedConfig, rootPath, specifiedEnvironments)=>{
|
|
4731
|
-
let defaultEntry
|
|
4732
|
-
let getDefaultEntryWithMemo = ()=>(defaultEntry || (defaultEntry = function(root) {
|
|
4696
|
+
let defaultEntry, getDefaultEntryWithMemo = ()=>(defaultEntry || (defaultEntry = function(root) {
|
|
4733
4697
|
let entryFile = findExists([
|
|
4734
4698
|
'ts',
|
|
4735
4699
|
'js',
|
|
@@ -4802,25 +4766,24 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
4802
4766
|
server
|
|
4803
4767
|
};
|
|
4804
4768
|
}
|
|
4805
|
-
|
|
4769
|
+
context.normalizedConfig = {
|
|
4806
4770
|
...normalizeBaseConfig,
|
|
4807
4771
|
environments
|
|
4808
|
-
}, await updateEnvironmentContext(context, environments)
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
}(context), validateRsbuildConfig(context.normalizedConfig), context.normalizedConfig;
|
|
4772
|
+
}, await updateEnvironmentContext(context, environments);
|
|
4773
|
+
let distPaths = Object.values(context.environments).map((item)=>item.distPath);
|
|
4774
|
+
return context.distPath = function(paths) {
|
|
4775
|
+
let uniquePaths = [
|
|
4776
|
+
...new Set(paths)
|
|
4777
|
+
];
|
|
4778
|
+
if (1 === uniquePaths.length) return uniquePaths[0];
|
|
4779
|
+
let [first, ...rest] = uniquePaths.map((p)=>p.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep)), common = [];
|
|
4780
|
+
for(let i = 0; i < first.length; i++){
|
|
4781
|
+
let segment = first[i];
|
|
4782
|
+
if (rest.every((p)=>p[i] === segment)) common.push(segment);
|
|
4783
|
+
else break;
|
|
4784
|
+
}
|
|
4785
|
+
return common.join(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep);
|
|
4786
|
+
}(distPaths), validateRsbuildConfig(context.normalizedConfig), context.normalizedConfig;
|
|
4824
4787
|
}
|
|
4825
4788
|
async function initConfigs({ context, pluginManager, rsbuildOptions }) {
|
|
4826
4789
|
let normalizedConfig = await initRsbuildConfig({
|
|
@@ -4906,14 +4869,14 @@ async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
|
|
|
4906
4869
|
}
|
|
4907
4870
|
}
|
|
4908
4871
|
async function setupWatchFiles(options) {
|
|
4909
|
-
let { dev, server, root,
|
|
4910
|
-
if (!hmr && !liveReload || !
|
|
4911
|
-
let closeDevFilesWatcher = await watchDevFiles(dev,
|
|
4872
|
+
let { dev, server, root, compilationManager } = options, { hmr, liveReload } = dev;
|
|
4873
|
+
if (!hmr && !liveReload || !compilationManager) return;
|
|
4874
|
+
let closeDevFilesWatcher = await watchDevFiles(dev, compilationManager, root), serverFilesWatcher = await function(serverConfig, compilationManager, root) {
|
|
4912
4875
|
let publicDirs = normalizePublicDirs(serverConfig.publicDir);
|
|
4913
4876
|
if (!publicDirs.length) return;
|
|
4914
4877
|
let watchPaths = publicDirs.filter((item)=>item.watch).map((item)=>item.name);
|
|
4915
|
-
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths),
|
|
4916
|
-
}(server,
|
|
4878
|
+
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), compilationManager, root);
|
|
4879
|
+
}(server, compilationManager, root);
|
|
4917
4880
|
return {
|
|
4918
4881
|
async close () {
|
|
4919
4882
|
await Promise.all([
|
|
@@ -4923,12 +4886,12 @@ async function setupWatchFiles(options) {
|
|
|
4923
4886
|
}
|
|
4924
4887
|
};
|
|
4925
4888
|
}
|
|
4926
|
-
async function watchDevFiles(devConfig,
|
|
4889
|
+
async function watchDevFiles(devConfig, compilationManager, root) {
|
|
4927
4890
|
let { watchFiles } = devConfig;
|
|
4928
4891
|
if (!watchFiles) return;
|
|
4929
4892
|
let watchers = [];
|
|
4930
4893
|
for (let { paths, options, type } of castArray(watchFiles)){
|
|
4931
|
-
let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions,
|
|
4894
|
+
let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions, compilationManager, root);
|
|
4932
4895
|
watcher && watchers.push(watcher);
|
|
4933
4896
|
}
|
|
4934
4897
|
return async ()=>{
|
|
@@ -4956,11 +4919,13 @@ async function createChokidar(pathOrGlobs, root, options) {
|
|
|
4956
4919
|
}
|
|
4957
4920
|
return chokidar.watch(Array.from(watchFiles), options);
|
|
4958
4921
|
}
|
|
4959
|
-
async function startWatchFiles({ paths, options, type = 'reload-page' },
|
|
4922
|
+
async function startWatchFiles({ paths, options, type = 'reload-page' }, compilationManager, root) {
|
|
4960
4923
|
if ('reload-page' !== type) return;
|
|
4961
4924
|
let watcher = await createChokidar(paths, root, options);
|
|
4962
4925
|
return watcher.on('change', ()=>{
|
|
4963
|
-
|
|
4926
|
+
compilationManager.socketServer.sockWrite({
|
|
4927
|
+
type: 'static-changed'
|
|
4928
|
+
});
|
|
4964
4929
|
}), watcher;
|
|
4965
4930
|
}
|
|
4966
4931
|
let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
@@ -5005,7 +4970,7 @@ async function watchFilesForRestart({ files, rsbuild, isBuildWatch, watchOptions
|
|
|
5005
4970
|
ignorePermissionErrors: !0,
|
|
5006
4971
|
...watchOptions
|
|
5007
4972
|
}), restarting = !1, onChange = async (filePath)=>{
|
|
5008
|
-
|
|
4973
|
+
restarting || (restarting = !0, (isBuildWatch ? await restartBuild({
|
|
5009
4974
|
filePath
|
|
5010
4975
|
}) : await restartDevServer({
|
|
5011
4976
|
filePath
|
|
@@ -5099,37 +5064,39 @@ let isClientCompiler = (compiler)=>{
|
|
|
5099
5064
|
}, isNodeCompiler = (compiler)=>{
|
|
5100
5065
|
let { target } = compiler.options;
|
|
5101
5066
|
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
5102
|
-
}, setupServerHooks = (compiler,
|
|
5067
|
+
}, setupServerHooks = (compiler, { onDone, onInvalid })=>{
|
|
5103
5068
|
if (isNodeCompiler(compiler)) return;
|
|
5104
5069
|
let { compile, invalid, done } = compiler.hooks;
|
|
5105
5070
|
compile.tap('rsbuild-dev-server', ()=>{
|
|
5106
|
-
|
|
5071
|
+
onInvalid(getCompilationId(compiler));
|
|
5107
5072
|
}), invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
5108
|
-
|
|
5109
|
-
}), done.tap('rsbuild-dev-server',
|
|
5110
|
-
},
|
|
5111
|
-
let { default: rsbuildDevMiddleware } = await import("../compiled/rsbuild-dev-middleware/index.js");
|
|
5112
|
-
return
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5073
|
+
onInvalid(getCompilationId(compiler), fileName);
|
|
5074
|
+
}), done.tap('rsbuild-dev-server', onDone);
|
|
5075
|
+
}, getCompilationMiddleware = async (compiler, options)=>{
|
|
5076
|
+
let { default: rsbuildDevMiddleware } = await import("../compiled/rsbuild-dev-middleware/index.js"), { clientPaths, callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
|
|
5077
|
+
return applyToCompiler(compiler, (compiler)=>{
|
|
5078
|
+
clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig }) {
|
|
5079
|
+
if (isClientCompiler(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
|
|
5080
|
+
RSBUILD_COMPILATION_NAME: JSON.stringify(getCompilationId(compiler)),
|
|
5081
|
+
RSBUILD_CLIENT_CONFIG: JSON.stringify(devConfig.client),
|
|
5082
|
+
RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
|
|
5083
|
+
RSBUILD_DEV_LIVE_RELOAD: devConfig.liveReload
|
|
5084
|
+
}).apply(compiler), clientPaths))new compiler.webpack.EntryPlugin(compiler.context, clientPath, {
|
|
5085
|
+
name: void 0
|
|
5086
|
+
}).apply(compiler);
|
|
5087
|
+
}({
|
|
5088
|
+
compiler,
|
|
5089
|
+
clientPaths,
|
|
5090
|
+
devConfig,
|
|
5091
|
+
resolvedClientConfig
|
|
5092
|
+
}), setupServerHooks(compiler, callbacks);
|
|
5093
|
+
}), rsbuildDevMiddleware(compiler, {
|
|
5094
|
+
etag: 'weak',
|
|
5095
|
+
publicPath: '/',
|
|
5096
|
+
stats: !1,
|
|
5097
|
+
serverSideRender: !0,
|
|
5098
|
+
writeToDisk: devConfig.writeToDisk
|
|
5099
|
+
});
|
|
5133
5100
|
}, styles = {
|
|
5134
5101
|
1: 'font-weight:bold',
|
|
5135
5102
|
2: 'opacity:0.5',
|
|
@@ -5176,11 +5143,6 @@ function socketServer_define_property(obj, key, value) {
|
|
|
5176
5143
|
}) : obj[key] = value, obj;
|
|
5177
5144
|
}
|
|
5178
5145
|
class SocketServer {
|
|
5179
|
-
upgrade(req, sock, head) {
|
|
5180
|
-
this.wsServer.shouldHandle(req) && this.wsServer.handleUpgrade(req, sock, head, (connection)=>{
|
|
5181
|
-
this.wsServer.emit('connection', connection, req);
|
|
5182
|
-
});
|
|
5183
|
-
}
|
|
5184
5146
|
clearHeartbeatTimer() {
|
|
5185
5147
|
this.heartbeatTimer && (clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
5186
5148
|
}
|
|
@@ -5297,13 +5259,16 @@ class SocketServer {
|
|
|
5297
5259
|
data: {
|
|
5298
5260
|
text: formattedErrors,
|
|
5299
5261
|
html: function(errors, root) {
|
|
5300
|
-
let htmlItems = errors.map((item)=>
|
|
5262
|
+
let htmlItems = errors.map((item)=>{
|
|
5263
|
+
var text;
|
|
5264
|
+
return text = server_ansiHTML(item ? item.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') : ''), text.replace(/(?:\.\.?[\/\\]|[a-zA-Z]:\\|\/)[^:]*:\d+:\d+/g, (file)=>{
|
|
5301
5265
|
let hasClosingSpan = file.includes('</span>') && !file.includes('<span'), filePath = hasClosingSpan ? file.replace('</span>', '') : file, isAbsolute = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.isAbsolute(filePath), absolutePath = root && !isAbsolute ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(root, filePath) : filePath, relativePath = root && isAbsolute ? function(base, filepath) {
|
|
5302
5266
|
let relativePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.relative)(base, filepath);
|
|
5303
5267
|
return '' === relativePath ? `.${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep}` : relativePath.startsWith('.') ? relativePath : `.${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep}${relativePath}`;
|
|
5304
5268
|
}(root, filePath) : filePath;
|
|
5305
5269
|
return `<a class="file-link" data-file="${absolutePath}">${relativePath}</a>${hasClosingSpan ? '</span>' : ''}`;
|
|
5306
|
-
})
|
|
5270
|
+
});
|
|
5271
|
+
});
|
|
5307
5272
|
return `
|
|
5308
5273
|
<style>
|
|
5309
5274
|
.root {
|
|
@@ -5450,13 +5415,17 @@ class SocketServer {
|
|
|
5450
5415
|
1 === connection.readyState && connection.send(message);
|
|
5451
5416
|
}
|
|
5452
5417
|
constructor(options){
|
|
5453
|
-
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "
|
|
5418
|
+
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "upgrade", (req, sock, head)=>{
|
|
5419
|
+
this.wsServer.shouldHandle(req) && this.wsServer.handleUpgrade(req, sock, head, (connection)=>{
|
|
5420
|
+
this.wsServer.emit('connection', connection, req);
|
|
5421
|
+
});
|
|
5422
|
+
}), socketServer_define_property(this, "checkSockets", ()=>{
|
|
5454
5423
|
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
5455
5424
|
null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref());
|
|
5456
5425
|
}), this.options = options, this.stats = {}, this.initialChunks = {};
|
|
5457
5426
|
}
|
|
5458
5427
|
}
|
|
5459
|
-
function
|
|
5428
|
+
function compilationManager_define_property(obj, key, value) {
|
|
5460
5429
|
return key in obj ? Object.defineProperty(obj, key, {
|
|
5461
5430
|
value: value,
|
|
5462
5431
|
enumerable: !0,
|
|
@@ -5464,7 +5433,7 @@ function compilerDevMiddleware_define_property(obj, key, value) {
|
|
|
5464
5433
|
writable: !0
|
|
5465
5434
|
}) : obj[key] = value, obj;
|
|
5466
5435
|
}
|
|
5467
|
-
let
|
|
5436
|
+
let compilationManager_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), formatDevConfig = (config, environments)=>{
|
|
5468
5437
|
let writeToDiskValues = Object.values(environments).map((env)=>env.config.dev.writeToDisk);
|
|
5469
5438
|
return 1 === new Set(writeToDiskValues).size ? {
|
|
5470
5439
|
...config,
|
|
@@ -5477,13 +5446,11 @@ let compilerDevMiddleware_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab
|
|
|
5477
5446
|
}
|
|
5478
5447
|
};
|
|
5479
5448
|
};
|
|
5480
|
-
class
|
|
5449
|
+
class CompilationManager {
|
|
5481
5450
|
async init() {
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
upgrade(req, sock, head) {
|
|
5486
|
-
this.socketServer.upgrade(req, sock, head);
|
|
5451
|
+
await this.setupCompilationMiddleware(), await this.socketServer.prepare();
|
|
5452
|
+
let { compiler } = this;
|
|
5453
|
+
this.outputFileSystem = (helpers_isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default;
|
|
5487
5454
|
}
|
|
5488
5455
|
async close() {
|
|
5489
5456
|
await this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
|
|
@@ -5496,21 +5463,12 @@ class CompilerDevMiddleware {
|
|
|
5496
5463
|
});
|
|
5497
5464
|
});
|
|
5498
5465
|
}
|
|
5499
|
-
|
|
5500
|
-
this
|
|
5501
|
-
type,
|
|
5502
|
-
data
|
|
5503
|
-
});
|
|
5504
|
-
}
|
|
5505
|
-
async setupDevMiddleware(devMiddleware, publicPaths) {
|
|
5506
|
-
let { devConfig, serverConfig } = this, { headers, base } = serverConfig, clientPaths = function(devConfig) {
|
|
5466
|
+
async setupCompilationMiddleware() {
|
|
5467
|
+
let { devConfig, serverConfig, publicPaths } = this, clientPaths = function(devConfig) {
|
|
5507
5468
|
var _devConfig_client;
|
|
5508
5469
|
let clientPaths = [];
|
|
5509
|
-
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(
|
|
5510
|
-
}(devConfig), middleware = await
|
|
5511
|
-
headers,
|
|
5512
|
-
publicPath: '/',
|
|
5513
|
-
stats: !1,
|
|
5470
|
+
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/hmr')), (null === (_devConfig_client = devConfig.client) || void 0 === _devConfig_client ? void 0 : _devConfig_client.overlay) && clientPaths.push(`${compilationManager_require.resolve('@rsbuild/core/client/overlay')}`)), clientPaths;
|
|
5471
|
+
}(devConfig), middleware = await getCompilationMiddleware(this.compiler, {
|
|
5514
5472
|
callbacks: {
|
|
5515
5473
|
onInvalid: (compilationId, fileName)=>{
|
|
5516
5474
|
if ('string' == typeof fileName && HTML_REGEX.test(fileName)) {
|
|
@@ -5529,348 +5487,91 @@ class CompilerDevMiddleware {
|
|
|
5529
5487
|
this.socketServer.updateStats(stats);
|
|
5530
5488
|
}
|
|
5531
5489
|
},
|
|
5532
|
-
clientPaths
|
|
5533
|
-
|
|
5534
|
-
liveReload: devConfig.liveReload,
|
|
5535
|
-
writeToDisk: devConfig.writeToDisk,
|
|
5536
|
-
serverSideRender: !0,
|
|
5537
|
-
etag: 'weak',
|
|
5490
|
+
clientPaths,
|
|
5491
|
+
devConfig,
|
|
5538
5492
|
serverConfig
|
|
5539
|
-
}), assetPrefixes = publicPaths.map(pathnameParse).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
5493
|
+
}), { base } = serverConfig, assetPrefixes = publicPaths.map(pathnameParse).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
5540
5494
|
let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
|
|
5541
5495
|
assetPrefix && '/' !== assetPrefix ? (req.url = url.slice(assetPrefix.length - 1), middleware(req, res, (...args)=>{
|
|
5542
5496
|
req.url = url, next(...args);
|
|
5543
5497
|
})) : middleware(req, res, next);
|
|
5544
5498
|
};
|
|
5545
|
-
|
|
5499
|
+
wrapper.close = middleware.close, this.middleware = wrapper;
|
|
5546
5500
|
}
|
|
5547
5501
|
constructor({ dev, server, compiler, publicPaths, environments }){
|
|
5548
|
-
|
|
5502
|
+
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "devConfig", void 0), compilationManager_define_property(this, "serverConfig", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.readFileSync(fileName, 'utf-8')), this.devConfig = formatDevConfig(dev, environments), this.serverConfig = server, this.compiler = compiler, this.publicPaths = publicPaths, this.outputFileSystem = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default, this.socketServer = new SocketServer(dev);
|
|
5549
5503
|
}
|
|
5550
5504
|
}
|
|
5551
|
-
let
|
|
5552
|
-
if (
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
context
|
|
5563
|
-
});
|
|
5564
|
-
return unlinked || (await m.link(()=>{}), m.instantiate && m.instantiate(), await m.evaluate()), m;
|
|
5565
|
-
};
|
|
5566
|
-
function basic_define_property(obj, key, value) {
|
|
5567
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
5568
|
-
value: value,
|
|
5569
|
-
enumerable: !0,
|
|
5570
|
-
configurable: !0,
|
|
5571
|
-
writable: !0
|
|
5572
|
-
}) : obj[key] = value, obj;
|
|
5573
|
-
}
|
|
5574
|
-
let isRelativePath = (p)=>/^\.\.?\//.test(p), getSubPath = (p)=>{
|
|
5575
|
-
let lastSlash = p.lastIndexOf('/'), firstSlash = p.indexOf('/');
|
|
5576
|
-
if (-1 !== lastSlash && firstSlash !== lastSlash) {
|
|
5577
|
-
if (-1 !== firstSlash) {
|
|
5578
|
-
let next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5579
|
-
for(; '.' === dir;)firstSlash = next, next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5505
|
+
let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, shouldCompress = (res)=>{
|
|
5506
|
+
if (res.getHeader('Content-Encoding')) return !1;
|
|
5507
|
+
let contentType = String(res.getHeader('Content-Type'));
|
|
5508
|
+
if (contentType && !CONTENT_TYPE_REGEX.test(contentType)) return !1;
|
|
5509
|
+
let size = res.getHeader('Content-Length');
|
|
5510
|
+
return void 0 === size || Number(size) > 1024;
|
|
5511
|
+
}, gzipMiddleware = ({ level = __WEBPACK_EXTERNAL_MODULE_node_zlib_a5bb16fc__.default.constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
5512
|
+
let gzip, writeHeadStatus, accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
|
|
5513
|
+
if ('HEAD' === req.method || !encoding) {
|
|
5514
|
+
next();
|
|
5515
|
+
return;
|
|
5580
5516
|
}
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
return (currentDirectory, modulePath, context = {})=>entryRequire(currentDirectory, Array.isArray(modulePath) ? modulePath : modulePath.split('?')[0], context);
|
|
5594
|
-
}
|
|
5595
|
-
getFile(modulePath, currentDirectory) {
|
|
5596
|
-
if (Array.isArray(modulePath)) return {
|
|
5597
|
-
path: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(currentDirectory, '.array-require.js'),
|
|
5598
|
-
content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
|
|
5599
|
-
subPath: ''
|
|
5600
|
-
};
|
|
5601
|
-
let joinedPath = isRelativePath(modulePath) ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(currentDirectory, modulePath) : modulePath;
|
|
5602
|
-
return this._options.isBundleOutput(joinedPath) ? {
|
|
5603
|
-
path: joinedPath,
|
|
5604
|
-
content: this._options.readFileSync(joinedPath),
|
|
5605
|
-
subPath: getSubPath(modulePath)
|
|
5606
|
-
} : null;
|
|
5607
|
-
}
|
|
5608
|
-
preExecute(_code, _file) {}
|
|
5609
|
-
postExecute(_m, _file) {}
|
|
5610
|
-
createRunner() {
|
|
5611
|
-
this.requirers.set('entry', (_currentDirectory, _modulePath, _context = {})=>{
|
|
5612
|
-
throw Error('[rsbuild:runner] Not implement');
|
|
5613
|
-
});
|
|
5614
|
-
}
|
|
5615
|
-
constructor(_options){
|
|
5616
|
-
basic_define_property(this, "_options", void 0), basic_define_property(this, "globalContext", void 0), basic_define_property(this, "baseModuleScope", void 0), basic_define_property(this, "requirers", void 0), this._options = _options, this.globalContext = null, this.baseModuleScope = null, this.requirers = new Map();
|
|
5617
|
-
}
|
|
5618
|
-
}
|
|
5619
|
-
let cjs_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), cjs_define = (...args)=>{
|
|
5620
|
-
args.pop()();
|
|
5621
|
-
};
|
|
5622
|
-
class CommonJsRunner extends BasicRunner {
|
|
5623
|
-
createGlobalContext() {
|
|
5624
|
-
return {
|
|
5625
|
-
console: console,
|
|
5626
|
-
setTimeout: (cb, ms, ...args)=>{
|
|
5627
|
-
let timeout = setTimeout(cb, ms, ...args);
|
|
5628
|
-
return timeout.unref(), timeout;
|
|
5629
|
-
},
|
|
5630
|
-
clearTimeout: clearTimeout,
|
|
5631
|
-
queueMicrotask
|
|
5632
|
-
};
|
|
5633
|
-
}
|
|
5634
|
-
createBaseModuleScope() {
|
|
5635
|
-
return {
|
|
5636
|
-
console: this.globalContext.console,
|
|
5637
|
-
setTimeout: this.globalContext.setTimeout,
|
|
5638
|
-
clearTimeout: this.globalContext.clearTimeout,
|
|
5639
|
-
nsObj: (m)=>(Object.defineProperty(m, Symbol.toStringTag, {
|
|
5640
|
-
value: 'Module'
|
|
5641
|
-
}), m),
|
|
5642
|
-
queueMicrotask
|
|
5643
|
-
};
|
|
5644
|
-
}
|
|
5645
|
-
createModuleScope(requireFn, m, file) {
|
|
5646
|
-
return {
|
|
5647
|
-
...this.baseModuleScope,
|
|
5648
|
-
require: requireFn.bind(null, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(file.path)),
|
|
5649
|
-
module: m,
|
|
5650
|
-
exports: m.exports,
|
|
5651
|
-
__dirname: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(file.path),
|
|
5652
|
-
__filename: file.path,
|
|
5653
|
-
define: cjs_define
|
|
5654
|
-
};
|
|
5655
|
-
}
|
|
5656
|
-
createRunner() {
|
|
5657
|
-
this.requirers.set('miss', this.createMissRequirer()), this.requirers.set('entry', this.createCjsRequirer());
|
|
5658
|
-
}
|
|
5659
|
-
createMissRequirer() {
|
|
5660
|
-
return (_currentDirectory, modulePath, _context = {})=>{
|
|
5661
|
-
let resolvedPath = cjs_require.resolve(modulePath, {
|
|
5662
|
-
paths: [
|
|
5663
|
-
_currentDirectory
|
|
5664
|
-
]
|
|
5665
|
-
});
|
|
5666
|
-
return cjs_require(resolvedPath.startsWith('node:') ? resolvedPath.slice(5) : resolvedPath);
|
|
5667
|
-
};
|
|
5668
|
-
}
|
|
5669
|
-
createCjsRequirer() {
|
|
5670
|
-
let requireCache = Object.create(null);
|
|
5671
|
-
return (currentDirectory, modulePath, context = {})=>{
|
|
5672
|
-
let file = context.file || this.getFile(modulePath, currentDirectory);
|
|
5673
|
-
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5674
|
-
if (file.path in requireCache) return requireCache[file.path].exports;
|
|
5675
|
-
let m = {
|
|
5676
|
-
exports: {}
|
|
5677
|
-
};
|
|
5678
|
-
requireCache[file.path] = m;
|
|
5679
|
-
let currentModuleScope = this.createModuleScope(this.getRequire(), m, file), args = Object.keys(currentModuleScope), argValues = args.map((arg)=>currentModuleScope[arg]), code = `(function(${args.join(', ')}) {
|
|
5680
|
-
${file.content}
|
|
5681
|
-
})`;
|
|
5682
|
-
this.preExecute(code, file);
|
|
5683
|
-
let dynamicImport = Function('specifier', 'return import(specifier)');
|
|
5684
|
-
return __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.runInThisContext(code, {
|
|
5685
|
-
filename: file.path,
|
|
5686
|
-
importModuleDynamically: async (specifier)=>await dynamicImport(specifier)
|
|
5687
|
-
}).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
|
|
5517
|
+
let started = !1, { end, write, on, writeHead } = res, listeners = [], start = ()=>{
|
|
5518
|
+
if (!started) {
|
|
5519
|
+
if (started = !0, shouldCompress(res)) for (let listener of (res.setHeader('Content-Encoding', 'gzip'), res.removeHeader('Content-Length'), (gzip = __WEBPACK_EXTERNAL_MODULE_node_zlib_a5bb16fc__.default.createGzip({
|
|
5520
|
+
level
|
|
5521
|
+
})).on('data', (chunk)=>{
|
|
5522
|
+
!1 === write.call(res, chunk) && gzip.pause();
|
|
5523
|
+
}), on.call(res, 'drain', ()=>gzip.resume()), gzip.on('end', ()=>{
|
|
5524
|
+
end.call(res);
|
|
5525
|
+
}), listeners))gzip.on.apply(gzip, listener);
|
|
5526
|
+
else for (let listener of listeners)on.apply(res, listener);
|
|
5527
|
+
writeHead.call(res, writeHeadStatus ?? res.statusCode);
|
|
5528
|
+
}
|
|
5688
5529
|
};
|
|
5530
|
+
res.writeHead = (status, reason, headers)=>{
|
|
5531
|
+
if (reason) for (let [key, value] of Object.entries(headers || reason))res.setHeader(key, value);
|
|
5532
|
+
return writeHeadStatus = status, res;
|
|
5533
|
+
}, res.write = (...args)=>(start(), gzip ? gzip.write(...args) : write.apply(res, args)), res.end = (...args)=>(start(), gzip ? gzip.end(...args) : end.apply(res, args)), res.on = (type, listener)=>(started ? gzip && 'drain' === type ? gzip.on(type, listener) : on.call(res, type, listener) : listeners.push([
|
|
5534
|
+
type,
|
|
5535
|
+
listener
|
|
5536
|
+
]), res), next();
|
|
5537
|
+
}, faviconFallbackMiddleware = (req, res, next)=>{
|
|
5538
|
+
'/favicon.ico' === req.url ? (res.statusCode = 204, res.end()) : next();
|
|
5539
|
+
}, getStatusCodeColor = (status)=>status >= 500 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.red : status >= 400 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow : status >= 300 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan : status >= 200 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green : (res)=>res, getRequestLoggerMiddleware = async ()=>{
|
|
5540
|
+
let { default: onFinished } = await import("../compiled/on-finished/index.js");
|
|
5541
|
+
return (req, res, next)=>{
|
|
5542
|
+
let _startAt = process.hrtime();
|
|
5543
|
+
onFinished(res, ()=>{
|
|
5544
|
+
let method = req.method, url = req.originalUrl || req.url, status = Number(res.statusCode), statusColor = getStatusCodeColor(status), endAt = process.hrtime(), totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
5545
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`${statusColor(status)} ${method} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(url)} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(`${totalTime.toFixed(3)} ms`)}`);
|
|
5546
|
+
}), next();
|
|
5547
|
+
};
|
|
5548
|
+
}, notFoundMiddleware = (_req, res, _next)=>{
|
|
5549
|
+
res.statusCode = 404, res.end();
|
|
5550
|
+
}, optionsFallbackMiddleware = (req, res, next)=>{
|
|
5551
|
+
if ('OPTIONS' === req.method) {
|
|
5552
|
+
res.statusCode = 204, res.setHeader('Content-Length', '0'), res.end();
|
|
5553
|
+
return;
|
|
5689
5554
|
}
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
var _this__options_compilerOptions_experiments;
|
|
5695
|
-
super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
|
|
5696
|
-
let outputModule = null === (_this__options_compilerOptions_experiments = this._options.compilerOptions.experiments) || void 0 === _this__options_compilerOptions_experiments ? void 0 : _this__options_compilerOptions_experiments.outputModule;
|
|
5697
|
-
this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
|
|
5698
|
-
let file = this.getFile(modulePath, currentDirectory);
|
|
5699
|
-
return file ? outputModule && !file.path.endsWith('.cjs') ? this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
5700
|
-
...context,
|
|
5701
|
-
file
|
|
5702
|
-
}) : this.requirers.get('cjs')(currentDirectory, modulePath, {
|
|
5703
|
-
...context,
|
|
5704
|
-
file
|
|
5705
|
-
}) : this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5706
|
-
});
|
|
5707
|
-
}
|
|
5708
|
-
createEsmRequirer() {
|
|
5709
|
-
let esmContext = __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.createContext(this.baseModuleScope, {
|
|
5710
|
-
name: 'context for esm'
|
|
5711
|
-
}), esmCache = new Map(), esmIdentifier = this._options.name;
|
|
5712
|
-
return (currentDirectory, modulePath, context = {})=>{
|
|
5713
|
-
if (!__WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.SourceTextModule) throw Error('[rsbuild:runner] Running ESM bundle needs add Node.js option "--experimental-vm-modules".');
|
|
5714
|
-
let _require = this.getRequire(), file = context.file || this.getFile(modulePath, currentDirectory);
|
|
5715
|
-
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5716
|
-
let esm = esmCache.get(file.path);
|
|
5717
|
-
return (esm || (esm = new __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.SourceTextModule(file.content, {
|
|
5718
|
-
identifier: `${esmIdentifier}-${file.path}`,
|
|
5719
|
-
url: `${(0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
5720
|
-
context: esmContext,
|
|
5721
|
-
initializeImportMeta: (meta, _)=>{
|
|
5722
|
-
meta.url = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(file.path).href;
|
|
5723
|
-
},
|
|
5724
|
-
importModuleDynamically: async (specifier, module)=>{
|
|
5725
|
-
let result = await _require(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(file.path), specifier, {
|
|
5726
|
-
esmMode: type_EsmMode.Evaluated
|
|
5727
|
-
});
|
|
5728
|
-
return await asModule(result, module.context);
|
|
5729
|
-
}
|
|
5730
|
-
}), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
|
|
5731
|
-
if (await esm.link(async (specifier, referencingModule)=>await asModule(await _require(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(referencingModule.url)), specifier, {
|
|
5732
|
-
esmMode: type_EsmMode.Unlinked
|
|
5733
|
-
}), referencingModule.context, !0)), esm.instantiate && esm.instantiate(), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
|
|
5734
|
-
let ns = esm.namespace;
|
|
5735
|
-
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
5736
|
-
})();
|
|
5737
|
-
};
|
|
5738
|
-
}
|
|
5739
|
-
}
|
|
5740
|
-
class BasicRunnerFactory {
|
|
5741
|
-
create(options) {
|
|
5742
|
-
return this.createRunner(options);
|
|
5743
|
-
}
|
|
5744
|
-
createRunner(options) {
|
|
5745
|
-
let runnerOptions = {
|
|
5746
|
-
name: this.name,
|
|
5747
|
-
...options
|
|
5748
|
-
}, { compilerOptions } = options;
|
|
5749
|
-
if ('web' === compilerOptions.target || 'webworker' === compilerOptions.target) throw Error(`[rsbuild:runner] Not support run "${compilerOptions.target}" resource in Rsbuild server`);
|
|
5750
|
-
return new EsmRunner(runnerOptions);
|
|
5751
|
-
}
|
|
5752
|
-
constructor(name){
|
|
5753
|
-
var key, value;
|
|
5754
|
-
value = void 0, (key = "name") in this ? Object.defineProperty(this, key, {
|
|
5755
|
-
value: value,
|
|
5756
|
-
enumerable: !0,
|
|
5757
|
-
configurable: !0,
|
|
5758
|
-
writable: !0
|
|
5759
|
-
}) : this[key] = value, this.name = name;
|
|
5760
|
-
}
|
|
5761
|
-
}
|
|
5762
|
-
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions).run(bundlePath), loadBundle = async (stats, entryName, utils)=>{
|
|
5763
|
-
let { chunks, entrypoints, outputPath } = stats.toJson({
|
|
5764
|
-
all: !1,
|
|
5765
|
-
chunks: !0,
|
|
5766
|
-
entrypoints: !0,
|
|
5767
|
-
outputPath: !0
|
|
5768
|
-
});
|
|
5769
|
-
if (!(null == entrypoints ? void 0 : entrypoints[entryName])) throw Error(`[rsbuild:loadBundle] Can't find entry: "${entryName}"`);
|
|
5770
|
-
let { chunks: entryChunks = [] } = entrypoints[entryName], files = entryChunks.reduce((prev, entryChunkName)=>{
|
|
5771
|
-
let chunk = null == chunks ? void 0 : chunks.find((chunk)=>{
|
|
5772
|
-
var _chunk_names;
|
|
5773
|
-
return chunk.entry && (null === (_chunk_names = chunk.names) || void 0 === _chunk_names ? void 0 : _chunk_names.includes(String(entryChunkName)));
|
|
5774
|
-
});
|
|
5775
|
-
return (null == chunk ? void 0 : chunk.files) ? prev.concat(chunk.files.filter((file)=>!file.endsWith('.css'))) : prev;
|
|
5776
|
-
}, []);
|
|
5777
|
-
if (0 === files.length) throw Error(`[rsbuild:loadBundle] Failed to get bundle by entryName: "${entryName}"`);
|
|
5778
|
-
if (files.length > 1) throw Error(`[rsbuild:loadBundle] Only support load single entry chunk, but got ${files.length}: ${files.join(',')}`);
|
|
5779
|
-
let allChunkFiles = (null == chunks ? void 0 : chunks.flatMap((c)=>c.files).map((file)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, file))) || [];
|
|
5780
|
-
return await runner_run({
|
|
5781
|
-
bundlePath: files[0],
|
|
5782
|
-
dist: outputPath,
|
|
5783
|
-
compilerOptions: stats.compilation.options,
|
|
5784
|
-
readFileSync: utils.readFileSync,
|
|
5785
|
-
isBundleOutput: (modulePath)=>allChunkFiles.includes(modulePath)
|
|
5786
|
-
});
|
|
5787
|
-
}, getTransformedHtml = async (entryName, utils)=>{
|
|
5788
|
-
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
5789
|
-
if (!htmlPath) throw Error(`[rsbuild:getTransformedHtml] Failed to get HTML file by entryName: "${entryName}"`);
|
|
5790
|
-
let fileName = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, htmlPath);
|
|
5791
|
-
return utils.readFileSync(fileName);
|
|
5792
|
-
}, createCacheableFunction = (getter)=>{
|
|
5793
|
-
let cache = new WeakMap();
|
|
5794
|
-
return async (stats, entryName, utils)=>{
|
|
5795
|
-
let cachedEntries = cache.get(stats);
|
|
5796
|
-
if (null == cachedEntries ? void 0 : cachedEntries[entryName]) return cachedEntries[entryName];
|
|
5797
|
-
let res = await getter(stats, entryName, utils);
|
|
5798
|
-
return cache.set(stats, {
|
|
5799
|
-
...cachedEntries || {},
|
|
5800
|
-
[entryName]: res
|
|
5801
|
-
}), res;
|
|
5802
|
-
};
|
|
5803
|
-
}, ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, shouldCompress = (res)=>{
|
|
5804
|
-
if (res.getHeader('Content-Encoding')) return !1;
|
|
5805
|
-
let contentType = String(res.getHeader('Content-Type'));
|
|
5806
|
-
if (contentType && !CONTENT_TYPE_REGEX.test(contentType)) return !1;
|
|
5807
|
-
let size = res.getHeader('Content-Length');
|
|
5808
|
-
return void 0 === size || Number(size) > 1024;
|
|
5809
|
-
}, gzipMiddleware = ({ level = __WEBPACK_EXTERNAL_MODULE_node_zlib_a5bb16fc__.default.constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
5810
|
-
let gzip, writeHeadStatus;
|
|
5811
|
-
let accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
|
|
5812
|
-
if ('HEAD' === req.method || !encoding) {
|
|
5813
|
-
next();
|
|
5814
|
-
return;
|
|
5815
|
-
}
|
|
5816
|
-
let started = !1, { end, write, on, writeHead } = res, listeners = [], start = ()=>{
|
|
5817
|
-
if (!started) {
|
|
5818
|
-
if (started = !0, shouldCompress(res)) for (let listener of (res.setHeader('Content-Encoding', 'gzip'), res.removeHeader('Content-Length'), (gzip = __WEBPACK_EXTERNAL_MODULE_node_zlib_a5bb16fc__.default.createGzip({
|
|
5819
|
-
level
|
|
5820
|
-
})).on('data', (chunk)=>{
|
|
5821
|
-
!1 === write.call(res, chunk) && gzip.pause();
|
|
5822
|
-
}), on.call(res, 'drain', ()=>gzip.resume()), gzip.on('end', ()=>{
|
|
5823
|
-
end.call(res);
|
|
5824
|
-
}), listeners))gzip.on.apply(gzip, listener);
|
|
5825
|
-
else for (let listener of listeners)on.apply(res, listener);
|
|
5826
|
-
writeHead.call(res, writeHeadStatus ?? res.statusCode);
|
|
5827
|
-
}
|
|
5828
|
-
};
|
|
5829
|
-
res.writeHead = (status, reason, headers)=>{
|
|
5830
|
-
if (reason) for (let [key, value] of Object.entries(headers || reason))res.setHeader(key, value);
|
|
5831
|
-
return writeHeadStatus = status, res;
|
|
5832
|
-
}, res.write = (...args)=>(start(), gzip ? gzip.write(...args) : write.apply(res, args)), res.end = (...args)=>(start(), gzip ? gzip.end(...args) : end.apply(res, args)), res.on = (type, listener)=>(started ? gzip && 'drain' === type ? gzip.on(type, listener) : on.call(res, type, listener) : listeners.push([
|
|
5833
|
-
type,
|
|
5834
|
-
listener
|
|
5835
|
-
]), res), next();
|
|
5836
|
-
}, faviconFallbackMiddleware = (req, res, next)=>{
|
|
5837
|
-
'/favicon.ico' === req.url ? (res.statusCode = 204, res.end()) : next();
|
|
5838
|
-
}, getStatusCodeColor = (status)=>status >= 500 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.red : status >= 400 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow : status >= 300 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.cyan : status >= 200 ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green : (res)=>res, getRequestLoggerMiddleware = async ()=>{
|
|
5839
|
-
let { default: onFinished } = await import("../compiled/on-finished/index.js");
|
|
5840
|
-
return (req, res, next)=>{
|
|
5841
|
-
let _startAt = process.hrtime();
|
|
5842
|
-
onFinished(res, ()=>{
|
|
5843
|
-
let method = req.method, url = req.originalUrl || req.url, status = Number(res.statusCode), statusColor = getStatusCodeColor(status), endAt = process.hrtime(), totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
5844
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`${statusColor(status)} ${method} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(url)} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(`${totalTime.toFixed(3)} ms`)}`);
|
|
5845
|
-
}), next();
|
|
5846
|
-
};
|
|
5847
|
-
}, notFoundMiddleware = (_req, res, _next)=>{
|
|
5848
|
-
res.statusCode = 404, res.end();
|
|
5849
|
-
}, optionsFallbackMiddleware = (req, res, next)=>{
|
|
5850
|
-
if ('OPTIONS' === req.method) {
|
|
5851
|
-
res.statusCode = 204, res.setHeader('Content-Length', '0'), res.end();
|
|
5852
|
-
return;
|
|
5853
|
-
}
|
|
5854
|
-
next();
|
|
5855
|
-
}, middlewares_isFileExists = async (filePath, outputFileSystem)=>new Promise((resolve)=>{
|
|
5856
|
-
outputFileSystem.stat(filePath, (_error, stats)=>{
|
|
5857
|
-
resolve(null == stats ? void 0 : stats.isFile());
|
|
5555
|
+
next();
|
|
5556
|
+
}, middlewares_isFileExists = async (filePath, outputFileSystem)=>new Promise((resolve)=>{
|
|
5557
|
+
outputFileSystem.stat(filePath, (_error, stats)=>{
|
|
5558
|
+
resolve(null == stats ? void 0 : stats.isFile());
|
|
5858
5559
|
});
|
|
5859
5560
|
}), maybeHTMLRequest = (req)=>{
|
|
5860
5561
|
if (!req.url || !req.headers || 'GET' !== req.method && 'HEAD' !== req.method) return !1;
|
|
5861
5562
|
let { accept } = req.headers;
|
|
5862
5563
|
return 'string' == typeof accept && (accept.includes('text/html') || accept.includes('*/*'));
|
|
5863
|
-
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getHtmlCompletionMiddleware = ({ distPath,
|
|
5564
|
+
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getHtmlCompletionMiddleware = ({ distPath, compilationManager })=>async (req, res, next)=>{
|
|
5864
5565
|
if (!maybeHTMLRequest(req)) return next();
|
|
5865
|
-
let pathname = getUrlPathname(req.url), rewrite = (newUrl)=>(req.url = newUrl,
|
|
5566
|
+
let pathname = getUrlPathname(req.url), rewrite = (newUrl)=>(req.url = newUrl, compilationManager.middleware(req, res, (...args)=>{
|
|
5866
5567
|
next(...args);
|
|
5867
5568
|
}));
|
|
5868
5569
|
if (pathname.endsWith('/')) {
|
|
5869
5570
|
let newUrl = `${pathname}index.html`, filePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(distPath, newUrl);
|
|
5870
|
-
if (await middlewares_isFileExists(filePath, outputFileSystem)) return rewrite(newUrl);
|
|
5571
|
+
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) return rewrite(newUrl);
|
|
5871
5572
|
} else if (!__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.extname(pathname)) {
|
|
5872
5573
|
let newUrl = `${pathname}.html`, filePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(distPath, newUrl);
|
|
5873
|
-
if (await middlewares_isFileExists(filePath, outputFileSystem)) return rewrite(newUrl);
|
|
5574
|
+
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) return rewrite(newUrl);
|
|
5874
5575
|
}
|
|
5875
5576
|
next();
|
|
5876
5577
|
}, getBaseMiddleware = ({ base })=>async (req, res, next)=>{
|
|
@@ -5893,12 +5594,12 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
|
|
|
5893
5594
|
res.writeHead(404, {
|
|
5894
5595
|
'Content-Type': 'text/plain'
|
|
5895
5596
|
}), res.end(`The server is configured with a base URL of ${base} - did you mean to visit ${redirectPath} instead?`);
|
|
5896
|
-
}, getHtmlFallbackMiddleware = ({ htmlFallback, distPath,
|
|
5597
|
+
}, getHtmlFallbackMiddleware = ({ htmlFallback, distPath, compilationManager })=>async (req, res, next)=>{
|
|
5897
5598
|
if (!maybeHTMLRequest(req) || '/favicon.ico' === req.url || 'index' !== htmlFallback) return next();
|
|
5898
5599
|
let filePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(distPath, 'index.html');
|
|
5899
|
-
if (await middlewares_isFileExists(filePath, outputFileSystem)) {
|
|
5600
|
+
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) {
|
|
5900
5601
|
let newUrl = '/index.html';
|
|
5901
|
-
return 'verbose' === __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`${req.method} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(`${req.url} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('fallback')} to ${newUrl}`)}`), req.url = newUrl,
|
|
5602
|
+
return 'verbose' === __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`${req.method} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(`${req.url} ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('fallback')} to ${newUrl}`)}`), req.url = newUrl, compilationManager.middleware(req, res, (...args)=>next(...args));
|
|
5902
5603
|
}
|
|
5903
5604
|
next();
|
|
5904
5605
|
}, viewingServedFilesMiddleware = ({ environments })=>async (req, res, next)=>{
|
|
@@ -5990,9 +5691,12 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
|
|
|
5990
5691
|
for (let middleware of proxyMiddlewares)'function' == typeof middleware.upgrade && middleware.upgrade(req, socket, head);
|
|
5991
5692
|
}
|
|
5992
5693
|
};
|
|
5993
|
-
}, applySetupMiddlewares = (dev, environments,
|
|
5694
|
+
}, applySetupMiddlewares = (dev, environments, compilationManager)=>{
|
|
5994
5695
|
let setupMiddlewares = dev.setupMiddlewares || [], serverOptions = {
|
|
5995
|
-
sockWrite: (type, data)=>null ==
|
|
5696
|
+
sockWrite: (type, data)=>null == compilationManager ? void 0 : compilationManager.socketServer.sockWrite({
|
|
5697
|
+
type,
|
|
5698
|
+
data
|
|
5699
|
+
}),
|
|
5996
5700
|
environments
|
|
5997
5701
|
}, before = [], after = [];
|
|
5998
5702
|
for (let handler of setupMiddlewares)handler({
|
|
@@ -6003,20 +5707,20 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
|
|
|
6003
5707
|
before,
|
|
6004
5708
|
after
|
|
6005
5709
|
};
|
|
6006
|
-
}, applyDefaultMiddlewares = async ({ middlewares, server,
|
|
5710
|
+
}, applyDefaultMiddlewares = async ({ dev, middlewares, server, compilationManager, context, pwd, environments, postCallbacks })=>{
|
|
6007
5711
|
let upgradeEvents = [];
|
|
6008
|
-
if (server.compress && middlewares.push(gzipMiddleware()),
|
|
6009
|
-
var _parseUrl;
|
|
6010
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
6011
|
-
let path = req.url ? null === (_parseUrl = parseUrl(req.url)) || void 0 === _parseUrl ? void 0 : _parseUrl.pathname : '';
|
|
6012
|
-
(null == path ? void 0 : path.includes('hot-update')) && res.setHeader('Access-Control-Allow-Credentials', 'false');
|
|
6013
|
-
let confHeaders = server.headers;
|
|
6014
|
-
if (confHeaders) for (let [key, value] of Object.entries(confHeaders))res.setHeader(key, value);
|
|
6015
|
-
next();
|
|
6016
|
-
}), server.cors) {
|
|
5712
|
+
if (server.compress && middlewares.push(gzipMiddleware()), server.cors) {
|
|
6017
5713
|
let { default: corsMiddleware } = await import("../compiled/cors/index.js");
|
|
6018
5714
|
middlewares.push(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
6019
5715
|
}
|
|
5716
|
+
let { headers } = server;
|
|
5717
|
+
if (headers && middlewares.push((_req, res, next)=>{
|
|
5718
|
+
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
5719
|
+
next();
|
|
5720
|
+
}), 'dev' === context.action && 'rspack' === context.bundlerType && dev.lazyCompilation && compilationManager) {
|
|
5721
|
+
let { compiler } = compilationManager;
|
|
5722
|
+
middlewares.push(__WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.default.experiments.lazyCompilationMiddleware(helpers_isMultiCompiler(compiler) ? compiler.compilers[0] : compiler, dev.lazyCompilation));
|
|
5723
|
+
}
|
|
6020
5724
|
if (server.proxy) {
|
|
6021
5725
|
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy);
|
|
6022
5726
|
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.push(middleware);
|
|
@@ -6025,20 +5729,17 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
|
|
|
6025
5729
|
base: server.base
|
|
6026
5730
|
}));
|
|
6027
5731
|
let { default: launchEditorMiddleware } = await import("../compiled/launch-editor-middleware/index.js");
|
|
6028
|
-
middlewares.push([
|
|
5732
|
+
for (let publicDir of (middlewares.push([
|
|
6029
5733
|
'/__open-in-editor',
|
|
6030
5734
|
launchEditorMiddleware()
|
|
6031
5735
|
]), middlewares.push(viewingServedFilesMiddleware({
|
|
6032
5736
|
environments
|
|
6033
|
-
})),
|
|
5737
|
+
})), compilationManager && (middlewares.push(compilationManager.middleware), upgradeEvents.push(compilationManager.socketServer.upgrade), middlewares.push((req, res, next)=>{
|
|
6034
5738
|
var _req_url;
|
|
6035
5739
|
(null === (_req_url = req.url) || void 0 === _req_url ? void 0 : _req_url.endsWith('.hot-update.json')) && 'OPTIONS' !== req.method ? (res.statusCode = 404, res.end()) : next();
|
|
6036
|
-
}))
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
distPath,
|
|
6040
|
-
callback: compileMiddlewareAPI.middleware,
|
|
6041
|
-
outputFileSystem
|
|
5740
|
+
})), compilationManager && middlewares.push(getHtmlCompletionMiddleware({
|
|
5741
|
+
compilationManager,
|
|
5742
|
+
distPath: context.distPath
|
|
6042
5743
|
})), normalizePublicDirs(null == server ? void 0 : server.publicDir))){
|
|
6043
5744
|
let { default: sirv } = await import("../compiled/sirv/index.js"), { name } = publicDir, assetMiddleware = sirv((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.isAbsolute)(name) ? name : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(pwd, name), {
|
|
6044
5745
|
etag: !0,
|
|
@@ -6047,24 +5748,23 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
|
|
|
6047
5748
|
middlewares.push(assetMiddleware);
|
|
6048
5749
|
}
|
|
6049
5750
|
for (let callback of postCallbacks)callback();
|
|
6050
|
-
if (
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
htmlFallback: server.htmlFallback
|
|
6054
|
-
outputFileSystem
|
|
5751
|
+
if (compilationManager && middlewares.push(getHtmlFallbackMiddleware({
|
|
5752
|
+
compilationManager,
|
|
5753
|
+
distPath: context.distPath,
|
|
5754
|
+
htmlFallback: server.htmlFallback
|
|
6055
5755
|
})), server.historyApiFallback) {
|
|
6056
5756
|
let { default: connectHistoryApiFallback } = await import("../compiled/connect-history-api-fallback/index.js"), historyApiFallbackMiddleware = connectHistoryApiFallback(!0 === server.historyApiFallback ? {} : server.historyApiFallback);
|
|
6057
|
-
middlewares.push(historyApiFallbackMiddleware), (null ==
|
|
5757
|
+
middlewares.push(historyApiFallbackMiddleware), (null == compilationManager ? void 0 : compilationManager.middleware) && middlewares.push(compilationManager.middleware);
|
|
6058
5758
|
}
|
|
6059
5759
|
return middlewares.push(faviconFallbackMiddleware), {
|
|
6060
5760
|
onUpgrade: (...args)=>{
|
|
6061
5761
|
for (let cb of upgradeEvents)cb(...args);
|
|
6062
5762
|
}
|
|
6063
5763
|
};
|
|
6064
|
-
},
|
|
6065
|
-
let middlewares = [], { environments,
|
|
5764
|
+
}, getDevMiddlewares = async (options)=>{
|
|
5765
|
+
let middlewares = [], { environments, compilationManager } = options;
|
|
6066
5766
|
'verbose' === __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level && middlewares.push(await getRequestLoggerMiddleware());
|
|
6067
|
-
let { before, after } = applySetupMiddlewares(options.dev, environments,
|
|
5767
|
+
let { before, after } = applySetupMiddlewares(options.dev, environments, compilationManager);
|
|
6068
5768
|
middlewares.push(...before);
|
|
6069
5769
|
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
6070
5770
|
...options,
|
|
@@ -6072,11 +5772,263 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunne
|
|
|
6072
5772
|
});
|
|
6073
5773
|
return middlewares.push(...after), {
|
|
6074
5774
|
close: async ()=>{
|
|
6075
|
-
await (null ==
|
|
5775
|
+
await (null == compilationManager ? void 0 : compilationManager.close());
|
|
6076
5776
|
},
|
|
6077
5777
|
onUpgrade,
|
|
6078
5778
|
middlewares
|
|
6079
5779
|
};
|
|
5780
|
+
}, SYNTHETIC_MODULES_STORE = '__SYNTHETIC_MODULES_STORE', asModule = async (something, context, unlinked)=>{
|
|
5781
|
+
if (something instanceof __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.Module) return something;
|
|
5782
|
+
context[SYNTHETIC_MODULES_STORE] = context[SYNTHETIC_MODULES_STORE] || [];
|
|
5783
|
+
let i = context[SYNTHETIC_MODULES_STORE].length;
|
|
5784
|
+
context[SYNTHETIC_MODULES_STORE].push(something);
|
|
5785
|
+
let code = [
|
|
5786
|
+
...new Set([
|
|
5787
|
+
'default',
|
|
5788
|
+
...Object.keys(something)
|
|
5789
|
+
])
|
|
5790
|
+
].map((name)=>`const _${name} = ${SYNTHETIC_MODULES_STORE}[${i}]${'default' === name ? '' : `[${JSON.stringify(name)}]`}; export { _${name} as ${name}};`).join('\n'), m = new __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.SourceTextModule(code, {
|
|
5791
|
+
context
|
|
5792
|
+
});
|
|
5793
|
+
return unlinked || (await m.link(()=>{}), m.instantiate && m.instantiate(), await m.evaluate()), m;
|
|
5794
|
+
};
|
|
5795
|
+
function basic_define_property(obj, key, value) {
|
|
5796
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
5797
|
+
value: value,
|
|
5798
|
+
enumerable: !0,
|
|
5799
|
+
configurable: !0,
|
|
5800
|
+
writable: !0
|
|
5801
|
+
}) : obj[key] = value, obj;
|
|
5802
|
+
}
|
|
5803
|
+
let isRelativePath = (p)=>/^\.\.?\//.test(p), getSubPath = (p)=>{
|
|
5804
|
+
let lastSlash = p.lastIndexOf('/'), firstSlash = p.indexOf('/');
|
|
5805
|
+
if (-1 !== lastSlash && firstSlash !== lastSlash) {
|
|
5806
|
+
if (-1 !== firstSlash) {
|
|
5807
|
+
let next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5808
|
+
for(; '.' === dir;)firstSlash = next, next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5809
|
+
}
|
|
5810
|
+
return p.slice(firstSlash + 1, lastSlash + 1);
|
|
5811
|
+
}
|
|
5812
|
+
return '';
|
|
5813
|
+
};
|
|
5814
|
+
class BasicRunner {
|
|
5815
|
+
run(file) {
|
|
5816
|
+
this.globalContext || (this.globalContext = this.createGlobalContext()), this.baseModuleScope = this.createBaseModuleScope(), this.createRunner();
|
|
5817
|
+
let res = this.getRequire()(this._options.dist, file.startsWith('./') ? file : `./${file}`);
|
|
5818
|
+
return 'object' == typeof res && 'then' in res ? res : Promise.resolve(res);
|
|
5819
|
+
}
|
|
5820
|
+
getRequire() {
|
|
5821
|
+
let entryRequire = this.requirers.get('entry');
|
|
5822
|
+
return (currentDirectory, modulePath, context = {})=>entryRequire(currentDirectory, Array.isArray(modulePath) ? modulePath : modulePath.split('?')[0], context);
|
|
5823
|
+
}
|
|
5824
|
+
getFile(modulePath, currentDirectory) {
|
|
5825
|
+
if (Array.isArray(modulePath)) return {
|
|
5826
|
+
path: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(currentDirectory, '.array-require.js'),
|
|
5827
|
+
content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
|
|
5828
|
+
subPath: ''
|
|
5829
|
+
};
|
|
5830
|
+
let joinedPath = isRelativePath(modulePath) ? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(currentDirectory, modulePath) : modulePath;
|
|
5831
|
+
return this._options.isBundleOutput(joinedPath) ? {
|
|
5832
|
+
path: joinedPath,
|
|
5833
|
+
content: this._options.readFileSync(joinedPath),
|
|
5834
|
+
subPath: getSubPath(modulePath)
|
|
5835
|
+
} : null;
|
|
5836
|
+
}
|
|
5837
|
+
preExecute(_code, _file) {}
|
|
5838
|
+
postExecute(_m, _file) {}
|
|
5839
|
+
createRunner() {
|
|
5840
|
+
this.requirers.set('entry', (_currentDirectory, _modulePath, _context = {})=>{
|
|
5841
|
+
throw Error('[rsbuild:runner] Not implement');
|
|
5842
|
+
});
|
|
5843
|
+
}
|
|
5844
|
+
constructor(_options){
|
|
5845
|
+
basic_define_property(this, "_options", void 0), basic_define_property(this, "globalContext", void 0), basic_define_property(this, "baseModuleScope", void 0), basic_define_property(this, "requirers", void 0), this._options = _options, this.globalContext = null, this.baseModuleScope = null, this.requirers = new Map();
|
|
5846
|
+
}
|
|
5847
|
+
}
|
|
5848
|
+
let cjs_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), cjs_define = (...args)=>{
|
|
5849
|
+
args.pop()();
|
|
5850
|
+
};
|
|
5851
|
+
class CommonJsRunner extends BasicRunner {
|
|
5852
|
+
createGlobalContext() {
|
|
5853
|
+
return {
|
|
5854
|
+
console: console,
|
|
5855
|
+
setTimeout: (cb, ms, ...args)=>{
|
|
5856
|
+
let timeout = setTimeout(cb, ms, ...args);
|
|
5857
|
+
return timeout.unref(), timeout;
|
|
5858
|
+
},
|
|
5859
|
+
clearTimeout: clearTimeout,
|
|
5860
|
+
queueMicrotask
|
|
5861
|
+
};
|
|
5862
|
+
}
|
|
5863
|
+
createBaseModuleScope() {
|
|
5864
|
+
return {
|
|
5865
|
+
console: this.globalContext.console,
|
|
5866
|
+
setTimeout: this.globalContext.setTimeout,
|
|
5867
|
+
clearTimeout: this.globalContext.clearTimeout,
|
|
5868
|
+
nsObj: (m)=>(Object.defineProperty(m, Symbol.toStringTag, {
|
|
5869
|
+
value: 'Module'
|
|
5870
|
+
}), m),
|
|
5871
|
+
queueMicrotask
|
|
5872
|
+
};
|
|
5873
|
+
}
|
|
5874
|
+
createModuleScope(requireFn, m, file) {
|
|
5875
|
+
return {
|
|
5876
|
+
...this.baseModuleScope,
|
|
5877
|
+
require: requireFn.bind(null, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(file.path)),
|
|
5878
|
+
module: m,
|
|
5879
|
+
exports: m.exports,
|
|
5880
|
+
__dirname: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(file.path),
|
|
5881
|
+
__filename: file.path,
|
|
5882
|
+
define: cjs_define
|
|
5883
|
+
};
|
|
5884
|
+
}
|
|
5885
|
+
createRunner() {
|
|
5886
|
+
this.requirers.set('miss', this.createMissRequirer()), this.requirers.set('entry', this.createCjsRequirer());
|
|
5887
|
+
}
|
|
5888
|
+
createMissRequirer() {
|
|
5889
|
+
return (_currentDirectory, modulePath, _context = {})=>{
|
|
5890
|
+
let resolvedPath = cjs_require.resolve(modulePath, {
|
|
5891
|
+
paths: [
|
|
5892
|
+
_currentDirectory
|
|
5893
|
+
]
|
|
5894
|
+
});
|
|
5895
|
+
return cjs_require(resolvedPath.startsWith('node:') ? resolvedPath.slice(5) : resolvedPath);
|
|
5896
|
+
};
|
|
5897
|
+
}
|
|
5898
|
+
createCjsRequirer() {
|
|
5899
|
+
let requireCache = Object.create(null);
|
|
5900
|
+
return (currentDirectory, modulePath, context = {})=>{
|
|
5901
|
+
let file = context.file || this.getFile(modulePath, currentDirectory);
|
|
5902
|
+
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5903
|
+
if (file.path in requireCache) return requireCache[file.path].exports;
|
|
5904
|
+
let m = {
|
|
5905
|
+
exports: {}
|
|
5906
|
+
};
|
|
5907
|
+
requireCache[file.path] = m;
|
|
5908
|
+
let currentModuleScope = this.createModuleScope(this.getRequire(), m, file), args = Object.keys(currentModuleScope), argValues = args.map((arg)=>currentModuleScope[arg]), code = `(function(${args.join(', ')}) {
|
|
5909
|
+
${file.content}
|
|
5910
|
+
})`;
|
|
5911
|
+
this.preExecute(code, file);
|
|
5912
|
+
let dynamicImport = Function('specifier', 'return import(specifier)');
|
|
5913
|
+
return __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.runInThisContext(code, {
|
|
5914
|
+
filename: file.path,
|
|
5915
|
+
importModuleDynamically: async (specifier)=>await dynamicImport(specifier)
|
|
5916
|
+
}).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
|
|
5917
|
+
};
|
|
5918
|
+
}
|
|
5919
|
+
}
|
|
5920
|
+
var type_EsmMode = ((EsmMode = {})[EsmMode.Unknown = 0] = "Unknown", EsmMode[EsmMode.Evaluated = 1] = "Evaluated", EsmMode[EsmMode.Unlinked = 2] = "Unlinked", EsmMode);
|
|
5921
|
+
class EsmRunner extends CommonJsRunner {
|
|
5922
|
+
createRunner() {
|
|
5923
|
+
var _this__options_compilerOptions_experiments;
|
|
5924
|
+
super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
|
|
5925
|
+
let outputModule = null === (_this__options_compilerOptions_experiments = this._options.compilerOptions.experiments) || void 0 === _this__options_compilerOptions_experiments ? void 0 : _this__options_compilerOptions_experiments.outputModule;
|
|
5926
|
+
this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
|
|
5927
|
+
let file = this.getFile(modulePath, currentDirectory);
|
|
5928
|
+
return file ? outputModule && !file.path.endsWith('.cjs') ? this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
5929
|
+
...context,
|
|
5930
|
+
file
|
|
5931
|
+
}) : this.requirers.get('cjs')(currentDirectory, modulePath, {
|
|
5932
|
+
...context,
|
|
5933
|
+
file
|
|
5934
|
+
}) : this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5935
|
+
});
|
|
5936
|
+
}
|
|
5937
|
+
createEsmRequirer() {
|
|
5938
|
+
let esmContext = __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.createContext(this.baseModuleScope, {
|
|
5939
|
+
name: 'context for esm'
|
|
5940
|
+
}), esmCache = new Map(), esmIdentifier = this._options.name;
|
|
5941
|
+
return (currentDirectory, modulePath, context = {})=>{
|
|
5942
|
+
if (!__WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.SourceTextModule) throw Error('[rsbuild:runner] Running ESM bundle needs add Node.js option "--experimental-vm-modules".');
|
|
5943
|
+
let _require = this.getRequire(), file = context.file || this.getFile(modulePath, currentDirectory);
|
|
5944
|
+
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5945
|
+
let esm = esmCache.get(file.path);
|
|
5946
|
+
return (esm || (esm = new __WEBPACK_EXTERNAL_MODULE_node_vm_bd3d9cea__.default.SourceTextModule(file.content, {
|
|
5947
|
+
identifier: `${esmIdentifier}-${file.path}`,
|
|
5948
|
+
url: `${(0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
5949
|
+
context: esmContext,
|
|
5950
|
+
initializeImportMeta: (meta, _)=>{
|
|
5951
|
+
meta.url = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(file.path).href;
|
|
5952
|
+
},
|
|
5953
|
+
importModuleDynamically: async (specifier, module)=>{
|
|
5954
|
+
let result = await _require(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(file.path), specifier, {
|
|
5955
|
+
esmMode: type_EsmMode.Evaluated
|
|
5956
|
+
});
|
|
5957
|
+
return await asModule(result, module.context);
|
|
5958
|
+
}
|
|
5959
|
+
}), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
|
|
5960
|
+
if (await esm.link(async (specifier, referencingModule)=>await asModule(await _require(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(referencingModule.url)), specifier, {
|
|
5961
|
+
esmMode: type_EsmMode.Unlinked
|
|
5962
|
+
}), referencingModule.context, !0)), esm.instantiate && esm.instantiate(), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
|
|
5963
|
+
let ns = esm.namespace;
|
|
5964
|
+
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
5965
|
+
})();
|
|
5966
|
+
};
|
|
5967
|
+
}
|
|
5968
|
+
}
|
|
5969
|
+
class BasicRunnerFactory {
|
|
5970
|
+
create(options) {
|
|
5971
|
+
return this.createRunner(options);
|
|
5972
|
+
}
|
|
5973
|
+
createRunner(options) {
|
|
5974
|
+
let runnerOptions = {
|
|
5975
|
+
name: this.name,
|
|
5976
|
+
...options
|
|
5977
|
+
}, { compilerOptions } = options;
|
|
5978
|
+
if ('web' === compilerOptions.target || 'webworker' === compilerOptions.target) throw Error(`[rsbuild:runner] Not support run "${compilerOptions.target}" resource in Rsbuild server`);
|
|
5979
|
+
return new EsmRunner(runnerOptions);
|
|
5980
|
+
}
|
|
5981
|
+
constructor(name){
|
|
5982
|
+
var key, value;
|
|
5983
|
+
value = void 0, (key = "name") in this ? Object.defineProperty(this, key, {
|
|
5984
|
+
value: value,
|
|
5985
|
+
enumerable: !0,
|
|
5986
|
+
configurable: !0,
|
|
5987
|
+
writable: !0
|
|
5988
|
+
}) : this[key] = value, this.name = name;
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions).run(bundlePath), loadBundle = async (stats, entryName, utils)=>{
|
|
5992
|
+
let { chunks, entrypoints, outputPath } = stats.toJson({
|
|
5993
|
+
all: !1,
|
|
5994
|
+
chunks: !0,
|
|
5995
|
+
entrypoints: !0,
|
|
5996
|
+
outputPath: !0
|
|
5997
|
+
});
|
|
5998
|
+
if (!(null == entrypoints ? void 0 : entrypoints[entryName])) throw Error(`[rsbuild:loadBundle] Can't find entry: "${entryName}"`);
|
|
5999
|
+
let { chunks: entryChunks = [] } = entrypoints[entryName], files = entryChunks.reduce((prev, entryChunkName)=>{
|
|
6000
|
+
let chunk = null == chunks ? void 0 : chunks.find((chunk)=>{
|
|
6001
|
+
var _chunk_names;
|
|
6002
|
+
return chunk.entry && (null === (_chunk_names = chunk.names) || void 0 === _chunk_names ? void 0 : _chunk_names.includes(String(entryChunkName)));
|
|
6003
|
+
});
|
|
6004
|
+
return (null == chunk ? void 0 : chunk.files) ? prev.concat(chunk.files.filter((file)=>!file.endsWith('.css'))) : prev;
|
|
6005
|
+
}, []);
|
|
6006
|
+
if (0 === files.length) throw Error(`[rsbuild:loadBundle] Failed to get bundle by entryName: "${entryName}"`);
|
|
6007
|
+
if (files.length > 1) throw Error(`[rsbuild:loadBundle] Only support load single entry chunk, but got ${files.length}: ${files.join(',')}`);
|
|
6008
|
+
let allChunkFiles = (null == chunks ? void 0 : chunks.flatMap((c)=>c.files).map((file)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, file))) || [];
|
|
6009
|
+
return await runner_run({
|
|
6010
|
+
bundlePath: files[0],
|
|
6011
|
+
dist: outputPath,
|
|
6012
|
+
compilerOptions: stats.compilation.options,
|
|
6013
|
+
readFileSync: utils.readFileSync,
|
|
6014
|
+
isBundleOutput: (modulePath)=>allChunkFiles.includes(modulePath)
|
|
6015
|
+
});
|
|
6016
|
+
}, getTransformedHtml = async (entryName, utils)=>{
|
|
6017
|
+
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
6018
|
+
if (!htmlPath) throw Error(`[rsbuild:getTransformedHtml] Failed to get HTML file by entryName: "${entryName}"`);
|
|
6019
|
+
let fileName = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, htmlPath);
|
|
6020
|
+
return utils.readFileSync(fileName);
|
|
6021
|
+
}, createCacheableFunction = (getter)=>{
|
|
6022
|
+
let cache = new WeakMap();
|
|
6023
|
+
return async (stats, entryName, utils)=>{
|
|
6024
|
+
let cachedEntries = cache.get(stats);
|
|
6025
|
+
if (null == cachedEntries ? void 0 : cachedEntries[entryName]) return cachedEntries[entryName];
|
|
6026
|
+
let res = await getter(stats, entryName, utils);
|
|
6027
|
+
return cache.set(stats, {
|
|
6028
|
+
...cachedEntries || {},
|
|
6029
|
+
[entryName]: res
|
|
6030
|
+
}), res;
|
|
6031
|
+
};
|
|
6080
6032
|
}, cleanupCallbacks = new Set(), handleTermination = async (_, exitCode)=>{
|
|
6081
6033
|
try {
|
|
6082
6034
|
await Promise.all([
|
|
@@ -6116,14 +6068,14 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6116
6068
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create dev server');
|
|
6117
6069
|
let { port, host, https, portTip } = await getServerConfig({
|
|
6118
6070
|
config
|
|
6119
|
-
}), { middlewareMode } = config.server, devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(
|
|
6120
|
-
|
|
6071
|
+
}), { middlewareMode } = config.server, { context } = options, devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(context), root = context.rootPath;
|
|
6072
|
+
context.devServer = {
|
|
6121
6073
|
hostname: host,
|
|
6122
6074
|
port,
|
|
6123
6075
|
https
|
|
6124
6076
|
};
|
|
6125
|
-
let
|
|
6126
|
-
|
|
6077
|
+
let waitFirstCompileDone = runCompile ? new Promise((resolve)=>{
|
|
6078
|
+
context.hooks.onDevCompileDone.tap(({ stats, isFirstCompile })=>{
|
|
6127
6079
|
lastStats = 'stats' in stats ? stats.stats : [
|
|
6128
6080
|
stats
|
|
6129
6081
|
], isFirstCompile && resolve();
|
|
@@ -6133,7 +6085,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6133
6085
|
if (!compiler) throw Error('[rsbuild:server] Failed to get compiler instance.');
|
|
6134
6086
|
let publicPaths = helpers_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
6135
6087
|
getPublicPathFromCompiler(compiler)
|
|
6136
|
-
],
|
|
6088
|
+
], compilationManager = new CompilationManager({
|
|
6137
6089
|
dev: devConfig,
|
|
6138
6090
|
server: {
|
|
6139
6091
|
...config.server,
|
|
@@ -6141,14 +6093,9 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6141
6093
|
},
|
|
6142
6094
|
publicPaths: publicPaths,
|
|
6143
6095
|
compiler,
|
|
6144
|
-
environments:
|
|
6096
|
+
environments: context.environments
|
|
6145
6097
|
});
|
|
6146
|
-
return await
|
|
6147
|
-
middleware: compilerDevMiddleware.middleware,
|
|
6148
|
-
sockWrite: (...args)=>compilerDevMiddleware.sockWrite(...args),
|
|
6149
|
-
onUpgrade: (...args)=>compilerDevMiddleware.upgrade(...args),
|
|
6150
|
-
close: ()=>null == compilerDevMiddleware ? void 0 : compilerDevMiddleware.close()
|
|
6151
|
-
};
|
|
6098
|
+
return await compilationManager.init(), compilationManager;
|
|
6152
6099
|
}, protocol = https ? 'https' : 'http', urls = getAddressUrls({
|
|
6153
6100
|
protocol,
|
|
6154
6101
|
port,
|
|
@@ -6167,7 +6114,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6167
6114
|
config,
|
|
6168
6115
|
clearCache: !0
|
|
6169
6116
|
}), cleanupGracefulShutdown = middlewareMode ? null : setupGracefulShutdown(), closeServer = async ()=>{
|
|
6170
|
-
removeCleanup(closeServer), null == cleanupGracefulShutdown || cleanupGracefulShutdown(), await
|
|
6117
|
+
removeCleanup(closeServer), null == cleanupGracefulShutdown || cleanupGracefulShutdown(), await context.hooks.onCloseDevServer.callBatch(), await Promise.all([
|
|
6171
6118
|
null == devMiddlewares ? void 0 : devMiddlewares.close(),
|
|
6172
6119
|
null == fileWatcher ? void 0 : fileWatcher.close()
|
|
6173
6120
|
]);
|
|
@@ -6185,24 +6132,30 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6185
6132
|
help: shortcutsOptions.help,
|
|
6186
6133
|
customShortcuts: shortcutsOptions.custom
|
|
6187
6134
|
});
|
|
6188
|
-
|
|
6135
|
+
context.hooks.onCloseDevServer.tap(cleanup);
|
|
6189
6136
|
}
|
|
6190
6137
|
!getPortSilently && portTip && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(portTip);
|
|
6191
|
-
},
|
|
6138
|
+
}, cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>getTransformedHtml(entryName, utils)), environmentAPI = Object.fromEntries(Object.entries(context.environments).map(([name, environment])=>[
|
|
6192
6139
|
name,
|
|
6193
6140
|
{
|
|
6194
6141
|
getStats: async ()=>{
|
|
6195
|
-
if (!
|
|
6142
|
+
if (!compilationManager) throw Error('[rsbuild:server] Can not call `getStats` when `runCompile` is false');
|
|
6196
6143
|
return await waitFirstCompileDone, lastStats[environment.index];
|
|
6197
6144
|
},
|
|
6198
|
-
loadBundle: async (entryName)=>
|
|
6199
|
-
|
|
6145
|
+
loadBundle: async (entryName)=>{
|
|
6146
|
+
if (!compilationManager) throw Error('[rsbuild:server] Can not call `loadBundle` when `runCompile` is false');
|
|
6147
|
+
return await waitFirstCompileDone, cacheableLoadBundle(lastStats[environment.index], entryName, {
|
|
6148
|
+
readFileSync: compilationManager.readFileSync,
|
|
6200
6149
|
environment
|
|
6201
|
-
})
|
|
6202
|
-
|
|
6203
|
-
|
|
6150
|
+
});
|
|
6151
|
+
},
|
|
6152
|
+
getTransformedHtml: async (entryName)=>{
|
|
6153
|
+
if (!compilationManager) throw Error('[rsbuild:server] Can not call `getTransformedHtml` when `runCompile` is false');
|
|
6154
|
+
return await waitFirstCompileDone, cacheableTransformedHtml(lastStats[environment.index], entryName, {
|
|
6155
|
+
readFileSync: compilationManager.readFileSync,
|
|
6204
6156
|
environment
|
|
6205
|
-
})
|
|
6157
|
+
});
|
|
6158
|
+
}
|
|
6206
6159
|
}
|
|
6207
6160
|
])), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect(), httpServer = middlewareMode ? null : await createHttpServer({
|
|
6208
6161
|
serverConfig: config.server,
|
|
@@ -6215,7 +6168,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6215
6168
|
listen: async ()=>{
|
|
6216
6169
|
if (!httpServer) throw Error('[rsbuild:server] Can not listen dev server as `server.middlewareMode` is enabled.');
|
|
6217
6170
|
let serverTerminator = getServerTerminator(httpServer);
|
|
6218
|
-
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('listen dev server'),
|
|
6171
|
+
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('listen dev server'), context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
|
|
6219
6172
|
httpServer.listen({
|
|
6220
6173
|
host,
|
|
6221
6174
|
port
|
|
@@ -6232,10 +6185,10 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6232
6185
|
});
|
|
6233
6186
|
},
|
|
6234
6187
|
afterListen: async ()=>{
|
|
6235
|
-
await
|
|
6188
|
+
await context.hooks.onAfterStartDevServer.callBatch({
|
|
6236
6189
|
port,
|
|
6237
6190
|
routes,
|
|
6238
|
-
environments:
|
|
6191
|
+
environments: context.environments
|
|
6239
6192
|
});
|
|
6240
6193
|
},
|
|
6241
6194
|
connectWebSocket: ({ server })=>{
|
|
@@ -6244,27 +6197,24 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6244
6197
|
close: closeServer,
|
|
6245
6198
|
printUrls,
|
|
6246
6199
|
open: openPage
|
|
6247
|
-
}, postCallbacks = (await
|
|
6200
|
+
}, postCallbacks = (await context.hooks.onBeforeStartDevServer.callBatch({
|
|
6248
6201
|
server: devServerAPI,
|
|
6249
|
-
environments:
|
|
6202
|
+
environments: context.environments
|
|
6250
6203
|
})).filter((item)=>'function' == typeof item);
|
|
6251
|
-
runCompile ?
|
|
6252
|
-
let
|
|
6204
|
+
runCompile ? context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
|
|
6205
|
+
let compilationManager = runCompile ? await startCompile() : void 0;
|
|
6253
6206
|
for (let item of (fileWatcher = await setupWatchFiles({
|
|
6254
6207
|
dev: devConfig,
|
|
6255
6208
|
server: config.server,
|
|
6256
|
-
|
|
6209
|
+
compilationManager,
|
|
6257
6210
|
root
|
|
6258
|
-
}), (devMiddlewares = await
|
|
6211
|
+
}), (devMiddlewares = await getDevMiddlewares({
|
|
6259
6212
|
pwd: root,
|
|
6260
|
-
|
|
6213
|
+
compilationManager,
|
|
6261
6214
|
dev: devConfig,
|
|
6215
|
+
context,
|
|
6262
6216
|
server: config.server,
|
|
6263
6217
|
environments: environmentAPI,
|
|
6264
|
-
output: {
|
|
6265
|
-
distPath: options.context.distPath || ROOT_DIST_DIR
|
|
6266
|
-
},
|
|
6267
|
-
outputFileSystem,
|
|
6268
6218
|
postCallbacks
|
|
6269
6219
|
})).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
|
|
6270
6220
|
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create dev server done'), devServerAPI;
|
|
@@ -6350,8 +6300,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
6350
6300
|
};
|
|
6351
6301
|
}
|
|
6352
6302
|
let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
|
|
6353
|
-
let compiler, bundlerConfigs;
|
|
6354
|
-
let { context } = initOptions;
|
|
6303
|
+
let compiler, bundlerConfigs, { context } = initOptions;
|
|
6355
6304
|
if (customCompiler) compiler = customCompiler;
|
|
6356
6305
|
else {
|
|
6357
6306
|
let result = await createCompiler_createCompiler(initOptions);
|
|
@@ -6453,14 +6402,14 @@ class RsbuildProdServer {
|
|
|
6453
6402
|
let { headers, proxy, historyApiFallback, compress, base, cors } = this.options.serverConfig;
|
|
6454
6403
|
if ('verbose' === __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level && this.middlewares.use(await getRequestLoggerMiddleware()), compress && this.middlewares.use(gzipMiddleware({
|
|
6455
6404
|
level: 6
|
|
6456
|
-
})),
|
|
6457
|
-
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
6458
|
-
next();
|
|
6459
|
-
}), cors) {
|
|
6405
|
+
})), cors) {
|
|
6460
6406
|
let { default: corsMiddleware } = await import("../compiled/cors/index.js");
|
|
6461
6407
|
this.middlewares.use(corsMiddleware('boolean' == typeof cors ? {} : cors));
|
|
6462
6408
|
}
|
|
6463
|
-
if (
|
|
6409
|
+
if (headers && this.middlewares.use((_req, res, next)=>{
|
|
6410
|
+
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
6411
|
+
next();
|
|
6412
|
+
}), proxy) {
|
|
6464
6413
|
let { middlewares, upgrade } = await createProxyMiddleware(proxy);
|
|
6465
6414
|
for (let middleware of middlewares)this.middlewares.use(middleware);
|
|
6466
6415
|
this.app.on('upgrade', upgrade);
|
|
@@ -6636,13 +6585,13 @@ async function applyDefaultPlugins(pluginManager, context) {
|
|
|
6636
6585
|
setup (api) {
|
|
6637
6586
|
'webpack' !== api.context.bundlerType && (api.modifyRsbuildConfig((config)=>{
|
|
6638
6587
|
let { moduleFederation } = config;
|
|
6639
|
-
if ((null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
|
|
6588
|
+
if (api.isPluginExists('rsbuild:module-federation-enhanced') && (config.server ||= {}, config.server.cors = !0), (null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
|
|
6640
6589
|
var _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
6641
|
-
config.dev ||= {}, (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.port) && !(null === (_config_dev_client = config.dev.client) || void 0 === _config_dev_client ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null === (_originalConfig_dev = api.getRsbuildConfig('original').dev) || void 0 === _originalConfig_dev ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null === (_config_server1 = config.server) || void 0 === _config_server1 ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
|
|
6590
|
+
config.dev ||= {}, config.server ||= {}, config.server.cors = !0, (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.port) && !(null === (_config_dev_client = config.dev.client) || void 0 === _config_dev_client ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null === (_originalConfig_dev = api.getRsbuildConfig('original').dev) || void 0 === _originalConfig_dev ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null === (_config_server1 = config.server) || void 0 === _config_server1 ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
|
|
6642
6591
|
}
|
|
6643
6592
|
}), api.modifyEnvironmentConfig((config)=>{
|
|
6644
6593
|
var _config_moduleFederation, _config_performance_chunkSplit, _config_performance;
|
|
6645
|
-
(null === (_config_moduleFederation = config.moduleFederation) || void 0 === _config_moduleFederation ? void 0 : _config_moduleFederation.options) && ((null === (_config_performance = config.performance) || void 0 === _config_performance
|
|
6594
|
+
(null === (_config_moduleFederation = config.moduleFederation) || void 0 === _config_moduleFederation ? void 0 : _config_moduleFederation.options) && ((null === (_config_performance = config.performance) || void 0 === _config_performance || null === (_config_performance_chunkSplit = _config_performance.chunkSplit) || void 0 === _config_performance_chunkSplit ? void 0 : _config_performance_chunkSplit.strategy) === 'split-by-experience' && (config.performance.chunkSplit = {
|
|
6646
6595
|
...config.performance.chunkSplit,
|
|
6647
6596
|
strategy: 'custom'
|
|
6648
6597
|
}), config.source.include = [
|
|
@@ -6663,37 +6612,31 @@ async function applyDefaultPlugins(pluginManager, context) {
|
|
|
6663
6612
|
}
|
|
6664
6613
|
},
|
|
6665
6614
|
pluginRspackProfile(),
|
|
6666
|
-
pluginLazyCompilation(),
|
|
6667
6615
|
pluginSri(),
|
|
6668
6616
|
pluginNonce()
|
|
6669
6617
|
]);
|
|
6670
6618
|
}
|
|
6671
6619
|
async function createRsbuild(options = {}) {
|
|
6672
|
-
let plugins
|
|
6673
|
-
let envs = options.loadEnv ? loadEnv({
|
|
6620
|
+
let plugins, envs = options.loadEnv ? loadEnv({
|
|
6674
6621
|
cwd: options.cwd,
|
|
6675
6622
|
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
6676
6623
|
}) : null, config = isFunction(options.rsbuildConfig) ? await options.rsbuildConfig() : options.rsbuildConfig || {};
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
paths: envs.filePaths,
|
|
6687
|
-
type: 'reload-server'
|
|
6688
|
-
}
|
|
6689
|
-
], null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache)) {
|
|
6690
|
-
let { buildCache } = config.performance;
|
|
6691
|
-
!0 === buildCache ? config.performance.buildCache = {
|
|
6692
|
-
buildDependencies: envs.filePaths
|
|
6693
|
-
} : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
|
|
6694
|
-
}
|
|
6624
|
+
var _config_performance, config1 = config, envs1 = envs;
|
|
6625
|
+
if (null !== envs1 && (config1.source ||= {}, config1.source.define = {
|
|
6626
|
+
...envs1.publicVars,
|
|
6627
|
+
...config1.source.define
|
|
6628
|
+
}, 0 !== envs1.filePaths.length && (config1.dev ||= {}, config1.dev.watchFiles = [
|
|
6629
|
+
...config1.dev.watchFiles ? castArray(config1.dev.watchFiles) : [],
|
|
6630
|
+
{
|
|
6631
|
+
paths: envs1.filePaths,
|
|
6632
|
+
type: 'reload-server'
|
|
6695
6633
|
}
|
|
6696
|
-
|
|
6634
|
+
], null === (_config_performance = config1.performance) || void 0 === _config_performance ? void 0 : _config_performance.buildCache))) {
|
|
6635
|
+
let { buildCache } = config1.performance;
|
|
6636
|
+
!0 === buildCache ? config1.performance.buildCache = {
|
|
6637
|
+
buildDependencies: envs1.filePaths
|
|
6638
|
+
} : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs1.filePaths));
|
|
6639
|
+
}
|
|
6697
6640
|
let resolvedOptions = {
|
|
6698
6641
|
cwd: process.cwd(),
|
|
6699
6642
|
...options,
|
|
@@ -6706,15 +6649,14 @@ async function createRsbuild(options = {}) {
|
|
|
6706
6649
|
addPlugins: (newPlugins, options)=>{
|
|
6707
6650
|
let { before, environment = RSBUILD_ALL_ENVIRONMENT_SYMBOL } = options || {};
|
|
6708
6651
|
for (let newPlugin of newPlugins)if (newPlugin) {
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
if (
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green(`
|
|
6652
|
+
let type = typeof newPlugin;
|
|
6653
|
+
if ('object' !== type || null === newPlugin) throw Error(`[rsbuild:plugin] Expect Rsbuild plugin instance to be an object, but got ${type}.`);
|
|
6654
|
+
if (!isFunction(newPlugin.setup)) {
|
|
6655
|
+
if (isFunction(newPlugin.apply)) {
|
|
6656
|
+
let { name = 'SomeWebpackPlugin' } = newPlugin.constructor || {};
|
|
6657
|
+
throw Error([
|
|
6658
|
+
`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(name)} looks like a webpack or Rspack plugin, please use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('`tools.rspack`')} to register it:`,
|
|
6659
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green(`
|
|
6718
6660
|
// rsbuild.config.ts
|
|
6719
6661
|
export default {
|
|
6720
6662
|
tools: {
|
|
@@ -6724,11 +6666,11 @@ async function createRsbuild(options = {}) {
|
|
|
6724
6666
|
}
|
|
6725
6667
|
};
|
|
6726
6668
|
`)
|
|
6727
|
-
|
|
6728
|
-
}
|
|
6729
|
-
throw Error(`[rsbuild:plugin] Expect the setup function of Rsbuild plugin to be a function, but got ${type}.`);
|
|
6669
|
+
].join('\n'));
|
|
6730
6670
|
}
|
|
6731
|
-
|
|
6671
|
+
throw Error(`[rsbuild:plugin] Expect the setup function of Rsbuild plugin to be a function, but got ${type}.`);
|
|
6672
|
+
}
|
|
6673
|
+
if (before) {
|
|
6732
6674
|
let index = plugins.findIndex((item)=>item.instance.name === before);
|
|
6733
6675
|
-1 === index ? (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Plugin "${before}" does not exist.`), plugins.push({
|
|
6734
6676
|
environment,
|
|
@@ -7018,8 +6960,7 @@ function toArr(any) {
|
|
|
7018
6960
|
];
|
|
7019
6961
|
}
|
|
7020
6962
|
let removeBrackets = (v)=>v.replace(/[<[].+/, "").trim(), findAllBrackets = (v)=>{
|
|
7021
|
-
let angledMatch, squareMatch
|
|
7022
|
-
let ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g, SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g, res = [], parse = (match)=>{
|
|
6963
|
+
let angledMatch, squareMatch, ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g, SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g, res = [], parse = (match)=>{
|
|
7023
6964
|
let variadic = !1, value = match[1];
|
|
7024
6965
|
return value.startsWith("...") && (value = value.slice(3), variadic = !0), {
|
|
7025
6966
|
required: match[0].startsWith("<"),
|
|
@@ -7328,21 +7269,20 @@ let cac_dist = (name = "")=>new CAC(name), applyCommonOptions = (cli)=>{
|
|
|
7328
7269
|
command.option('-o, --open [url]', 'open the page in browser on startup').option('--port <port>', 'specify a port number for server to listen').option('--host <host>', 'specify the host that the server listens to');
|
|
7329
7270
|
};
|
|
7330
7271
|
async function runCLI() {
|
|
7331
|
-
!
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
}(), process.title = 'rsbuild-node';
|
|
7272
|
+
if (!process.env.NODE_ENV) {
|
|
7273
|
+
let command = process.argv[2];
|
|
7274
|
+
process.env.NODE_ENV = [
|
|
7275
|
+
'build',
|
|
7276
|
+
'preview'
|
|
7277
|
+
].includes(command) ? 'production' : 'development';
|
|
7278
|
+
}
|
|
7279
|
+
process.title = 'rsbuild-node';
|
|
7340
7280
|
let { npm_execpath } = process.env;
|
|
7341
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.3.0
|
|
7281
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.3.0\n`);
|
|
7342
7282
|
try {
|
|
7343
7283
|
!function() {
|
|
7344
7284
|
let cli = cac_dist('rsbuild');
|
|
7345
|
-
cli.help(), cli.version("1.3.0
|
|
7285
|
+
cli.help(), cli.version("1.3.0"), applyCommonOptions(cli);
|
|
7346
7286
|
let devCommand = cli.command('', 'starting the dev server').alias('dev'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
|
|
7347
7287
|
applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
|
|
7348
7288
|
try {
|
|
@@ -7393,6 +7333,6 @@ async function runCLI() {
|
|
|
7393
7333
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to start Rsbuild CLI.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
|
|
7394
7334
|
}
|
|
7395
7335
|
}
|
|
7396
|
-
let src_version = "1.3.0
|
|
7336
|
+
let src_version = "1.3.0";
|
|
7397
7337
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
|
|
7398
7338
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
|