@rsbuild/core 2.3.0 → 2.3.2
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/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/jiti/dist/babel.cjs +1 -1
- package/compiled/postcss/index.js +1 -1
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-loader/index.js +6 -6
- package/dist/chokidar.js +1 -1
- package/dist/client/overlay.js +2 -2
- package/dist/http-proxy-middleware.js +1 -1
- package/dist/m.js +909 -894
- package/dist/manifest-plugin.js +1 -1
- package/dist/memfs.js +1 -1
- package/dist/open.js +2 -2
- package/dist/server/assets-middleware/getFileFromUrl.d.ts +3 -1
- package/dist/server/assets-middleware/middleware.d.ts +0 -5
- package/dist/server/helper.d.ts +2 -1
- package/dist/transformLoader.mjs +10 -10
- package/dist/types/config.d.ts +8 -3
- package/dist/workerLoader.mjs +3 -3
- package/dist/ws.js +2 -2
- package/package.json +6 -6
package/dist/m.js
CHANGED
|
@@ -207,7 +207,7 @@ moduleFactories.add({
|
|
|
207
207
|
if ('function' != typeof loader) throw Error('loader is not a function');
|
|
208
208
|
}
|
|
209
209
|
module.exports.lilconfig = function lilconfig(name, options) {
|
|
210
|
-
let { ignoreEmptySearchPlaces, loaders, packageProp, searchPlaces, stopDir, transform, cache } = getOptions(name, options ?? {}, !1), searchCache = new Map(), loadCache = new Map(), emplace = (c, filepath, res)=>(cache && c.set(filepath, res), res);
|
|
210
|
+
let { ignoreEmptySearchPlaces, loaders, packageProp, searchPlaces, stopDir, transform, cache } = getOptions(name, options ?? {}, !1), searchCache = new Map(), loadCache = new Map(), emplace = (0, (c, filepath, res)=>(cache && c.set(filepath, res), res));
|
|
211
211
|
return {
|
|
212
212
|
async search (searchFrom = process.cwd()) {
|
|
213
213
|
let result = {
|
|
@@ -292,8 +292,8 @@ moduleFactories.add({
|
|
|
292
292
|
};
|
|
293
293
|
};
|
|
294
294
|
},
|
|
295
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
296
|
-
let yaml, { resolve } = __rspack_createRequire_require("node:path"), config = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/lilconfig/3.1.3/8e9a79516bf61f8427342cef50cdad2cdc2572f42288ba8053b88eadfdc0ebef/node_modules/lilconfig/src/index.js"), loadOptions = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
295
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/index.js" (module) {
|
|
296
|
+
let yaml, { resolve } = __rspack_createRequire_require("node:path"), config = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/lilconfig/3.1.3/8e9a79516bf61f8427342cef50cdad2cdc2572f42288ba8053b88eadfdc0ebef/node_modules/lilconfig/src/index.js"), loadOptions = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/options.js"), loadPlugins = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/plugins.js"), req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/req.js");
|
|
297
297
|
async function processResult(ctx, result) {
|
|
298
298
|
let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
|
|
299
299
|
default: obj
|
|
@@ -366,8 +366,8 @@ moduleFactories.add({
|
|
|
366
366
|
});
|
|
367
367
|
};
|
|
368
368
|
},
|
|
369
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
370
|
-
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
369
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/options.js" (module) {
|
|
370
|
+
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/req.js");
|
|
371
371
|
module.exports = async function options(config, file) {
|
|
372
372
|
if (config.parser && 'string' == typeof config.parser) try {
|
|
373
373
|
config.parser = await req(config.parser, file);
|
|
@@ -387,8 +387,8 @@ moduleFactories.add({
|
|
|
387
387
|
return config;
|
|
388
388
|
};
|
|
389
389
|
},
|
|
390
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
391
|
-
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
390
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/plugins.js" (module) {
|
|
391
|
+
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/req.js");
|
|
392
392
|
async function load(plugin, options, file) {
|
|
393
393
|
try {
|
|
394
394
|
if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
|
|
@@ -404,7 +404,7 @@ moduleFactories.add({
|
|
|
404
404
|
}), list;
|
|
405
405
|
};
|
|
406
406
|
},
|
|
407
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
407
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/req.js" (module) {
|
|
408
408
|
let tsx, jiti, { createRequire } = __rspack_createRequire_require("node:module"), { pathToFileURL } = __rspack_createRequire_require("node:url"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
409
409
|
module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
|
|
410
410
|
let url = createRequire(rootFile).resolve(name);
|
|
@@ -941,16 +941,16 @@ var Command = class {
|
|
|
941
941
|
arg.variadic ? actionArgs.push(args.slice(index)) : actionArgs.push(args[index]);
|
|
942
942
|
}), actionArgs.push(options), command.commandAction.apply(this, actionArgs);
|
|
943
943
|
}
|
|
944
|
-
},
|
|
944
|
+
}, dist_webpack_modules_ = {}, dist_webpack_module_cache_ = {};
|
|
945
945
|
function dist_webpack_require_(moduleId) {
|
|
946
|
-
var cachedModule =
|
|
946
|
+
var cachedModule = dist_webpack_module_cache_[moduleId];
|
|
947
947
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
948
|
-
var module =
|
|
948
|
+
var module = dist_webpack_module_cache_[moduleId] = {
|
|
949
949
|
exports: {}
|
|
950
950
|
};
|
|
951
|
-
return
|
|
951
|
+
return dist_webpack_modules_[moduleId](module, module.exports, dist_webpack_require_), module.exports;
|
|
952
952
|
}
|
|
953
|
-
dist_webpack_require_.m =
|
|
953
|
+
dist_webpack_require_.m = dist_webpack_modules_, dist_webpack_require_.add = function(modules) {
|
|
954
954
|
Object.assign(dist_webpack_require_.m, modules);
|
|
955
955
|
}, dist_webpack_require_.add({
|
|
956
956
|
"./node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js" (module) {
|
|
@@ -1170,7 +1170,7 @@ dist_webpack_require_.m = __webpack_modules__, dist_webpack_require_.add = funct
|
|
|
1170
1170
|
exports.A = void 0;
|
|
1171
1171
|
let stringify_1 = __webpack_require__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/stringify.js"), quote_1 = __webpack_require__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/quote.js"), ROOT_SENTINEL = Symbol("root");
|
|
1172
1172
|
function replacerToString(replacer) {
|
|
1173
|
-
return replacer ? (value, space, next, key)=>replacer(value, space, (value)=>stringify_1.toString(value, space, next, key), key) : stringify_1.toString;
|
|
1173
|
+
return replacer ? (0, (value, space, next, key)=>replacer(value, space, (value)=>stringify_1.toString(value, space, next, key), key)) : stringify_1.toString;
|
|
1174
1174
|
}
|
|
1175
1175
|
exports.A = function stringify(value, replacer, indent, options = {}) {
|
|
1176
1176
|
let space = "string" == typeof indent ? indent : " ".repeat(indent || 0), path = [], stack = new Set(), tracking = new Map(), unpack = new Map(), valueCount = 0, { maxDepth = 100, references = !1, skipUndefinedProperties = !1, maxValues = 100000 } = options, valueToString = replacerToString(replacer), onNext = (value, key)=>{
|
|
@@ -1997,7 +1997,11 @@ let vendors_require = createRequire(import.meta.url);
|
|
|
1997
1997
|
var cjs_0_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/deepmerge/4.3.1/56471899410038644780b3527c5076e78d3f57091a0da3ac0daf6d994929353d/node_modules/deepmerge/dist/cjs.js"));
|
|
1998
1998
|
let setNodeEnv = (env)=>{
|
|
1999
1999
|
process.env.NODE_ENV = env;
|
|
2000
|
-
}, isCI = ()=>!!process.env.CI && 'false' !== process.env.CI, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, helpers_getProto = Object.getPrototypeOf, isPlainObject = (obj)=>
|
|
2000
|
+
}, isCI = ()=>!!process.env.CI && 'false' !== process.env.CI, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, helpers_getProto = Object.getPrototypeOf, isPlainObject = (obj)=>{
|
|
2001
|
+
if (null === obj || 'object' != typeof obj) return !1;
|
|
2002
|
+
let proto = helpers_getProto(obj);
|
|
2003
|
+
return null === proto || proto === objectPrototype || null === helpers_getProto(proto);
|
|
2004
|
+
}, helpers_castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
|
|
2001
2005
|
arr
|
|
2002
2006
|
], cloneDeep = (value)=>null == value ? value : cjs_0_default()({}, value, {
|
|
2003
2007
|
isMergeableObject: isPlainObject
|
|
@@ -2379,19 +2383,20 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompile, isWa
|
|
|
2379
2383
|
if (compiler_isMultiCompiler(compiler)) {
|
|
2380
2384
|
let { compilers } = compiler, compilerStats = [], doneCompilers = 0;
|
|
2381
2385
|
for(let index = 0; index < compilers.length; index++){
|
|
2382
|
-
let compiler = compilers[index],
|
|
2386
|
+
let compiler = compilers[index], compilerDone = !1, generation = 0, compilationGeneration = 0;
|
|
2383
2387
|
compiler.hooks.done.tapPromise('rsbuild:done', async (stats)=>{
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
await onEnvironmentDone(index, stats), lastCompilerDone && await onDone(new MultiStatsCtor(compilerStats));
|
|
2388
|
+
let currentGeneration = compilationGeneration;
|
|
2389
|
+
await onEnvironmentDone(index, stats), currentGeneration === generation && (!compilerDone && (compilerDone = !0, doneCompilers++), compilerStats[index] = stats, doneCompilers === compilers.length && await onDone(new MultiStatsCtor(compilerStats)));
|
|
2387
2390
|
});
|
|
2388
2391
|
let resetDoneState = ()=>{
|
|
2389
|
-
compilerDone && (compilerDone = !1, doneCompilers--);
|
|
2392
|
+
generation++, compilerDone && (compilerDone = !1, doneCompilers--);
|
|
2390
2393
|
};
|
|
2391
2394
|
compiler.hooks.invalid.tap('rsbuild:done', resetDoneState), compiler.hooks.watchRun.tap({
|
|
2392
2395
|
name: 'rsbuild:done',
|
|
2393
2396
|
stage: -1 / 0
|
|
2394
|
-
},
|
|
2397
|
+
}, ()=>{
|
|
2398
|
+
resetDoneState(), compilationGeneration = generation;
|
|
2399
|
+
});
|
|
2395
2400
|
}
|
|
2396
2401
|
} else compiler.hooks.done.tapPromise('rsbuild:done', async (stats)=>{
|
|
2397
2402
|
await onEnvironmentDone(0, stats), await onDone(stats);
|
|
@@ -2582,13 +2587,8 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2582
2587
|
'provider',
|
|
2583
2588
|
'customLogger'
|
|
2584
2589
|
]), merge = (x, y, path = '')=>{
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
let realKey = key.split('.').slice(2).join('.');
|
|
2588
|
-
return OVERRIDE_PATHS.has(realKey);
|
|
2589
|
-
}
|
|
2590
|
-
return OVERRIDE_PATHS.has(key) || key.startsWith('output.filename.');
|
|
2591
|
-
})(path)) return y ?? x;
|
|
2590
|
+
let realKey;
|
|
2591
|
+
if (realKey = path.startsWith('environments.') ? path.split('.').slice(2).join('.') : path, OVERRIDE_PATHS.has(realKey) || realKey.startsWith('output.filename.')) return y ?? x;
|
|
2592
2592
|
if (void 0 === x) return isPlainObject(y) ? cloneDeep(y) : y;
|
|
2593
2593
|
if (void 0 === y) return isPlainObject(x) ? cloneDeep(x) : x;
|
|
2594
2594
|
let typeX = typeof x, typeY = typeof y;
|
|
@@ -2608,14 +2608,22 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2608
2608
|
y
|
|
2609
2609
|
];
|
|
2610
2610
|
if (!isPlainObject(x) || !isPlainObject(y)) return y;
|
|
2611
|
-
let merged = {};
|
|
2612
|
-
for (let key of
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2611
|
+
let merged = {}, xKeys = Object.keys(x), yKeys = Object.keys(y), xKeySet = xKeys.length > 8 && yKeys.length > 8 ? new Set(xKeys) : void 0;
|
|
2612
|
+
for (let key of xKeys){
|
|
2613
|
+
let childPath = path ? `${path}.${key}` : key;
|
|
2614
|
+
merged[key] = merge(x[key], y[key], childPath);
|
|
2615
|
+
}
|
|
2616
|
+
for (let key of yKeys)if (!(xKeySet ? xKeySet.has(key) : xKeys.includes(key))) {
|
|
2616
2617
|
let childPath = path ? `${path}.${key}` : key;
|
|
2617
2618
|
merged[key] = merge(x[key], y[key], childPath);
|
|
2618
2619
|
}
|
|
2620
|
+
for (let source of [
|
|
2621
|
+
x,
|
|
2622
|
+
y
|
|
2623
|
+
])for (let key of Object.getOwnPropertySymbols(source))if (Object.prototype.propertyIsEnumerable.call(source, key)) {
|
|
2624
|
+
let value = source[key];
|
|
2625
|
+
void 0 !== value && (merged[key] = value);
|
|
2626
|
+
}
|
|
2619
2627
|
return merged;
|
|
2620
2628
|
}, normalizeConfigStructure = (config)=>{
|
|
2621
2629
|
let { dev, output } = config, normalizedConfig = {
|
|
@@ -2788,17 +2796,7 @@ function getDefaultEntry(root) {
|
|
|
2788
2796
|
index: entryFile
|
|
2789
2797
|
} : {};
|
|
2790
2798
|
}
|
|
2791
|
-
let
|
|
2792
|
-
let config = mergeRsbuildConfig(createDefaultConfig(), userConfig);
|
|
2793
|
-
if (config.root ||= rootPath, config.source ||= {}, config.server?.base && (userConfig.dev?.assetPrefix === void 0 && (config.dev ||= {}, config.dev.assetPrefix = config.server.base), userConfig.output?.assetPrefix === void 0 && (config.output ||= {}, config.output.assetPrefix = config.server.base)), userConfig.dev?.client?.logLevel === void 0 && (config.dev ||= {}, config.dev.client ||= {}, config.dev.client.logLevel = config.logLevel), config.dev?.lazyCompilation === void 0 && (config.dev ||= {}, config.dev.lazyCompilation = {
|
|
2794
|
-
imports: !0,
|
|
2795
|
-
entries: !1
|
|
2796
|
-
}), !config.source.tsconfigPath) {
|
|
2797
|
-
let tsconfigPath = join(rootPath, TS_CONFIG_FILE);
|
|
2798
|
-
await isFileExists(tsconfigPath) && (config.source.tsconfigPath = tsconfigPath);
|
|
2799
|
-
}
|
|
2800
|
-
return config;
|
|
2801
|
-
}, normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2799
|
+
let normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2802
2800
|
if (!1 === publicDir) return [];
|
|
2803
2801
|
let defaultConfig = {
|
|
2804
2802
|
name: join(rootPath, 'public'),
|
|
@@ -3079,7 +3077,7 @@ function initPluginAPI({ context, pluginManager }) {
|
|
|
3079
3077
|
context: publicContext,
|
|
3080
3078
|
expose,
|
|
3081
3079
|
logger: context.logger,
|
|
3082
|
-
transform: (descriptor, handler)=>{
|
|
3080
|
+
transform: (0, (descriptor, handler)=>{
|
|
3083
3081
|
let id = `rsbuild-transform-${transformId++}`;
|
|
3084
3082
|
transformer[id] = handler, hooks.modifyBundlerChain.tapEnvironment({
|
|
3085
3083
|
environment: environment,
|
|
@@ -3094,24 +3092,24 @@ function initPluginAPI({ context, pluginManager }) {
|
|
|
3094
3092
|
void 0 !== descriptor.codeFilter && use.set('codeFilter', descriptor.codeFilter);
|
|
3095
3093
|
}
|
|
3096
3094
|
});
|
|
3097
|
-
},
|
|
3098
|
-
useExposed: (id)=>{
|
|
3095
|
+
}),
|
|
3096
|
+
useExposed: (0, (id)=>{
|
|
3099
3097
|
let exposedAPIs = exposed.get(id);
|
|
3100
3098
|
if (exposedAPIs) return void 0 !== environment && exposedAPIs.has(environment) ? exposedAPIs.get(environment) : exposedAPIs.get(GLOBAL_EXPOSED_KEY);
|
|
3101
|
-
},
|
|
3102
|
-
processAssets: (descriptor, handler)=>{
|
|
3099
|
+
}),
|
|
3100
|
+
processAssets: (0, (descriptor, handler)=>{
|
|
3103
3101
|
processAssetsFns.push({
|
|
3104
3102
|
environment: environment,
|
|
3105
3103
|
descriptor,
|
|
3106
3104
|
handler
|
|
3107
3105
|
});
|
|
3108
|
-
},
|
|
3109
|
-
resolve: (handler)=>{
|
|
3106
|
+
}),
|
|
3107
|
+
resolve: (0, (handler)=>{
|
|
3110
3108
|
resolveFns.push({
|
|
3111
3109
|
environment: environment,
|
|
3112
3110
|
handler
|
|
3113
3111
|
});
|
|
3114
|
-
},
|
|
3112
|
+
}),
|
|
3115
3113
|
getRsbuildConfig,
|
|
3116
3114
|
getNormalizedConfig,
|
|
3117
3115
|
isPluginExists: pluginManager.isPluginExists,
|
|
@@ -3248,9 +3246,19 @@ function createPublicContext(context) {
|
|
|
3248
3246
|
});
|
|
3249
3247
|
}
|
|
3250
3248
|
async function createContext(options, userConfig, logger, loadConfigResult) {
|
|
3251
|
-
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await
|
|
3249
|
+
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await (async (rootPath, userConfig)=>{
|
|
3250
|
+
let config = mergeRsbuildConfig(createDefaultConfig(), userConfig);
|
|
3251
|
+
if (config.root ||= rootPath, config.source ||= {}, config.server?.base && (userConfig.dev?.assetPrefix === void 0 && (config.dev ||= {}, config.dev.assetPrefix = config.server.base), userConfig.output?.assetPrefix === void 0 && (config.output ||= {}, config.output.assetPrefix = config.server.base)), userConfig.dev?.client?.logLevel === void 0 && (config.dev ||= {}, config.dev.client ||= {}, config.dev.client.logLevel = config.logLevel), config.dev?.lazyCompilation === void 0 && (config.dev ||= {}, config.dev.lazyCompilation = {
|
|
3252
|
+
imports: !0,
|
|
3253
|
+
entries: !1
|
|
3254
|
+
}), !config.source.tsconfigPath) {
|
|
3255
|
+
let tsconfigPath = join(rootPath, TS_CONFIG_FILE);
|
|
3256
|
+
await isFileExists(tsconfigPath) && (config.source.tsconfigPath = tsconfigPath);
|
|
3257
|
+
}
|
|
3258
|
+
return config;
|
|
3259
|
+
})(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, hooks = initHooks();
|
|
3252
3260
|
return {
|
|
3253
|
-
version: "2.3.
|
|
3261
|
+
version: "2.3.2",
|
|
3254
3262
|
rootPath,
|
|
3255
3263
|
configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
|
|
3256
3264
|
configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
|
|
@@ -3792,6 +3800,9 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
3792
3800
|
},
|
|
3793
3801
|
server: {
|
|
3794
3802
|
...normalizedBaseConfig.server,
|
|
3803
|
+
...pick(environmentConfig.server ?? {}, [
|
|
3804
|
+
'serveAssets'
|
|
3805
|
+
]),
|
|
3795
3806
|
publicDir: void 0 === publicDir ? normalizedBaseConfig.server.publicDir : normalizePublicDirs(context.rootPath, publicDir)
|
|
3796
3807
|
}
|
|
3797
3808
|
}, { tsconfigPath } = normalizedEnvironmentConfig.source;
|
|
@@ -3972,28 +3983,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
3972
3983
|
let { message, level } = formatStats(stats, hasErrors, options.context.rootPath, logger);
|
|
3973
3984
|
'error' === level && logger.error(message), 'warning' === level && logger.warn(message), isMultiCompiler || printTime(0, hasErrors), isCompiling = !1;
|
|
3974
3985
|
}), 'dev' === context.action && (({ context, compiler, bundlerConfigs, MultiStatsCtor })=>{
|
|
3975
|
-
let isFirstCompile = !0, { environmentList } = context
|
|
3976
|
-
let promise = context.hooks.onAfterDevCompile.callBatch({
|
|
3977
|
-
isFirstCompile,
|
|
3978
|
-
stats,
|
|
3979
|
-
environments: context.environments
|
|
3980
|
-
});
|
|
3981
|
-
isFirstCompile = !1, await promise;
|
|
3982
|
-
}, onEnvironmentDone = async (index, stats)=>{
|
|
3983
|
-
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
3984
|
-
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
3985
|
-
environment: environment.name,
|
|
3986
|
-
args: [
|
|
3987
|
-
{
|
|
3988
|
-
isFirstCompile,
|
|
3989
|
-
stats,
|
|
3990
|
-
environment,
|
|
3991
|
-
isWatch: !0,
|
|
3992
|
-
time
|
|
3993
|
-
}
|
|
3994
|
-
]
|
|
3995
|
-
});
|
|
3996
|
-
};
|
|
3986
|
+
let isFirstCompile = !0, { environmentList } = context;
|
|
3997
3987
|
onBeforeCompile({
|
|
3998
3988
|
compiler,
|
|
3999
3989
|
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
@@ -4019,8 +4009,29 @@ async function createCompiler_createCompiler(options) {
|
|
|
4019
4009
|
isWatch: !0
|
|
4020
4010
|
}), onCompileDone({
|
|
4021
4011
|
compiler,
|
|
4022
|
-
onDone
|
|
4023
|
-
|
|
4012
|
+
onDone: async (stats)=>{
|
|
4013
|
+
let promise = context.hooks.onAfterDevCompile.callBatch({
|
|
4014
|
+
isFirstCompile,
|
|
4015
|
+
stats,
|
|
4016
|
+
environments: context.environments
|
|
4017
|
+
});
|
|
4018
|
+
isFirstCompile = !1, await promise;
|
|
4019
|
+
},
|
|
4020
|
+
onEnvironmentDone: async (index, stats)=>{
|
|
4021
|
+
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
4022
|
+
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
4023
|
+
environment: environment.name,
|
|
4024
|
+
args: [
|
|
4025
|
+
{
|
|
4026
|
+
isFirstCompile,
|
|
4027
|
+
stats,
|
|
4028
|
+
environment,
|
|
4029
|
+
isWatch: !0,
|
|
4030
|
+
time
|
|
4031
|
+
}
|
|
4032
|
+
]
|
|
4033
|
+
});
|
|
4034
|
+
},
|
|
4024
4035
|
MultiStatsCtor
|
|
4025
4036
|
});
|
|
4026
4037
|
})({
|
|
@@ -4049,8 +4060,8 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (inp
|
|
|
4049
4060
|
if ('' === basePath || !url.startsWith(basePath)) return url;
|
|
4050
4061
|
let nextChar = url[basePath.length];
|
|
4051
4062
|
return void 0 === nextChar ? '/' : '/' === nextChar ? url.slice(basePath.length) : '?' === nextChar || '#' === nextChar ? `/${url.slice(basePath.length)}` : url;
|
|
4052
|
-
}, getRoutes = (context)=>{
|
|
4053
|
-
let environmentWithHtml = context.environmentList.filter((item)=>Object.keys(item.htmlPaths).length > 0);
|
|
4063
|
+
}, isServingAssets = (config)=>config.server.serveAssets ?? isWebTarget(config.output.target), getRoutes = (context)=>{
|
|
4064
|
+
let environmentWithHtml = context.environmentList.filter((item)=>isServingAssets(item.config) && Object.keys(item.htmlPaths).length > 0);
|
|
4054
4065
|
if (0 === environmentWithHtml.length) return [];
|
|
4055
4066
|
let commonDistPath = getCommonParentPath(environmentWithHtml.map((item)=>item.distPath));
|
|
4056
4067
|
return environmentWithHtml.reduce((prev, environmentContext)=>{
|
|
@@ -4127,32 +4138,32 @@ function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls
|
|
|
4127
4138
|
});
|
|
4128
4139
|
return originalConfig && originalConfig.server?.host === void 0 && (message += ` ➜ ${color.dim('Network:')} ${color.dim('use')} ${color.bold('--host')} ${color.dim('to expose')}\n`), !0 === cliShortcutsEnabled && message.endsWith('\n') && (message = message.slice(0, -1)), logger.log(message), message;
|
|
4129
4140
|
}
|
|
4130
|
-
let
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4141
|
+
let resolvePort = async (config, lastPort)=>{
|
|
4142
|
+
let { host, port: originalPort, strictPort } = config.server, preferredPort = 0 === originalPort ? lastPort : void 0, port = await (async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
4143
|
+
'string' == typeof port && (port = Number.parseInt(port, 10)), strictPort && (tryLimits = 1);
|
|
4144
|
+
let { createServer } = await import("node:net"), original = port, found = !1, attempts = 0;
|
|
4145
|
+
for(; !found && attempts <= tryLimits;)try {
|
|
4146
|
+
await new Promise((resolve, reject)=>{
|
|
4147
|
+
let server = createServer();
|
|
4148
|
+
server.unref(), server.on('error', reject), server.listen({
|
|
4149
|
+
port,
|
|
4150
|
+
host
|
|
4151
|
+
}, ()=>{
|
|
4152
|
+
if (0 === port) {
|
|
4153
|
+
let address = server.address();
|
|
4154
|
+
address && 'string' != typeof address && (port = address.port);
|
|
4155
|
+
}
|
|
4156
|
+
found = !0, server.close(resolve);
|
|
4157
|
+
});
|
|
4145
4158
|
});
|
|
4146
|
-
})
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
}, resolvePort = async (config, lastPort)=>{
|
|
4155
|
-
let { host, port: originalPort, strictPort } = config.server, preferredPort = 0 === originalPort ? lastPort : void 0, port = await getPort({
|
|
4159
|
+
} catch (e) {
|
|
4160
|
+
if (!(e instanceof Error) || !('code' in e) || 'EADDRINUSE' !== e.code) throw e;
|
|
4161
|
+
port++, attempts++;
|
|
4162
|
+
}
|
|
4163
|
+
if (!found) throw Error(`${color.dim('[rsbuild:server]')} Failed to find an available port after ${tryLimits + 1} attempts, starting from ${color.yellow(original)}.`);
|
|
4164
|
+
if (0 !== original && port !== original && strictPort) throw Error(`${color.dim('[rsbuild:server]')} Port ${color.yellow(original)} is occupied, please choose another one.`);
|
|
4165
|
+
return port;
|
|
4166
|
+
})({
|
|
4156
4167
|
host,
|
|
4157
4168
|
port: preferredPort ?? originalPort,
|
|
4158
4169
|
strictPort: void 0 === preferredPort && strictPort
|
|
@@ -4380,100 +4391,7 @@ function watchFilesForRestart({ watchFiles, context, restartContext }) {
|
|
|
4380
4391
|
close
|
|
4381
4392
|
};
|
|
4382
4393
|
}
|
|
4383
|
-
let RSPACK_BUILD_ERROR = 'Rspack build failed.',
|
|
4384
|
-
let stats, closeCompiler, closingPromise, unregisterRestart, restartWatcher, { watch } = buildOptions, { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
4385
|
-
if ((({ context, isWatch, compiler, rspackConfigs, MultiStatsCtor })=>{
|
|
4386
|
-
let isFirstCompile = !0, { environmentList } = context, onDone = async (stats)=>{
|
|
4387
|
-
let shouldLogWatching = isWatch && isFirstCompile, promise = context.hooks.onAfterBuild.callBatch({
|
|
4388
|
-
isFirstCompile,
|
|
4389
|
-
stats,
|
|
4390
|
-
environments: context.environments,
|
|
4391
|
-
isWatch
|
|
4392
|
-
});
|
|
4393
|
-
isFirstCompile = !1, await promise, shouldLogWatching && context.logger.info('watching for changes...');
|
|
4394
|
-
}, onEnvironmentDone = async (index, stats)=>{
|
|
4395
|
-
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
4396
|
-
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
4397
|
-
environment: environment.name,
|
|
4398
|
-
args: [
|
|
4399
|
-
{
|
|
4400
|
-
isFirstCompile,
|
|
4401
|
-
stats,
|
|
4402
|
-
environment,
|
|
4403
|
-
isWatch,
|
|
4404
|
-
time
|
|
4405
|
-
}
|
|
4406
|
-
]
|
|
4407
|
-
});
|
|
4408
|
-
};
|
|
4409
|
-
onBeforeCompile({
|
|
4410
|
-
compiler,
|
|
4411
|
-
beforeCompile: async ()=>context.hooks.onBeforeBuild.callBatch({
|
|
4412
|
-
bundlerConfigs: rspackConfigs,
|
|
4413
|
-
environments: context.environments,
|
|
4414
|
-
isWatch,
|
|
4415
|
-
isFirstCompile
|
|
4416
|
-
}),
|
|
4417
|
-
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
4418
|
-
let environment = environmentList[buildIndex];
|
|
4419
|
-
return context.hooks.onBeforeEnvironmentCompile.callBatch({
|
|
4420
|
-
environment: environment.name,
|
|
4421
|
-
args: [
|
|
4422
|
-
{
|
|
4423
|
-
bundlerConfig: rspackConfigs[buildIndex],
|
|
4424
|
-
environment,
|
|
4425
|
-
isWatch,
|
|
4426
|
-
isFirstCompile
|
|
4427
|
-
}
|
|
4428
|
-
]
|
|
4429
|
-
});
|
|
4430
|
-
},
|
|
4431
|
-
isWatch
|
|
4432
|
-
}), onCompileDone({
|
|
4433
|
-
compiler,
|
|
4434
|
-
onDone,
|
|
4435
|
-
onEnvironmentDone,
|
|
4436
|
-
MultiStatsCtor
|
|
4437
|
-
});
|
|
4438
|
-
})({
|
|
4439
|
-
context,
|
|
4440
|
-
rspackConfigs,
|
|
4441
|
-
compiler,
|
|
4442
|
-
isWatch: !!watch,
|
|
4443
|
-
MultiStatsCtor: core_rspack.MultiStats
|
|
4444
|
-
}), watch) {
|
|
4445
|
-
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
4446
|
-
compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
4447
|
-
err && logger.error(err);
|
|
4448
|
-
}), closeCompiler = ()=>new Promise((resolve)=>{
|
|
4449
|
-
compiler.close(()=>{
|
|
4450
|
-
resolve();
|
|
4451
|
-
});
|
|
4452
|
-
});
|
|
4453
|
-
} else stats = await new Promise((resolve, reject)=>{
|
|
4454
|
-
compiler.run((err, stats)=>{
|
|
4455
|
-
compiler.close((closeErr)=>{
|
|
4456
|
-
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(stats);
|
|
4457
|
-
});
|
|
4458
|
-
});
|
|
4459
|
-
});
|
|
4460
|
-
let closeBuild = ()=>closingPromise ||= (async ()=>{
|
|
4461
|
-
unregisterRestart?.(), unregisterRestart = void 0, await context.hooks.onCloseBuild.callBatch(), await closeCompiler?.();
|
|
4462
|
-
})();
|
|
4463
|
-
return watch && (unregisterRestart = context.restartManager.registerCleanup(closeBuild), restartWatcher = watchFilesForRestart({
|
|
4464
|
-
watchFiles: context.normalizedConfig.dev.watchFiles,
|
|
4465
|
-
context,
|
|
4466
|
-
restartContext: {
|
|
4467
|
-
action: 'build',
|
|
4468
|
-
options: buildOptions
|
|
4469
|
-
}
|
|
4470
|
-
})), {
|
|
4471
|
-
stats,
|
|
4472
|
-
close: async ()=>{
|
|
4473
|
-
await restartWatcher?.close(), await closeBuild();
|
|
4474
|
-
}
|
|
4475
|
-
};
|
|
4476
|
-
}, main = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/dotenv-expand/13.0.0/1d3d360f4c41ed89366b79ec2c361d16e6aee7ab6c47163ea4f3718f7f78cc4c/node_modules/dotenv-expand/lib/main.js"), DOTENV_LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
4394
|
+
let RSPACK_BUILD_ERROR = 'Rspack build failed.', main = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/dotenv-expand/13.0.0/1d3d360f4c41ed89366b79ec2c361d16e6aee7ab6c47163ea4f3718f7f78cc4c/node_modules/dotenv-expand/lib/main.js"), DOTENV_LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
4477
4395
|
function loadEnv_parse(src) {
|
|
4478
4396
|
let match, obj = {}, lines = src.toString();
|
|
4479
4397
|
for(lines = lines.replace(/\r\n?/gm, '\n'); null != (match = DOTENV_LINE.exec(lines));){
|
|
@@ -5103,7 +5021,7 @@ function parseMinifyOptions(config) {
|
|
|
5103
5021
|
cssOptions: minify.cssOptions
|
|
5104
5022
|
};
|
|
5105
5023
|
}
|
|
5106
|
-
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
5024
|
+
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/index.js"));
|
|
5107
5025
|
async function getLightningCSSLoaderOptions(config, targets, minify) {
|
|
5108
5026
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
5109
5027
|
targets,
|
|
@@ -5134,75 +5052,6 @@ async function loadUserPostcssrc(root, postcssrcCache) {
|
|
|
5134
5052
|
});
|
|
5135
5053
|
return postcssrcCache.set(root, promise), promise.then((config)=>(postcssrcCache.set(root, config), clonePostCSSConfig(config)));
|
|
5136
5054
|
}
|
|
5137
|
-
let getPostcssLoaderOptions = async ({ config, root, postcssrcCache })=>{
|
|
5138
|
-
let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
|
|
5139
|
-
userOptions.plugins ||= [];
|
|
5140
|
-
let defaultOptions = {
|
|
5141
|
-
implementation: getCompiledPath('postcss'),
|
|
5142
|
-
postcssOptions: userOptions,
|
|
5143
|
-
sourceMap: getCSSSourceMap(config)
|
|
5144
|
-
}, finalOptions = await reduceConfigsWithContext({
|
|
5145
|
-
initial: defaultOptions,
|
|
5146
|
-
config: config.tools.postcss,
|
|
5147
|
-
ctx: {
|
|
5148
|
-
addPlugins (plugins, options = {}) {
|
|
5149
|
-
let { order = 'post' } = options, list = helpers_castArray(plugins);
|
|
5150
|
-
'pre' === order ? extraPlugins.unshift(...list) : extraPlugins.push(...list);
|
|
5151
|
-
}
|
|
5152
|
-
}
|
|
5153
|
-
});
|
|
5154
|
-
finalOptions.postcssOptions ||= {};
|
|
5155
|
-
let updatePostcssOptions = (options)=>(options.plugins ||= [], extraPlugins.length && options.plugins.push(...extraPlugins), options.plugins = options.plugins.map((plugin)=>'function' == typeof plugin && 'postcss' in plugin && plugin.postcss ? plugin() : plugin), options.config = !1, options), { postcssOptions } = finalOptions;
|
|
5156
|
-
if ('function' == typeof postcssOptions) {
|
|
5157
|
-
let postcssOptionsWrapper = (loaderContext)=>{
|
|
5158
|
-
let options = postcssOptions(loaderContext);
|
|
5159
|
-
if ('object' != typeof options || null === options) throw Error(`${color.dim('[rsbuild:css]')} \`postcssOptions\` function must return a PostCSSOptions object, got ${color.yellow(typeof options)}.`);
|
|
5160
|
-
return updatePostcssOptions({
|
|
5161
|
-
...userOptions,
|
|
5162
|
-
...options,
|
|
5163
|
-
plugins: [
|
|
5164
|
-
...userOptions.plugins || [],
|
|
5165
|
-
...options.plugins || []
|
|
5166
|
-
]
|
|
5167
|
-
});
|
|
5168
|
-
};
|
|
5169
|
-
return postcssOptionsWrapper.config = !1, {
|
|
5170
|
-
...finalOptions,
|
|
5171
|
-
postcssOptions: postcssOptionsWrapper
|
|
5172
|
-
};
|
|
5173
|
-
}
|
|
5174
|
-
return finalOptions.postcssOptions = updatePostcssOptions(postcssOptions), finalOptions;
|
|
5175
|
-
}, getCSSLoaderOptions = async ({ config, localIdentName, emitCss })=>{
|
|
5176
|
-
let { cssModules } = config.output, defaultOptions = {
|
|
5177
|
-
modules: {
|
|
5178
|
-
...cssModules,
|
|
5179
|
-
localIdentName
|
|
5180
|
-
},
|
|
5181
|
-
sourceMap: getCSSSourceMap(config)
|
|
5182
|
-
};
|
|
5183
|
-
return ((options, exportOnlyLocals)=>{
|
|
5184
|
-
if (options.modules && exportOnlyLocals) {
|
|
5185
|
-
let { modules } = options;
|
|
5186
|
-
return modules = !0 === modules ? {
|
|
5187
|
-
exportOnlyLocals: !0
|
|
5188
|
-
} : 'string' == typeof modules ? {
|
|
5189
|
-
mode: modules,
|
|
5190
|
-
exportOnlyLocals: !0
|
|
5191
|
-
} : {
|
|
5192
|
-
...modules,
|
|
5193
|
-
exportOnlyLocals: !0
|
|
5194
|
-
}, {
|
|
5195
|
-
...options,
|
|
5196
|
-
modules
|
|
5197
|
-
};
|
|
5198
|
-
}
|
|
5199
|
-
return options;
|
|
5200
|
-
})(await reduceConfigs({
|
|
5201
|
-
initial: defaultOptions,
|
|
5202
|
-
config: config.tools.cssLoader,
|
|
5203
|
-
mergeFn: cjs_0_default()
|
|
5204
|
-
}), !emitCss);
|
|
5205
|
-
};
|
|
5206
5055
|
function checkProcessEnvSecurity(define, logger) {
|
|
5207
5056
|
let value = define['process.env'];
|
|
5208
5057
|
if (!value) return;
|
|
@@ -5215,13 +5064,7 @@ function checkProcessEnvSecurity(define, logger) {
|
|
|
5215
5064
|
check(JSON.parse(value));
|
|
5216
5065
|
} catch {}
|
|
5217
5066
|
}
|
|
5218
|
-
let
|
|
5219
|
-
if (await isFileExists(pkgJsonPath)) try {
|
|
5220
|
-
return JSON.parse(await readFile(pkgJsonPath, 'utf8'));
|
|
5221
|
-
} catch {
|
|
5222
|
-
return;
|
|
5223
|
-
}
|
|
5224
|
-
}, dependencyTypes = [
|
|
5067
|
+
let dependencyTypes = [
|
|
5225
5068
|
'dependencies',
|
|
5226
5069
|
'peerDependencies',
|
|
5227
5070
|
'devDependencies',
|
|
@@ -5238,18 +5081,6 @@ let readPackageJsonByPath = async (pkgJsonPath)=>{
|
|
|
5238
5081
|
...!0 === autoExternal ? {} : autoExternal
|
|
5239
5082
|
};
|
|
5240
5083
|
return dependencyTypes.some((type)=>externalOptions[type]) ? externalOptions : void 0;
|
|
5241
|
-
}, readPackageJsonList = async (paths, cache)=>{
|
|
5242
|
-
var packageJsonList = (await Promise.all(paths.map(async (path)=>(cache.has(path) || cache.set(path, await readPackageJsonByPath(path)), cache.get(path))))).filter((pkgJson)=>!!pkgJson);
|
|
5243
|
-
return packageJsonList.length ? dependencyTypes.reduce((merged, type)=>{
|
|
5244
|
-
for (let pkgJson of packageJsonList){
|
|
5245
|
-
let deps = pkgJson[type];
|
|
5246
|
-
isPlainObject(deps) && (merged[type] = {
|
|
5247
|
-
...merged[type],
|
|
5248
|
-
...deps
|
|
5249
|
-
});
|
|
5250
|
-
}
|
|
5251
|
-
return merged;
|
|
5252
|
-
}, {}) : void 0;
|
|
5253
5084
|
};
|
|
5254
5085
|
function pluginExternals() {
|
|
5255
5086
|
return {
|
|
@@ -5260,7 +5091,25 @@ function pluginExternals() {
|
|
|
5260
5091
|
let pkgJson, { autoExternal, externals } = environment.config.output, externalOptions = resolveAutoExternalOptions(autoExternal);
|
|
5261
5092
|
if (externalOptions) {
|
|
5262
5093
|
let rootPath, packageJsonPaths = (rootPath = api.context.rootPath, helpers_castArray(externalOptions.packageJson ?? 'package.json').map((path)=>external_node_path_resolve(rootPath, path)));
|
|
5263
|
-
pkgJson = await
|
|
5094
|
+
pkgJson = await (async (paths, cache)=>{
|
|
5095
|
+
var packageJsonList = (await Promise.all(paths.map(async (path)=>(cache.has(path) || cache.set(path, await (async (pkgJsonPath)=>{
|
|
5096
|
+
if (await isFileExists(pkgJsonPath)) try {
|
|
5097
|
+
return JSON.parse(await readFile(pkgJsonPath, 'utf8'));
|
|
5098
|
+
} catch {
|
|
5099
|
+
return;
|
|
5100
|
+
}
|
|
5101
|
+
})(path)), cache.get(path))))).filter((pkgJson)=>!!pkgJson);
|
|
5102
|
+
return packageJsonList.length ? dependencyTypes.reduce((merged, type)=>{
|
|
5103
|
+
for (let pkgJson of packageJsonList){
|
|
5104
|
+
let deps = pkgJson[type];
|
|
5105
|
+
isPlainObject(deps) && (merged[type] = {
|
|
5106
|
+
...merged[type],
|
|
5107
|
+
...deps
|
|
5108
|
+
});
|
|
5109
|
+
}
|
|
5110
|
+
return merged;
|
|
5111
|
+
}, {}) : void 0;
|
|
5112
|
+
})(packageJsonPaths, packageJsonCache);
|
|
5264
5113
|
}
|
|
5265
5114
|
!externalOptions || pkgJson || hasWarnedReadPackageJsonFailed || (api.logger.warn('The `output.autoExternal` configuration will not be applied because reading package.json failed.'), hasWarnedReadPackageJsonFailed = !0);
|
|
5266
5115
|
let autoExternalRules = ((options)=>{
|
|
@@ -5296,7 +5145,10 @@ function getAssetNames(compilation) {
|
|
|
5296
5145
|
function createAssetProcessor() {
|
|
5297
5146
|
let failure, active = 0, waiting = [];
|
|
5298
5147
|
return async (names, processAsset)=>{
|
|
5299
|
-
let cursor = 0
|
|
5148
|
+
let cursor = 0;
|
|
5149
|
+
if (await Promise.all(Array.from({
|
|
5150
|
+
length: Math.min(16, names.length)
|
|
5151
|
+
}, async ()=>{
|
|
5300
5152
|
for(; cursor < names.length && !failure;){
|
|
5301
5153
|
let index = cursor++;
|
|
5302
5154
|
active >= 16 ? await new Promise((resolve)=>waiting.push(resolve)) : active++;
|
|
@@ -5312,10 +5164,7 @@ function createAssetProcessor() {
|
|
|
5312
5164
|
next ? next() : active--;
|
|
5313
5165
|
}
|
|
5314
5166
|
}
|
|
5315
|
-
};
|
|
5316
|
-
if (await Promise.all(Array.from({
|
|
5317
|
-
length: Math.min(16, names.length)
|
|
5318
|
-
}, consume)), failure) throw failure.error;
|
|
5167
|
+
})), failure) throw failure.error;
|
|
5319
5168
|
};
|
|
5320
5169
|
}
|
|
5321
5170
|
function getCompression(compressed) {
|
|
@@ -5379,7 +5228,7 @@ let EXCLUDE_ASSET_REGEX = /\.(?:map|LICENSE\.txt|d\.(?:ts|mts|cts))$/, isSignifi
|
|
|
5379
5228
|
label: (diff > 0 ? color.red : color.green)(label),
|
|
5380
5229
|
length: label.length
|
|
5381
5230
|
};
|
|
5382
|
-
}, getAssetColor = (size)=>size > 300000 ? color.red : size > 100000 ? color.yellow : (input)=>input;
|
|
5231
|
+
}, getAssetColor = (size)=>size > 300000 ? color.red : size > 100000 ? color.yellow : (0, (input)=>input);
|
|
5383
5232
|
function getHeader(maxFileLength, maxSizeLength, fileHeader, compressionHeader) {
|
|
5384
5233
|
let lengths = [
|
|
5385
5234
|
maxFileLength,
|
|
@@ -5639,42 +5488,7 @@ class RsbuildHtmlPlugin {
|
|
|
5639
5488
|
this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData, this.getHTMLPlugin = getHTMLPlugin;
|
|
5640
5489
|
}
|
|
5641
5490
|
apply(compiler) {
|
|
5642
|
-
let
|
|
5643
|
-
let fileContent, name = node_path.basename(favicon), outputFilename = node_path.posix.join(faviconDistPath, name);
|
|
5644
|
-
if (outputFilename in compilation.assets) return outputFilename;
|
|
5645
|
-
let inputFs = compilation.inputFileSystem;
|
|
5646
|
-
if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
|
|
5647
|
-
let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
|
|
5648
|
-
try {
|
|
5649
|
-
fileContent = await readFileAsync(inputFs, inputFilename);
|
|
5650
|
-
} catch (error) {
|
|
5651
|
-
return logger.debug('read favicon error:', error), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
|
|
5652
|
-
}
|
|
5653
|
-
let source = new core_rspack.sources.RawSource(fileContent, !1);
|
|
5654
|
-
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
5655
|
-
}, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath, logger })=>{
|
|
5656
|
-
let href = favicon;
|
|
5657
|
-
if (!isURL(favicon)) {
|
|
5658
|
-
let name = await emitFavicon({
|
|
5659
|
-
compilation,
|
|
5660
|
-
favicon,
|
|
5661
|
-
faviconDistPath,
|
|
5662
|
-
logger
|
|
5663
|
-
});
|
|
5664
|
-
if (null === name) return;
|
|
5665
|
-
href = ensureAssetPrefix(name, publicPath);
|
|
5666
|
-
}
|
|
5667
|
-
let tag = {
|
|
5668
|
-
tagName: 'link',
|
|
5669
|
-
voidTag: !0,
|
|
5670
|
-
attributes: {
|
|
5671
|
-
rel: 'icon',
|
|
5672
|
-
href
|
|
5673
|
-
},
|
|
5674
|
-
meta: {}
|
|
5675
|
-
};
|
|
5676
|
-
href.endsWith('.svg') && (tag.attributes.type = 'image/svg+xml'), headTags.unshift(tag);
|
|
5677
|
-
}, getExtraDataByPlugin = (plugin)=>{
|
|
5491
|
+
let getExtraDataByPlugin = (plugin)=>{
|
|
5678
5492
|
if (!plugin.options) return;
|
|
5679
5493
|
let entryName = plugin.options[entryNameSymbol];
|
|
5680
5494
|
if (entryName) return this.getExtraData(entryName);
|
|
@@ -5693,7 +5507,42 @@ class RsbuildHtmlPlugin {
|
|
|
5693
5507
|
voidTag: !1,
|
|
5694
5508
|
meta: {}
|
|
5695
5509
|
});
|
|
5696
|
-
})(headTags, data.plugin.options?.title), favicon && await
|
|
5510
|
+
})(headTags, data.plugin.options?.title), favicon && await (async ({ headTags, favicon, faviconDistPath, compilation, publicPath, logger })=>{
|
|
5511
|
+
let href = favicon;
|
|
5512
|
+
if (!isURL(favicon)) {
|
|
5513
|
+
let name = await (async ({ compilation, favicon, faviconDistPath, logger })=>{
|
|
5514
|
+
let fileContent, name = node_path.basename(favicon), outputFilename = node_path.posix.join(faviconDistPath, name);
|
|
5515
|
+
if (outputFilename in compilation.assets) return outputFilename;
|
|
5516
|
+
let inputFs = compilation.inputFileSystem;
|
|
5517
|
+
if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
|
|
5518
|
+
let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
|
|
5519
|
+
try {
|
|
5520
|
+
fileContent = await readFileAsync(inputFs, inputFilename);
|
|
5521
|
+
} catch (error) {
|
|
5522
|
+
return logger.debug('read favicon error:', error), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
|
|
5523
|
+
}
|
|
5524
|
+
let source = new core_rspack.sources.RawSource(fileContent, !1);
|
|
5525
|
+
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
5526
|
+
})({
|
|
5527
|
+
compilation,
|
|
5528
|
+
favicon,
|
|
5529
|
+
faviconDistPath,
|
|
5530
|
+
logger
|
|
5531
|
+
});
|
|
5532
|
+
if (null === name) return;
|
|
5533
|
+
href = ensureAssetPrefix(name, publicPath);
|
|
5534
|
+
}
|
|
5535
|
+
let tag = {
|
|
5536
|
+
tagName: 'link',
|
|
5537
|
+
voidTag: !0,
|
|
5538
|
+
attributes: {
|
|
5539
|
+
rel: 'icon',
|
|
5540
|
+
href
|
|
5541
|
+
},
|
|
5542
|
+
meta: {}
|
|
5543
|
+
};
|
|
5544
|
+
href.endsWith('.svg') && (tag.attributes.type = 'image/svg+xml'), headTags.unshift(tag);
|
|
5545
|
+
})({
|
|
5697
5546
|
headTags,
|
|
5698
5547
|
favicon,
|
|
5699
5548
|
faviconDistPath,
|
|
@@ -5922,14 +5771,14 @@ let supportedChromiumBrowsers = [
|
|
|
5922
5771
|
async function openBrowser(url, logger) {
|
|
5923
5772
|
let browser = process.env.BROWSER, browserArgs = process.env.BROWSER_ARGS;
|
|
5924
5773
|
if ('darwin' === process.platform && (!browser || !browserArgs) && (!browser || supportedChromiumBrowsers.includes(mapChromiumBrowserName(browser)))) {
|
|
5925
|
-
let { execFile } = await import("node:child_process"), execFileAsync = promisify(execFile)
|
|
5926
|
-
let { stdout: ps } = await execFileAsync('ps', [
|
|
5927
|
-
'cax'
|
|
5928
|
-
]);
|
|
5929
|
-
return supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
5930
|
-
};
|
|
5774
|
+
let { execFile } = await import("node:child_process"), execFileAsync = promisify(execFile);
|
|
5931
5775
|
try {
|
|
5932
|
-
let chromiumBrowser = browser ? mapChromiumBrowserName(browser) : await
|
|
5776
|
+
let chromiumBrowser = browser ? mapChromiumBrowserName(browser) : await (async ()=>{
|
|
5777
|
+
let { stdout: ps } = await execFileAsync('ps', [
|
|
5778
|
+
'cax'
|
|
5779
|
+
]);
|
|
5780
|
+
return supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
5781
|
+
})();
|
|
5933
5782
|
if (chromiumBrowser) return await execFileAsync("osascript", [
|
|
5934
5783
|
"openChrome.applescript",
|
|
5935
5784
|
encodeURI(url),
|
|
@@ -6018,7 +5867,7 @@ function doesChunkBelongToHtml({ chunk, htmlPluginData }) {
|
|
|
6018
5867
|
let { options } = htmlPluginData.plugin;
|
|
6019
5868
|
return recursiveChunkEntryNames(chunk).some((chunkName)=>isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks));
|
|
6020
5869
|
}
|
|
6021
|
-
let getManifestPlugin = cachedImport_cachedImport(()=>import("./manifest-plugin.js").then(rspackRequire.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/rspack-manifest-plugin/5.2.2/
|
|
5870
|
+
let getManifestPlugin = cachedImport_cachedImport(()=>import("./manifest-plugin.js").then(rspackRequire.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/rspack-manifest-plugin/5.2.2/7effcc0bb8833fe538e43fc501c2e2f26971eb61bf9b4827f15ff72c12352aed/node_modules/rspack-manifest-plugin/dist/index.js"))), isCSSPath = (filePath)=>filePath.endsWith('.css');
|
|
6022
5871
|
function normalizeManifestObjectConfig(manifest) {
|
|
6023
5872
|
let defaultOptions = {
|
|
6024
5873
|
prefix: !0,
|
|
@@ -6058,13 +5907,13 @@ function pluginModuleFederation() {
|
|
|
6058
5907
|
}
|
|
6059
5908
|
};
|
|
6060
5909
|
}
|
|
6061
|
-
function getPublicPath({ isDev, config, context }) {
|
|
5910
|
+
async function getPublicPath({ isDev, config, context }) {
|
|
6062
5911
|
let { dev, output, server } = config, publicPath = "/";
|
|
6063
5912
|
if (isDev) {
|
|
6064
5913
|
if ('string' == typeof dev.assetPrefix) publicPath = dev.assetPrefix;
|
|
6065
5914
|
else if (dev.assetPrefix) {
|
|
6066
|
-
let protocol = context.devServer?.https ? 'https' : 'http',
|
|
6067
|
-
publicPath =
|
|
5915
|
+
let protocol = context.devServer?.https ? 'https' : 'http', host = context.devServer?.hostname || LOCALHOST, hostname = WILDCARD_HOSTS.has(host) ? LOCALHOST : await getHostInUrl(host);
|
|
5916
|
+
publicPath = `${protocol}://${hostname}:<port>/`, server.base && '/' !== server.base && (publicPath = urlJoin(publicPath, server.base));
|
|
6068
5917
|
}
|
|
6069
5918
|
} else 'string' == typeof output.assetPrefix && (publicPath = output.assetPrefix);
|
|
6070
5919
|
let defaultPort = server.port ?? 3000;
|
|
@@ -6739,12 +6588,7 @@ function destroyStream(stream, suppress) {
|
|
|
6739
6588
|
'number' == typeof fd && this.close();
|
|
6740
6589
|
}), 'function' == typeof stream.addListener && suppress && (stream.removeAllListeners('error'), stream.addListener('error', ()=>{}));
|
|
6741
6590
|
}
|
|
6742
|
-
let getRangeParser = cachedImport_cachedImport(()=>import("./range-parser.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/range-parser/1.3.0/d49e5dcb9d0e39475844e240fad8cd1db6a58f4144f7ede43d9755e2fce5babc/node_modules/range-parser/index.js", 23)))
|
|
6743
|
-
let { default: rangeParser } = await getRangeParser(), [len, rangeHeader] = value.split('|');
|
|
6744
|
-
return rangeParser(Number(len), rangeHeader, {
|
|
6745
|
-
combine: !0
|
|
6746
|
-
});
|
|
6747
|
-
};
|
|
6591
|
+
let getRangeParser = cachedImport_cachedImport(()=>import("./range-parser.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/range-parser/1.3.0/d49e5dcb9d0e39475844e240fad8cd1db6a58f4144f7ede43d9755e2fce5babc/node_modules/range-parser/index.js", 23)));
|
|
6748
6592
|
function sendError(res, code) {
|
|
6749
6593
|
let content = {
|
|
6750
6594
|
400: 'Bad Request',
|
|
@@ -6769,12 +6613,11 @@ function sendError(res, code) {
|
|
|
6769
6613
|
let byteLength = Buffer.byteLength(document);
|
|
6770
6614
|
res.setHeader('Content-Length', byteLength), res.end(document);
|
|
6771
6615
|
}
|
|
6772
|
-
let filterWebEnvironments = (environmentList)=>environmentList.filter((environment)=>isWebTarget(environment.config.output.target));
|
|
6773
6616
|
function createAssetsMiddleware(context, { waitForAssets, waitForBuild }, outputFileSystem) {
|
|
6774
|
-
let { logger } = context,
|
|
6617
|
+
let { logger } = context, servedEnvironments = context.environmentList.filter((environment)=>isServingAssets(environment.config)), assetContext = {
|
|
6775
6618
|
...context,
|
|
6776
|
-
environmentList:
|
|
6777
|
-
publicPathnames:
|
|
6619
|
+
environmentList: servedEnvironments,
|
|
6620
|
+
publicPathnames: servedEnvironments.map((environment)=>context.publicPathnames[environment.index])
|
|
6778
6621
|
};
|
|
6779
6622
|
return async function assetsMiddleware(req, res, next) {
|
|
6780
6623
|
function goNext() {
|
|
@@ -6815,7 +6658,12 @@ function createAssetsMiddleware(context, { waitForAssets, waitForBuild }, output
|
|
|
6815
6658
|
}
|
|
6816
6659
|
}
|
|
6817
6660
|
if (rangeHeader) {
|
|
6818
|
-
let parsedRanges = await
|
|
6661
|
+
let parsedRanges = await (async (value)=>{
|
|
6662
|
+
let { default: rangeParser } = await getRangeParser(), [len, rangeHeader] = value.split('|');
|
|
6663
|
+
return rangeParser(Number(len), rangeHeader, {
|
|
6664
|
+
combine: !0
|
|
6665
|
+
});
|
|
6666
|
+
})(`${size}|${rangeHeader}`);
|
|
6819
6667
|
if (isRangeFresh(req.headers, res) || (parsedRanges = []), -1 === parsedRanges) {
|
|
6820
6668
|
logger.error("[rsbuild:middleware] Unsatisfiable range for 'Range' header."), res.setHeader('Content-Range', getValueContentRangeHeader('bytes', size)), sendError(res, 416);
|
|
6821
6669
|
return;
|
|
@@ -6915,10 +6763,7 @@ let noop = ()=>{}, normalizeLiveReload = (liveReload)=>'boolean' == typeof liveR
|
|
|
6915
6763
|
} : {
|
|
6916
6764
|
enabled: !0,
|
|
6917
6765
|
html: !1 !== liveReload.html
|
|
6918
|
-
},
|
|
6919
|
-
let { target } = compiler.options;
|
|
6920
|
-
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
6921
|
-
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6766
|
+
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6922
6767
|
function applyHMREntry({ config, compiler, token, resolvedHost, resolvedPort }) {
|
|
6923
6768
|
var overlay;
|
|
6924
6769
|
let overlay1;
|
|
@@ -6948,111 +6793,6 @@ init(
|
|
|
6948
6793
|
name: void 0
|
|
6949
6794
|
}).apply(compiler);
|
|
6950
6795
|
}
|
|
6951
|
-
let assets_middleware_assetsMiddleware = async ({ config, compiler, context, socketServer, resolvedPort })=>{
|
|
6952
|
-
let watching, allCompilers, webCompilers, earlyWebUpdates, { logger } = context, resolvedHost = await resolveHostname(config.server.host), { environmentList } = context, { allCompilers: allCompilers1, webCompilers: webCompilers1, earlyWebUpdates: earlyWebUpdates1 } = (earlyWebUpdates = (webCompilers = (allCompilers = compiler_isMultiCompiler(compiler) ? compiler.compilers : [
|
|
6953
|
-
compiler
|
|
6954
|
-
]).filter((compiler)=>!isNodeCompiler(compiler))).length > 0 && webCompilers.length < allCompilers.length, {
|
|
6955
|
-
allCompilers,
|
|
6956
|
-
webCompilers,
|
|
6957
|
-
earlyWebUpdates
|
|
6958
|
-
});
|
|
6959
|
-
applyToCompiler(compiler, (compiler, index)=>{
|
|
6960
|
-
let environment = environmentList[index];
|
|
6961
|
-
if (!environment) return;
|
|
6962
|
-
let token = environment.webSocketToken;
|
|
6963
|
-
token && (applyHMREntry({
|
|
6964
|
-
token,
|
|
6965
|
-
config: environment.config,
|
|
6966
|
-
compiler,
|
|
6967
|
-
resolvedHost,
|
|
6968
|
-
resolvedPort
|
|
6969
|
-
}), (({ context, compiler, token, socketServer, liveReload, earlyWebUpdates })=>{
|
|
6970
|
-
if (isNodeCompiler(compiler)) return;
|
|
6971
|
-
let errorsCount = null, warningsCount = null, reset = ()=>{
|
|
6972
|
-
errorsCount = null, warningsCount = null, socketServer.clearEnvironmentStats(token);
|
|
6973
|
-
};
|
|
6974
|
-
compiler.hooks.watchRun.tap('rsbuild-dev-server', reset), compiler.hooks.invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
6975
|
-
reset(), 'string' == typeof fileName && fileName.endsWith('.html') && normalizeLiveReload(liveReload).html && socketServer.sendMessage({
|
|
6976
|
-
type: 'full-reload'
|
|
6977
|
-
}, token);
|
|
6978
|
-
}), compiler.hooks.done.tap('rsbuild-dev-server', (stats)=>{
|
|
6979
|
-
let { errors, warnings } = stats.compilation;
|
|
6980
|
-
if (errors.length === errorsCount && warnings.length === warningsCount) return;
|
|
6981
|
-
null === errorsCount && null === warningsCount && earlyWebUpdates && !stats.hasErrors() && socketServer.onEnvironmentDone(token, ()=>getEarlyStats(stats));
|
|
6982
|
-
let isRecalled = null !== errorsCount || null !== warningsCount;
|
|
6983
|
-
if (errorsCount = errors.length, warningsCount = warnings.length, isRecalled) {
|
|
6984
|
-
let tsErrors = errors.filter(isTsError), tsWarnings = warnings.filter(isTsError);
|
|
6985
|
-
if (!tsErrors.length && !tsWarnings.length) return;
|
|
6986
|
-
let { stats: statsJson } = context.buildState, handleTsIssues = (issues, type, sendFn)=>{
|
|
6987
|
-
let statsIssues = issues.map((item)=>pick(item, [
|
|
6988
|
-
'message',
|
|
6989
|
-
'file'
|
|
6990
|
-
]));
|
|
6991
|
-
statsJson && (statsJson[type] = statsJson[type] ? [
|
|
6992
|
-
...statsJson[type],
|
|
6993
|
-
...statsIssues
|
|
6994
|
-
] : statsIssues), sendFn(statsIssues, token);
|
|
6995
|
-
};
|
|
6996
|
-
if (tsErrors.length > 0) return void handleTsIssues(tsErrors, 'errors', (issues, token)=>{
|
|
6997
|
-
socketServer.sendError(issues, token);
|
|
6998
|
-
});
|
|
6999
|
-
if (tsWarnings.length > 0) return void handleTsIssues(tsWarnings, 'warnings', (issues, token)=>{
|
|
7000
|
-
socketServer.sendWarning(issues, token);
|
|
7001
|
-
});
|
|
7002
|
-
}
|
|
7003
|
-
});
|
|
7004
|
-
})({
|
|
7005
|
-
context,
|
|
7006
|
-
compiler,
|
|
7007
|
-
socketServer,
|
|
7008
|
-
token,
|
|
7009
|
-
liveReload: environment.config.dev.liveReload,
|
|
7010
|
-
earlyWebUpdates: earlyWebUpdates1
|
|
7011
|
-
}));
|
|
7012
|
-
});
|
|
7013
|
-
let assetCallbacks = [], buildCallbacks = [], flushCallbacks = (callbacks)=>{
|
|
7014
|
-
for (let callback of callbacks.splice(0))callback();
|
|
7015
|
-
}, flushAllCallbacks = ()=>{
|
|
7016
|
-
flushCallbacks(assetCallbacks), flushCallbacks(buildCallbacks);
|
|
7017
|
-
};
|
|
7018
|
-
compiler.hooks.done.tap('rsbuild-dev-middleware', ()=>{
|
|
7019
|
-
process.nextTick(()=>{
|
|
7020
|
-
'done' === context.buildState.status && flushAllCallbacks();
|
|
7021
|
-
});
|
|
7022
|
-
});
|
|
7023
|
-
let compiledWebCompilers = new Set(), isWebReady = ()=>earlyWebUpdates1 && compiledWebCompilers.size === webCompilers1.length;
|
|
7024
|
-
if (earlyWebUpdates1) for (let item of webCompilers1){
|
|
7025
|
-
let reset = ()=>{
|
|
7026
|
-
compiledWebCompilers.delete(item);
|
|
7027
|
-
};
|
|
7028
|
-
item.hooks.invalid.tap('rsbuild-dev-middleware', reset), item.hooks.watchRun.tap('rsbuild-dev-middleware', reset), item.hooks.done.tap('rsbuild-dev-middleware', (stats)=>{
|
|
7029
|
-
!stats.hasErrors() && (compiledWebCompilers.add(item), isWebReady() && process.nextTick(()=>{
|
|
7030
|
-
isWebReady() && flushCallbacks(assetCallbacks);
|
|
7031
|
-
}));
|
|
7032
|
-
});
|
|
7033
|
-
}
|
|
7034
|
-
let writeToDiskList = environmentList.map((environment)=>environment.config.dev.writeToDisk);
|
|
7035
|
-
writeToDiskList.some(Boolean) && setupWriteToDisk(allCompilers1, writeToDiskList, logger);
|
|
7036
|
-
let outputFileSystem = await setupOutputFileSystem(writeToDiskList.every((writeToDisk)=>!0 === writeToDisk), allCompilers1), isBuildReady = ()=>'done' === context.buildState.status || 'failed' === context.buildState.status, instance = createAssetsMiddleware(context, {
|
|
7037
|
-
waitForAssets: (callback)=>{
|
|
7038
|
-
isBuildReady() || isWebReady() ? callback() : assetCallbacks.push(callback);
|
|
7039
|
-
},
|
|
7040
|
-
waitForBuild: (callback)=>{
|
|
7041
|
-
isBuildReady() ? callback() : buildCallbacks.push(callback);
|
|
7042
|
-
}
|
|
7043
|
-
}, outputFileSystem);
|
|
7044
|
-
return instance.watch = ()=>{
|
|
7045
|
-
if (compiler.watching) watching = compiler.watching;
|
|
7046
|
-
else {
|
|
7047
|
-
let watchOptions = allCompilers1.length > 1 ? allCompilers1.map(({ options })=>options.watchOptions || {}) : allCompilers1[0].options.watchOptions || {};
|
|
7048
|
-
watching = compiler.watch(watchOptions, (error)=>{
|
|
7049
|
-
error && (context.buildState.status = 'failed', context.buildState.hasErrors = !0, process.nextTick(flushAllCallbacks), error.message?.includes('× Error:') && (error.message = error.message.replace('× Error:', '').trim()), logger.error(error));
|
|
7050
|
-
});
|
|
7051
|
-
}
|
|
7052
|
-
}, instance.close = (callback = noop)=>{
|
|
7053
|
-
watching?.close(callback);
|
|
7054
|
-
}, instance;
|
|
7055
|
-
};
|
|
7056
6796
|
var UNKNOWN_FUNCTION = '<unknown>';
|
|
7057
6797
|
function stack_trace_parser_esm_parse(stackString) {
|
|
7058
6798
|
return stackString.split('\n').reduce(function(stack, line) {
|
|
@@ -7144,16 +6884,6 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7144
6884
|
} catch (error) {
|
|
7145
6885
|
error instanceof Error && context.logger.debug('failed to map source map position:', error);
|
|
7146
6886
|
}
|
|
7147
|
-
}, resolveOriginalLocation = async (stackFrames, fs, context, cache)=>{
|
|
7148
|
-
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
7149
|
-
if (!frame) return;
|
|
7150
|
-
let parsedFrame = await parseFrame(frame, fs, context, cache);
|
|
7151
|
-
if (!parsedFrame) return;
|
|
7152
|
-
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
7153
|
-
return {
|
|
7154
|
-
frame,
|
|
7155
|
-
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
7156
|
-
};
|
|
7157
6887
|
}, formatOriginalLocation = (sourceMapPath, originalMapping, context)=>{
|
|
7158
6888
|
let { source, line, column } = originalMapping;
|
|
7159
6889
|
if (!source) return;
|
|
@@ -7166,39 +6896,23 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7166
6896
|
}, formatFrameLocation = (frame)=>{
|
|
7167
6897
|
let { file, lineNumber, column } = frame;
|
|
7168
6898
|
if (file) return null !== lineNumber ? null !== column ? `${file}:${lineNumber}:${column}` : `${file}:${lineNumber}` : file;
|
|
7169
|
-
}, formatFullStack = async (stackFrames, context, fs, cache)=>{
|
|
7170
|
-
let formattedFrames = [];
|
|
7171
|
-
for (let frame of stackFrames){
|
|
7172
|
-
let location, parsedFrame = await parseFrame(frame, fs, context, cache), { methodName } = frame, parts = [];
|
|
7173
|
-
isValidMethodName(methodName) && parts.push(methodName);
|
|
7174
|
-
let parsed = !1;
|
|
7175
|
-
if (parsedFrame) {
|
|
7176
|
-
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
7177
|
-
originalLocation && (location = originalLocation, parts.push(originalLocation), parsed = !0);
|
|
7178
|
-
}
|
|
7179
|
-
if (!parsed && isVerbose(context.logger)) {
|
|
7180
|
-
let frameString = formatFrameLocation(frame);
|
|
7181
|
-
frameString && (location = frameString, parts.push(frameString));
|
|
7182
|
-
}
|
|
7183
|
-
let [first, second] = parts;
|
|
7184
|
-
if (first) {
|
|
7185
|
-
let isRspackRuntime = isRspackRuntimeStack(methodName) || isRspackRuntimeStack(location);
|
|
7186
|
-
formattedFrames.push({
|
|
7187
|
-
text: second ? `\n at ${first} (${second})` : `\n at ${first}`,
|
|
7188
|
-
isRspackRuntime,
|
|
7189
|
-
hasLocation: void 0 !== location
|
|
7190
|
-
});
|
|
7191
|
-
}
|
|
7192
|
-
}
|
|
7193
|
-
let shouldFilterRspackRuntime = formattedFrames.some((frame)=>!frame.isRspackRuntime && frame.hasLocation);
|
|
7194
|
-
return formattedFrames.filter((frame)=>!(shouldFilterRspackRuntime && frame.isRspackRuntime)).map((frame)=>frame.text).join('');
|
|
7195
6899
|
}, formatBrowserErrorLog = async (message, context, fs, stackTrace, stackFrames, cache)=>{
|
|
7196
6900
|
var log;
|
|
7197
6901
|
let log1 = color.red(message);
|
|
7198
6902
|
if (stackFrames?.length) switch(stackTrace){
|
|
7199
6903
|
case 'summary':
|
|
7200
6904
|
{
|
|
7201
|
-
let resolved = await
|
|
6905
|
+
let resolved = await (async (stackFrames, fs, context, cache)=>{
|
|
6906
|
+
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
6907
|
+
if (!frame) return;
|
|
6908
|
+
let parsedFrame = await parseFrame(frame, fs, context, cache);
|
|
6909
|
+
if (!parsedFrame) return;
|
|
6910
|
+
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
6911
|
+
return {
|
|
6912
|
+
frame,
|
|
6913
|
+
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
6914
|
+
};
|
|
6915
|
+
})(stackFrames, fs, context, cache);
|
|
7202
6916
|
if (!resolved) break;
|
|
7203
6917
|
let { frame, location } = resolved, { methodName } = frame, suffix = '';
|
|
7204
6918
|
isValidMethodName(methodName) && (suffix += ` at ${methodName}`), location && (suffix += ` (${location})`), log1 += suffix ? color.dim(suffix) : '';
|
|
@@ -7206,7 +6920,33 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7206
6920
|
}
|
|
7207
6921
|
case 'full':
|
|
7208
6922
|
{
|
|
7209
|
-
let fullStack = await
|
|
6923
|
+
let fullStack = await (async (stackFrames, context, fs, cache)=>{
|
|
6924
|
+
let formattedFrames = [];
|
|
6925
|
+
for (let frame of stackFrames){
|
|
6926
|
+
let location, parsedFrame = await parseFrame(frame, fs, context, cache), { methodName } = frame, parts = [];
|
|
6927
|
+
isValidMethodName(methodName) && parts.push(methodName);
|
|
6928
|
+
let parsed = !1;
|
|
6929
|
+
if (parsedFrame) {
|
|
6930
|
+
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
6931
|
+
originalLocation && (location = originalLocation, parts.push(originalLocation), parsed = !0);
|
|
6932
|
+
}
|
|
6933
|
+
if (!parsed && isVerbose(context.logger)) {
|
|
6934
|
+
let frameString = formatFrameLocation(frame);
|
|
6935
|
+
frameString && (location = frameString, parts.push(frameString));
|
|
6936
|
+
}
|
|
6937
|
+
let [first, second] = parts;
|
|
6938
|
+
if (first) {
|
|
6939
|
+
let isRspackRuntime = isRspackRuntimeStack(methodName) || isRspackRuntimeStack(location);
|
|
6940
|
+
formattedFrames.push({
|
|
6941
|
+
text: second ? `\n at ${first} (${second})` : `\n at ${first}`,
|
|
6942
|
+
isRspackRuntime,
|
|
6943
|
+
hasLocation: void 0 !== location
|
|
6944
|
+
});
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
let shouldFilterRspackRuntime = formattedFrames.some((frame)=>!frame.isRspackRuntime && frame.hasLocation);
|
|
6948
|
+
return formattedFrames.filter((frame)=>!(shouldFilterRspackRuntime && frame.isRspackRuntime)).map((frame)=>frame.text).join('');
|
|
6949
|
+
})(stackFrames, context, fs, cache);
|
|
7210
6950
|
fullStack && (log1 += fullStack);
|
|
7211
6951
|
}
|
|
7212
6952
|
}
|
|
@@ -7539,7 +7279,110 @@ class BuildManager {
|
|
|
7539
7279
|
}
|
|
7540
7280
|
readFileSync = (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : node_fs.readFileSync(fileName, 'utf-8');
|
|
7541
7281
|
async setupCompilationMiddleware() {
|
|
7542
|
-
let { config, context } = this, middleware = await
|
|
7282
|
+
let { config, context } = this, middleware = await (async ({ config, compiler, context, socketServer, resolvedPort })=>{
|
|
7283
|
+
let watching, allCompilers, webCompilers, earlyWebUpdates, { logger } = context, resolvedHost = await resolveHostname(config.server.host), { environmentList } = context, { allCompilers: allCompilers1, webCompilers: webCompilers1, earlyWebUpdates: earlyWebUpdates1 } = (earlyWebUpdates = (webCompilers = (allCompilers = compiler_isMultiCompiler(compiler) ? compiler.compilers : [
|
|
7284
|
+
compiler
|
|
7285
|
+
]).filter((_, index)=>isWebTarget(environmentList[index].config.output.target))).length > 0 && webCompilers.length < allCompilers.length, {
|
|
7286
|
+
allCompilers,
|
|
7287
|
+
webCompilers,
|
|
7288
|
+
earlyWebUpdates
|
|
7289
|
+
}), canServeWebAssetsEarly = earlyWebUpdates1 && !environmentList.some((environment)=>isServingAssets(environment.config) && !isWebTarget(environment.config.output.target));
|
|
7290
|
+
applyToCompiler(compiler, (compiler, index)=>{
|
|
7291
|
+
let environment = environmentList[index];
|
|
7292
|
+
if (!environment) return;
|
|
7293
|
+
let token = environment.webSocketToken;
|
|
7294
|
+
!token || (applyHMREntry({
|
|
7295
|
+
token,
|
|
7296
|
+
config: environment.config,
|
|
7297
|
+
compiler,
|
|
7298
|
+
resolvedHost,
|
|
7299
|
+
resolvedPort
|
|
7300
|
+
}), isWebTarget(environment.config.output.target) && (({ context, compiler, token, socketServer, liveReload, earlyWebUpdates })=>{
|
|
7301
|
+
let errorsCount = null, warningsCount = null, reset = ()=>{
|
|
7302
|
+
errorsCount = null, warningsCount = null, socketServer.clearEnvironmentStats(token);
|
|
7303
|
+
};
|
|
7304
|
+
compiler.hooks.watchRun.tap('rsbuild-dev-server', reset), compiler.hooks.invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
7305
|
+
reset(), 'string' == typeof fileName && fileName.endsWith('.html') && normalizeLiveReload(liveReload).html && socketServer.sendMessage({
|
|
7306
|
+
type: 'full-reload'
|
|
7307
|
+
}, token);
|
|
7308
|
+
}), compiler.hooks.done.tap('rsbuild-dev-server', (stats)=>{
|
|
7309
|
+
let { errors, warnings } = stats.compilation;
|
|
7310
|
+
if (errors.length === errorsCount && warnings.length === warningsCount) return;
|
|
7311
|
+
null === errorsCount && null === warningsCount && earlyWebUpdates && !stats.hasErrors() && socketServer.onEnvironmentDone(token, ()=>getEarlyStats(stats));
|
|
7312
|
+
let isRecalled = null !== errorsCount || null !== warningsCount;
|
|
7313
|
+
if (errorsCount = errors.length, warningsCount = warnings.length, isRecalled) {
|
|
7314
|
+
let tsErrors = errors.filter(isTsError), tsWarnings = warnings.filter(isTsError);
|
|
7315
|
+
if (!tsErrors.length && !tsWarnings.length) return;
|
|
7316
|
+
let { stats: statsJson } = context.buildState, handleTsIssues = (issues, type, sendFn)=>{
|
|
7317
|
+
let statsIssues = issues.map((item)=>pick(item, [
|
|
7318
|
+
'message',
|
|
7319
|
+
'file'
|
|
7320
|
+
]));
|
|
7321
|
+
statsJson && (statsJson[type] = statsJson[type] ? [
|
|
7322
|
+
...statsJson[type],
|
|
7323
|
+
...statsIssues
|
|
7324
|
+
] : statsIssues), sendFn(statsIssues, token);
|
|
7325
|
+
};
|
|
7326
|
+
if (tsErrors.length > 0) return void handleTsIssues(tsErrors, 'errors', (issues, token)=>{
|
|
7327
|
+
socketServer.sendError(issues, token);
|
|
7328
|
+
});
|
|
7329
|
+
if (tsWarnings.length > 0) return void handleTsIssues(tsWarnings, 'warnings', (issues, token)=>{
|
|
7330
|
+
socketServer.sendWarning(issues, token);
|
|
7331
|
+
});
|
|
7332
|
+
}
|
|
7333
|
+
});
|
|
7334
|
+
})({
|
|
7335
|
+
context,
|
|
7336
|
+
compiler,
|
|
7337
|
+
socketServer,
|
|
7338
|
+
token,
|
|
7339
|
+
liveReload: environment.config.dev.liveReload,
|
|
7340
|
+
earlyWebUpdates: earlyWebUpdates1
|
|
7341
|
+
}));
|
|
7342
|
+
});
|
|
7343
|
+
let assetCallbacks = [], buildCallbacks = [], flushCallbacks = (callbacks)=>{
|
|
7344
|
+
for (let callback of callbacks.splice(0))callback();
|
|
7345
|
+
}, flushAllCallbacks = ()=>{
|
|
7346
|
+
flushCallbacks(assetCallbacks), flushCallbacks(buildCallbacks);
|
|
7347
|
+
};
|
|
7348
|
+
compiler.hooks.done.tap('rsbuild-dev-middleware', ()=>{
|
|
7349
|
+
process.nextTick(()=>{
|
|
7350
|
+
'done' === context.buildState.status && flushAllCallbacks();
|
|
7351
|
+
});
|
|
7352
|
+
});
|
|
7353
|
+
let compiledWebCompilers = new Set(), isWebReady = ()=>canServeWebAssetsEarly && compiledWebCompilers.size === webCompilers1.length;
|
|
7354
|
+
if (canServeWebAssetsEarly) for (let item of webCompilers1){
|
|
7355
|
+
let reset = ()=>{
|
|
7356
|
+
compiledWebCompilers.delete(item);
|
|
7357
|
+
};
|
|
7358
|
+
item.hooks.invalid.tap('rsbuild-dev-middleware', reset), item.hooks.watchRun.tap('rsbuild-dev-middleware', reset), item.hooks.done.tap('rsbuild-dev-middleware', (stats)=>{
|
|
7359
|
+
!stats.hasErrors() && (compiledWebCompilers.add(item), isWebReady() && process.nextTick(()=>{
|
|
7360
|
+
isWebReady() && flushCallbacks(assetCallbacks);
|
|
7361
|
+
}));
|
|
7362
|
+
});
|
|
7363
|
+
}
|
|
7364
|
+
let writeToDiskList = environmentList.map((environment)=>environment.config.dev.writeToDisk);
|
|
7365
|
+
writeToDiskList.some(Boolean) && setupWriteToDisk(allCompilers1, writeToDiskList, logger);
|
|
7366
|
+
let outputFileSystem = await setupOutputFileSystem(writeToDiskList.every((writeToDisk)=>!0 === writeToDisk), allCompilers1), isBuildReady = ()=>'done' === context.buildState.status || 'failed' === context.buildState.status, instance = createAssetsMiddleware(context, {
|
|
7367
|
+
waitForAssets: (callback)=>{
|
|
7368
|
+
isBuildReady() || isWebReady() ? callback() : assetCallbacks.push(callback);
|
|
7369
|
+
},
|
|
7370
|
+
waitForBuild: (callback)=>{
|
|
7371
|
+
isBuildReady() ? callback() : buildCallbacks.push(callback);
|
|
7372
|
+
}
|
|
7373
|
+
}, outputFileSystem);
|
|
7374
|
+
return instance.watch = ()=>{
|
|
7375
|
+
if (compiler.watching) watching = compiler.watching;
|
|
7376
|
+
else {
|
|
7377
|
+
let watchOptions = allCompilers1.length > 1 ? allCompilers1.map(({ options })=>options.watchOptions || {}) : allCompilers1[0].options.watchOptions || {};
|
|
7378
|
+
watching = compiler.watch(watchOptions, (error)=>{
|
|
7379
|
+
error && (context.buildState.status = 'failed', context.buildState.hasErrors = !0, process.nextTick(flushAllCallbacks), error.message?.includes('× Error:') && (error.message = error.message.replace('× Error:', '').trim()), logger.error(error));
|
|
7380
|
+
});
|
|
7381
|
+
}
|
|
7382
|
+
}, instance.close = (callback = noop)=>{
|
|
7383
|
+
watching?.close(callback);
|
|
7384
|
+
}, instance;
|
|
7385
|
+
})({
|
|
7543
7386
|
config,
|
|
7544
7387
|
context,
|
|
7545
7388
|
compiler: this.compiler,
|
|
@@ -7731,7 +7574,7 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
7731
7574
|
}, getRequestLoggerMiddleware = (logger)=>(req, res, next)=>{
|
|
7732
7575
|
let _startAt = process.hrtime();
|
|
7733
7576
|
finished(res, ()=>{
|
|
7734
|
-
let method = req.method, url = req.originalUrl || req.url, status = Number(res.statusCode), statusColor = status >= 500 ? color.red : status >= 400 ? color.yellow : status >= 300 ? color.cyan : status >= 200 ? color.green : (res)=>res, endAt = process.hrtime(), totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
7577
|
+
let method = req.method, url = req.originalUrl || req.url, status = Number(res.statusCode), statusColor = status >= 500 ? color.red : status >= 400 ? color.yellow : status >= 300 ? color.cyan : status >= 200 ? color.green : (0, (res)=>res), endAt = process.hrtime(), totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
7735
7578
|
logger.debug(`${statusColor(status)} ${method} ${url} ${color.dim(`${totalTime.toFixed(3)} ms`)}`);
|
|
7736
7579
|
}), next();
|
|
7737
7580
|
}, notFoundMiddleware = (_req, res, _next)=>{
|
|
@@ -7856,193 +7699,33 @@ async function createProxyMiddleware(proxyOptions, logger) {
|
|
|
7856
7699
|
}
|
|
7857
7700
|
};
|
|
7858
7701
|
}
|
|
7859
|
-
let
|
|
7860
|
-
let
|
|
7861
|
-
if (
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
}
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
let
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
}
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
} catch (err) {
|
|
7887
|
-
next(err);
|
|
7888
|
-
}
|
|
7889
|
-
}), middlewares.use((({ environments, logger })=>async function viewingServedFilesMiddleware(req, res, next) {
|
|
7890
|
-
if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
|
|
7891
|
-
res.writeHead(200, {
|
|
7892
|
-
'Content-Type': 'text/html; charset=utf-8'
|
|
7893
|
-
}), res.write(`<!DOCTYPE html>
|
|
7894
|
-
<html>
|
|
7895
|
-
<head>
|
|
7896
|
-
<meta charset="utf-8"/>
|
|
7897
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7898
|
-
<style>
|
|
7899
|
-
body {
|
|
7900
|
-
margin: 0;
|
|
7901
|
-
color: #f6f7f9;
|
|
7902
|
-
padding: 32px 40px;
|
|
7903
|
-
line-height: 1.8;
|
|
7904
|
-
min-height: 100vh;
|
|
7905
|
-
background-image: linear-gradient(#020917, #101725);
|
|
7906
|
-
font-family: ui-sans-serif,system-ui,sans-serif;
|
|
7907
|
-
}
|
|
7908
|
-
h1, h2 {
|
|
7909
|
-
font-weight: 500;
|
|
7910
|
-
}
|
|
7911
|
-
h1 {
|
|
7912
|
-
margin: 0;
|
|
7913
|
-
font-size: 36px;
|
|
7914
|
-
}
|
|
7915
|
-
h2 {
|
|
7916
|
-
font-size: 20px;
|
|
7917
|
-
margin: 24px 0 16px;
|
|
7918
|
-
}
|
|
7919
|
-
ul {
|
|
7920
|
-
margin: 0;
|
|
7921
|
-
padding-left: 16px;
|
|
7922
|
-
}
|
|
7923
|
-
a {
|
|
7924
|
-
color: #58c4dc;
|
|
7925
|
-
text-decoration: none;
|
|
7926
|
-
}
|
|
7927
|
-
a:hover {
|
|
7928
|
-
text-decoration: underline;
|
|
7929
|
-
}
|
|
7930
|
-
</style>
|
|
7931
|
-
</head>
|
|
7932
|
-
<body>
|
|
7933
|
-
<h1>Assets Report</h1>
|
|
7934
|
-
</body>
|
|
7935
|
-
</html>`);
|
|
7936
|
-
try {
|
|
7937
|
-
for(let key in environments){
|
|
7938
|
-
res.write(`<h2>Environment: ${key}</h2>`);
|
|
7939
|
-
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetNames(stats.compilation);
|
|
7940
|
-
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset}">${asset}</a></li>`);
|
|
7941
|
-
res.write(list?.join('')), res.write('</ul>');
|
|
7942
|
-
}
|
|
7943
|
-
res.end('</body></html>');
|
|
7944
|
-
} catch (err) {
|
|
7945
|
-
logger.error(err), res.writeHead(500), res.end('Failed to list the files');
|
|
7946
|
-
}
|
|
7947
|
-
})({
|
|
7948
|
-
environments: devServer.environments,
|
|
7949
|
-
logger
|
|
7950
|
-
})), buildManager && (middlewares.use(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.use(function hotUpdateJsonFallbackMiddleware(req, res, next) {
|
|
7951
|
-
let url = req.url;
|
|
7952
|
-
if (!url || 'OPTIONS' === req.method) return void next();
|
|
7953
|
-
let queryIndex = url.indexOf('?'), end = -1 === queryIndex ? url.length : queryIndex;
|
|
7954
|
-
url.endsWith('.hot-update.json', end) || url.endsWith('.hot-update.json.mjs', end) ? notFoundMiddleware(req, res, next) : next();
|
|
7955
|
-
})), buildManager && middlewares.use(getHtmlCompletionMiddleware({
|
|
7956
|
-
assetsMiddleware: buildManager.assetsMiddleware,
|
|
7957
|
-
distPaths: [
|
|
7958
|
-
context.distPath
|
|
7959
|
-
],
|
|
7960
|
-
outputFileSystem: buildManager.outputFileSystem
|
|
7961
|
-
}));
|
|
7962
|
-
let publicDirPaths = getPublicDirPaths(config);
|
|
7963
|
-
if (publicDirPaths.length) {
|
|
7964
|
-
let { default: sirv } = await import("./sirv.js");
|
|
7965
|
-
for (let name of publicDirPaths){
|
|
7966
|
-
let sirvMiddleware = sirv(name, {
|
|
7967
|
-
etag: !0,
|
|
7968
|
-
dev: !0
|
|
7969
|
-
});
|
|
7970
|
-
middlewares.use(function publicDirMiddleware(req, res, next) {
|
|
7971
|
-
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? next() : sirvMiddleware(req, res, next);
|
|
7972
|
-
});
|
|
7973
|
-
}
|
|
7974
|
-
}
|
|
7975
|
-
for (let callback of postCallbacks)await callback();
|
|
7976
|
-
return server.historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === server.historyApiFallback ? {} : server.historyApiFallback)), buildManager?.assetsMiddleware && middlewares.use(buildManager.assetsMiddleware)), buildManager && server.htmlFallback && middlewares.use(getHtmlFallbackMiddleware({
|
|
7977
|
-
assetsMiddleware: buildManager.assetsMiddleware,
|
|
7978
|
-
distPaths: [
|
|
7979
|
-
context.distPath
|
|
7980
|
-
],
|
|
7981
|
-
logger,
|
|
7982
|
-
outputFileSystem: buildManager.outputFileSystem
|
|
7983
|
-
})), middlewares.use(faviconFallbackMiddleware), {
|
|
7984
|
-
onUpgrade: (...args)=>{
|
|
7985
|
-
for (let cb of upgradeEvents)cb(...args);
|
|
7986
|
-
}
|
|
7987
|
-
};
|
|
7988
|
-
}, getDevMiddlewares = async (options)=>{
|
|
7989
|
-
let { buildManager, context, devServer } = options, { middlewares } = devServer, { logger } = context;
|
|
7990
|
-
isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger));
|
|
7991
|
-
let { before, after } = ((config, devServer, logger)=>{
|
|
7992
|
-
let setupMiddlewares = config.dev.setupMiddlewares ? helpers_castArray(config.dev.setupMiddlewares) : [];
|
|
7993
|
-
setupMiddlewares.length && logger.warn('[rsbuild] `dev.setupMiddlewares` is deprecated, use `server.setup` instead');
|
|
7994
|
-
let serverOptions = pick(devServer, [
|
|
7995
|
-
'sockWrite',
|
|
7996
|
-
'environments'
|
|
7997
|
-
]), before = [], after = [];
|
|
7998
|
-
for (let handler of setupMiddlewares)handler({
|
|
7999
|
-
unshift: (...handlers)=>before.unshift(...handlers),
|
|
8000
|
-
push: (...handlers)=>after.push(...handlers)
|
|
8001
|
-
}, serverOptions);
|
|
8002
|
-
return {
|
|
8003
|
-
before,
|
|
8004
|
-
after
|
|
8005
|
-
};
|
|
8006
|
-
})(options.config, options.devServer, logger);
|
|
8007
|
-
for (let middleware of before)middlewares.use(middleware);
|
|
8008
|
-
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
8009
|
-
...options,
|
|
8010
|
-
middlewares
|
|
8011
|
-
});
|
|
8012
|
-
for (let middleware of after)middlewares.use(middleware);
|
|
8013
|
-
return {
|
|
8014
|
-
close: async ()=>{
|
|
8015
|
-
await buildManager?.close();
|
|
8016
|
-
},
|
|
8017
|
-
onUpgrade
|
|
8018
|
-
};
|
|
8019
|
-
}, isModuleNamespaceObject = (moduleExports)=>'[object Module]' === Object.prototype.toString.call(moduleExports), asModule = async (vm, moduleExports, context, unlinked)=>{
|
|
8020
|
-
let { Module, SyntheticModule } = vm;
|
|
8021
|
-
if (moduleExports instanceof Module) return moduleExports;
|
|
8022
|
-
let normalizedModuleExports = null !== moduleExports && ('object' == typeof moduleExports || 'function' == typeof moduleExports) ? moduleExports : {
|
|
8023
|
-
default: moduleExports
|
|
8024
|
-
}, exports = [
|
|
8025
|
-
...new Set([
|
|
8026
|
-
'default',
|
|
8027
|
-
...Object.keys(normalizedModuleExports)
|
|
8028
|
-
])
|
|
8029
|
-
], syntheticModule = new SyntheticModule(exports, ()=>{
|
|
8030
|
-
for (let name of exports)if ('default' === name) {
|
|
8031
|
-
let defaultExport = isModuleNamespaceObject(normalizedModuleExports) && 'default' in normalizedModuleExports ? normalizedModuleExports.default : moduleExports;
|
|
8032
|
-
syntheticModule.setExport(name, defaultExport);
|
|
8033
|
-
} else syntheticModule.setExport(name, normalizedModuleExports[name]);
|
|
8034
|
-
}, {
|
|
8035
|
-
context
|
|
8036
|
-
});
|
|
8037
|
-
return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
|
|
8038
|
-
};
|
|
8039
|
-
class BasicRunner {
|
|
8040
|
-
options;
|
|
8041
|
-
globalContext = null;
|
|
8042
|
-
baseModuleScope = null;
|
|
8043
|
-
requirers = new Map();
|
|
8044
|
-
constructor(options){
|
|
8045
|
-
this.options = options;
|
|
7702
|
+
let isModuleNamespaceObject = (moduleExports)=>'[object Module]' === Object.prototype.toString.call(moduleExports), asModule = async (vm, moduleExports, context, unlinked)=>{
|
|
7703
|
+
let { Module, SyntheticModule } = vm;
|
|
7704
|
+
if (moduleExports instanceof Module) return moduleExports;
|
|
7705
|
+
let normalizedModuleExports = null !== moduleExports && ('object' == typeof moduleExports || 'function' == typeof moduleExports) ? moduleExports : {
|
|
7706
|
+
default: moduleExports
|
|
7707
|
+
}, exports = [
|
|
7708
|
+
...new Set([
|
|
7709
|
+
'default',
|
|
7710
|
+
...Object.keys(normalizedModuleExports)
|
|
7711
|
+
])
|
|
7712
|
+
], syntheticModule = new SyntheticModule(exports, ()=>{
|
|
7713
|
+
for (let name of exports)if ('default' === name) {
|
|
7714
|
+
let defaultExport = isModuleNamespaceObject(normalizedModuleExports) && 'default' in normalizedModuleExports ? normalizedModuleExports.default : moduleExports;
|
|
7715
|
+
syntheticModule.setExport(name, defaultExport);
|
|
7716
|
+
} else syntheticModule.setExport(name, normalizedModuleExports[name]);
|
|
7717
|
+
}, {
|
|
7718
|
+
context
|
|
7719
|
+
});
|
|
7720
|
+
return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
|
|
7721
|
+
};
|
|
7722
|
+
class BasicRunner {
|
|
7723
|
+
options;
|
|
7724
|
+
globalContext = null;
|
|
7725
|
+
baseModuleScope = null;
|
|
7726
|
+
requirers = new Map();
|
|
7727
|
+
constructor(options){
|
|
7728
|
+
this.options = options;
|
|
8046
7729
|
}
|
|
8047
7730
|
run(file) {
|
|
8048
7731
|
this.globalContext || (this.globalContext = this.createGlobalContext()), this.baseModuleScope = this.createBaseModuleScope(), this.createRunner();
|
|
@@ -8218,10 +7901,7 @@ class BasicRunnerFactory {
|
|
|
8218
7901
|
return new EsmRunner(runnerOptions);
|
|
8219
7902
|
}
|
|
8220
7903
|
}
|
|
8221
|
-
let
|
|
8222
|
-
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
8223
|
-
return await runner.run(bundlePath);
|
|
8224
|
-
}, loadBundleStatsCache = new WeakMap(), loadBundle = async (stats, entryName, utils)=>{
|
|
7904
|
+
let loadBundleStatsCache = new WeakMap(), loadBundle = async (stats, entryName, utils)=>{
|
|
8225
7905
|
let loadBundleStats = loadBundleStatsCache.get(stats);
|
|
8226
7906
|
loadBundleStats || (loadBundleStats = {
|
|
8227
7907
|
...stats.toJson({
|
|
@@ -8245,7 +7925,10 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
8245
7925
|
for (let chunk of (outputFilePaths = new Set(), chunks || []))for (let file of chunk.files)outputFilePaths.add(join(outputPath, file));
|
|
8246
7926
|
loadBundleStats.outputFilePaths = outputFilePaths;
|
|
8247
7927
|
}
|
|
8248
|
-
return await
|
|
7928
|
+
return await (async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
7929
|
+
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
7930
|
+
return await runner.run(bundlePath);
|
|
7931
|
+
})({
|
|
8249
7932
|
bundlePath: files[0],
|
|
8250
7933
|
dist: outputPath,
|
|
8251
7934
|
compilerOptions: stats.compilation.options,
|
|
@@ -8373,51 +8056,7 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8373
8056
|
let currentStats = stats[index];
|
|
8374
8057
|
return currentStats || waiters[index].promise;
|
|
8375
8058
|
}
|
|
8376
|
-
}), hotConnectCallbacks = new Map(),
|
|
8377
|
-
let compiler = await createCompiler();
|
|
8378
|
-
if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
8379
|
-
context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
8380
|
-
getPublicPathFromCompiler(compiler)
|
|
8381
|
-
], config.server.base);
|
|
8382
|
-
let hookOptions = {
|
|
8383
|
-
name: 'rsbuild:environment-api',
|
|
8384
|
-
stage: -10000
|
|
8385
|
-
};
|
|
8386
|
-
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach((compiler, index)=>{
|
|
8387
|
-
compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8388
|
-
compileState.reset(index);
|
|
8389
|
-
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8390
|
-
compileState.done(index, stats);
|
|
8391
|
-
});
|
|
8392
|
-
}) : (compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8393
|
-
compileState.reset(0);
|
|
8394
|
-
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8395
|
-
compileState.done(0, stats);
|
|
8396
|
-
}));
|
|
8397
|
-
let buildManager = new BuildManager({
|
|
8398
|
-
context,
|
|
8399
|
-
config,
|
|
8400
|
-
compiler,
|
|
8401
|
-
resolvedPort: port,
|
|
8402
|
-
onSocketConnect: (socket, token)=>{
|
|
8403
|
-
let callbacks = hotConnectCallbacks?.get(token);
|
|
8404
|
-
if (!callbacks?.size) return;
|
|
8405
|
-
let client = {
|
|
8406
|
-
send: createHotSend(socket)
|
|
8407
|
-
};
|
|
8408
|
-
for (let callback of [
|
|
8409
|
-
...callbacks
|
|
8410
|
-
])try {
|
|
8411
|
-
Promise.resolve(callback(client)).catch((error)=>{
|
|
8412
|
-
logger.error(error);
|
|
8413
|
-
});
|
|
8414
|
-
} catch (error) {
|
|
8415
|
-
logger.error(error);
|
|
8416
|
-
}
|
|
8417
|
-
}
|
|
8418
|
-
});
|
|
8419
|
-
return await buildManager.init(), buildManager;
|
|
8420
|
-
}, protocol = isHttps ? 'https' : 'http', urls = await getAddressUrls({
|
|
8059
|
+
}), hotConnectCallbacks = new Map(), protocol = isHttps ? 'https' : 'http', urls = await getAddressUrls({
|
|
8421
8060
|
protocol,
|
|
8422
8061
|
port,
|
|
8423
8062
|
host
|
|
@@ -8582,12 +8221,214 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8582
8221
|
})).filter((item)=>'function' == typeof item),
|
|
8583
8222
|
...setupPostCallbacks
|
|
8584
8223
|
];
|
|
8585
|
-
return runCompile ? context.hooks.onBeforeCreateCompiler.tapOnce(beforeCreateCompiler) : await beforeCreateCompiler(), state.buildManager = runCompile ? await
|
|
8224
|
+
return runCompile ? context.hooks.onBeforeCreateCompiler.tapOnce(beforeCreateCompiler) : await beforeCreateCompiler(), state.buildManager = runCompile ? await (async ()=>{
|
|
8225
|
+
let compiler = await createCompiler();
|
|
8226
|
+
if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
8227
|
+
context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
8228
|
+
getPublicPathFromCompiler(compiler)
|
|
8229
|
+
], config.server.base);
|
|
8230
|
+
let hookOptions = {
|
|
8231
|
+
name: 'rsbuild:environment-api',
|
|
8232
|
+
stage: -10000
|
|
8233
|
+
};
|
|
8234
|
+
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach((compiler, index)=>{
|
|
8235
|
+
compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8236
|
+
compileState.reset(index);
|
|
8237
|
+
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8238
|
+
compileState.done(index, stats);
|
|
8239
|
+
});
|
|
8240
|
+
}) : (compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8241
|
+
compileState.reset(0);
|
|
8242
|
+
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8243
|
+
compileState.done(0, stats);
|
|
8244
|
+
}));
|
|
8245
|
+
let buildManager = new BuildManager({
|
|
8246
|
+
context,
|
|
8247
|
+
config,
|
|
8248
|
+
compiler,
|
|
8249
|
+
resolvedPort: port,
|
|
8250
|
+
onSocketConnect: (socket, token)=>{
|
|
8251
|
+
let callbacks = hotConnectCallbacks?.get(token);
|
|
8252
|
+
if (!callbacks?.size) return;
|
|
8253
|
+
let client = {
|
|
8254
|
+
send: createHotSend(socket)
|
|
8255
|
+
};
|
|
8256
|
+
for (let callback of [
|
|
8257
|
+
...callbacks
|
|
8258
|
+
])try {
|
|
8259
|
+
Promise.resolve(callback(client)).catch((error)=>{
|
|
8260
|
+
logger.error(error);
|
|
8261
|
+
});
|
|
8262
|
+
} catch (error) {
|
|
8263
|
+
logger.error(error);
|
|
8264
|
+
}
|
|
8265
|
+
}
|
|
8266
|
+
});
|
|
8267
|
+
return await buildManager.init(), buildManager;
|
|
8268
|
+
})() : void 0, state.fileWatcher = await setupWatchFiles({
|
|
8586
8269
|
config,
|
|
8587
8270
|
logger,
|
|
8588
8271
|
buildManager: state.buildManager,
|
|
8589
8272
|
root: context.rootPath
|
|
8590
|
-
}), state.devMiddlewares = await
|
|
8273
|
+
}), state.devMiddlewares = await (async (options)=>{
|
|
8274
|
+
let { buildManager, context, devServer } = options, { middlewares } = devServer, { logger } = context;
|
|
8275
|
+
isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger));
|
|
8276
|
+
let { before, after } = ((config, devServer, logger)=>{
|
|
8277
|
+
let setupMiddlewares = config.dev.setupMiddlewares ? helpers_castArray(config.dev.setupMiddlewares) : [];
|
|
8278
|
+
setupMiddlewares.length && logger.warn('[rsbuild] `dev.setupMiddlewares` is deprecated, use `server.setup` instead');
|
|
8279
|
+
let serverOptions = pick(devServer, [
|
|
8280
|
+
'sockWrite',
|
|
8281
|
+
'environments'
|
|
8282
|
+
]), before = [], after = [];
|
|
8283
|
+
for (let handler of setupMiddlewares)handler({
|
|
8284
|
+
unshift: (...handlers)=>before.unshift(...handlers),
|
|
8285
|
+
push: (...handlers)=>after.push(...handlers)
|
|
8286
|
+
}, serverOptions);
|
|
8287
|
+
return {
|
|
8288
|
+
before,
|
|
8289
|
+
after
|
|
8290
|
+
};
|
|
8291
|
+
})(options.config, options.devServer, logger);
|
|
8292
|
+
for (let middleware of before)middlewares.use(middleware);
|
|
8293
|
+
let { onUpgrade } = await (async ({ config, buildManager, context, devServer, middlewares, postCallbacks })=>{
|
|
8294
|
+
let launchEditorHandlerPromise, upgradeEvents = [], { server } = config, { logger } = context, servedEnvironments = context.environmentList.filter((environment)=>isServingAssets(environment.config)), distPaths = [
|
|
8295
|
+
...new Set(servedEnvironments.map((environment)=>environment.distPath))
|
|
8296
|
+
];
|
|
8297
|
+
if (server.cors) {
|
|
8298
|
+
let { default: corsMiddleware } = await import("./cors.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/cors/2.8.6/abeeebb4dd5e2293f01aa9f4c01ff28ab19103cfa7a845442d515e16cf051f35/node_modules/cors/lib/index.js", 23));
|
|
8299
|
+
middlewares.use(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
8300
|
+
}
|
|
8301
|
+
let { headers } = server;
|
|
8302
|
+
if (headers && middlewares.use((_req, res, next)=>{
|
|
8303
|
+
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
8304
|
+
next();
|
|
8305
|
+
}), server.proxy) {
|
|
8306
|
+
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy, logger);
|
|
8307
|
+
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.use(middleware);
|
|
8308
|
+
}
|
|
8309
|
+
let { compress } = server;
|
|
8310
|
+
if (compress && middlewares.use(gzipMiddleware_gzipMiddleware('object' == typeof compress ? compress : void 0)), 'dev' === context.action && buildManager) {
|
|
8311
|
+
let { compiler } = buildManager;
|
|
8312
|
+
(compiler_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>childCompiler.options.lazyCompilation) : compiler.options.lazyCompilation) && middlewares.use(core_rspack.lazyCompilationMiddleware(compiler));
|
|
8313
|
+
}
|
|
8314
|
+
server.base && '/' !== server.base && middlewares.use(getBaseUrlMiddleware({
|
|
8315
|
+
base: server.base
|
|
8316
|
+
})), middlewares.use('/__open-in-editor', async (req, res, next)=>{
|
|
8317
|
+
try {
|
|
8318
|
+
(await (launchEditorHandlerPromise ??= (async ()=>{
|
|
8319
|
+
let { default: launchEditorMiddleware } = await import("./launch-editor-middleware.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/launch-editor-middleware/2.14.2/46c81dbb0ad4cd8f776539a7cfaa5ea6144007363b919f05970ca6624282dcce/node_modules/launch-editor-middleware/index.js", 23));
|
|
8320
|
+
return launchEditorMiddleware();
|
|
8321
|
+
})()))(req, res, next);
|
|
8322
|
+
} catch (err) {
|
|
8323
|
+
next(err);
|
|
8324
|
+
}
|
|
8325
|
+
}), middlewares.use((({ environments, logger })=>async function viewingServedFilesMiddleware(req, res, next) {
|
|
8326
|
+
if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
|
|
8327
|
+
res.writeHead(200, {
|
|
8328
|
+
'Content-Type': 'text/html; charset=utf-8'
|
|
8329
|
+
}), res.write(`<!DOCTYPE html>
|
|
8330
|
+
<html>
|
|
8331
|
+
<head>
|
|
8332
|
+
<meta charset="utf-8"/>
|
|
8333
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8334
|
+
<style>
|
|
8335
|
+
body {
|
|
8336
|
+
margin: 0;
|
|
8337
|
+
color: #f6f7f9;
|
|
8338
|
+
padding: 32px 40px;
|
|
8339
|
+
line-height: 1.8;
|
|
8340
|
+
min-height: 100vh;
|
|
8341
|
+
background-image: linear-gradient(#020917, #101725);
|
|
8342
|
+
font-family: ui-sans-serif,system-ui,sans-serif;
|
|
8343
|
+
}
|
|
8344
|
+
h1, h2 {
|
|
8345
|
+
font-weight: 500;
|
|
8346
|
+
}
|
|
8347
|
+
h1 {
|
|
8348
|
+
margin: 0;
|
|
8349
|
+
font-size: 36px;
|
|
8350
|
+
}
|
|
8351
|
+
h2 {
|
|
8352
|
+
font-size: 20px;
|
|
8353
|
+
margin: 24px 0 16px;
|
|
8354
|
+
}
|
|
8355
|
+
ul {
|
|
8356
|
+
margin: 0;
|
|
8357
|
+
padding-left: 16px;
|
|
8358
|
+
}
|
|
8359
|
+
a {
|
|
8360
|
+
color: #58c4dc;
|
|
8361
|
+
text-decoration: none;
|
|
8362
|
+
}
|
|
8363
|
+
a:hover {
|
|
8364
|
+
text-decoration: underline;
|
|
8365
|
+
}
|
|
8366
|
+
</style>
|
|
8367
|
+
</head>
|
|
8368
|
+
<body>
|
|
8369
|
+
<h1>Assets Report</h1>
|
|
8370
|
+
</body>
|
|
8371
|
+
</html>`);
|
|
8372
|
+
try {
|
|
8373
|
+
for(let key in environments){
|
|
8374
|
+
res.write(`<h2>Environment: ${key}</h2>`);
|
|
8375
|
+
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetNames(stats.compilation);
|
|
8376
|
+
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset}">${asset}</a></li>`);
|
|
8377
|
+
res.write(list?.join('')), res.write('</ul>');
|
|
8378
|
+
}
|
|
8379
|
+
res.end('</body></html>');
|
|
8380
|
+
} catch (err) {
|
|
8381
|
+
logger.error(err), res.writeHead(500), res.end('Failed to list the files');
|
|
8382
|
+
}
|
|
8383
|
+
})({
|
|
8384
|
+
environments: pick(devServer.environments, servedEnvironments.map((environment)=>environment.name)),
|
|
8385
|
+
logger
|
|
8386
|
+
})), buildManager && (middlewares.use(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.use(function hotUpdateJsonFallbackMiddleware(req, res, next) {
|
|
8387
|
+
let url = req.url;
|
|
8388
|
+
if (!url || 'OPTIONS' === req.method) return void next();
|
|
8389
|
+
let queryIndex = url.indexOf('?'), end = -1 === queryIndex ? url.length : queryIndex;
|
|
8390
|
+
url.endsWith('.hot-update.json', end) || url.endsWith('.hot-update.json.mjs', end) ? notFoundMiddleware(req, res, next) : next();
|
|
8391
|
+
})), buildManager && middlewares.use(getHtmlCompletionMiddleware({
|
|
8392
|
+
assetsMiddleware: buildManager.assetsMiddleware,
|
|
8393
|
+
distPaths,
|
|
8394
|
+
outputFileSystem: buildManager.outputFileSystem
|
|
8395
|
+
}));
|
|
8396
|
+
let publicDirPaths = getPublicDirPaths(config);
|
|
8397
|
+
if (publicDirPaths.length) {
|
|
8398
|
+
let { default: sirv } = await import("./sirv.js");
|
|
8399
|
+
for (let name of publicDirPaths){
|
|
8400
|
+
let sirvMiddleware = sirv(name, {
|
|
8401
|
+
etag: !0,
|
|
8402
|
+
dev: !0
|
|
8403
|
+
});
|
|
8404
|
+
middlewares.use(function publicDirMiddleware(req, res, next) {
|
|
8405
|
+
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? next() : sirvMiddleware(req, res, next);
|
|
8406
|
+
});
|
|
8407
|
+
}
|
|
8408
|
+
}
|
|
8409
|
+
for (let callback of postCallbacks)await callback();
|
|
8410
|
+
return server.historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === server.historyApiFallback ? {} : server.historyApiFallback)), buildManager?.assetsMiddleware && middlewares.use(buildManager.assetsMiddleware)), buildManager && server.htmlFallback && middlewares.use(getHtmlFallbackMiddleware({
|
|
8411
|
+
assetsMiddleware: buildManager.assetsMiddleware,
|
|
8412
|
+
distPaths,
|
|
8413
|
+
logger,
|
|
8414
|
+
outputFileSystem: buildManager.outputFileSystem
|
|
8415
|
+
})), middlewares.use(faviconFallbackMiddleware), {
|
|
8416
|
+
onUpgrade: (...args)=>{
|
|
8417
|
+
for (let cb of upgradeEvents)cb(...args);
|
|
8418
|
+
}
|
|
8419
|
+
};
|
|
8420
|
+
})({
|
|
8421
|
+
...options,
|
|
8422
|
+
middlewares
|
|
8423
|
+
});
|
|
8424
|
+
for (let middleware of after)middlewares.use(middleware);
|
|
8425
|
+
return {
|
|
8426
|
+
close: async ()=>{
|
|
8427
|
+
await buildManager?.close();
|
|
8428
|
+
},
|
|
8429
|
+
onUpgrade
|
|
8430
|
+
};
|
|
8431
|
+
})({
|
|
8591
8432
|
buildManager: state.buildManager,
|
|
8592
8433
|
config,
|
|
8593
8434
|
devServer,
|
|
@@ -8649,12 +8490,14 @@ async function startPreviewServer(context, config, { getPortSilently } = {}) {
|
|
|
8649
8490
|
server: previewServer,
|
|
8650
8491
|
environments: context.environments
|
|
8651
8492
|
});
|
|
8652
|
-
let
|
|
8493
|
+
let servedEnvironments = context.environmentList.filter((environment)=>isServingAssets(environment.config)), assetsMiddleware = createAssetsMiddleware(context, {
|
|
8653
8494
|
waitForAssets: (callback)=>callback(),
|
|
8654
8495
|
waitForBuild: (callback)=>callback()
|
|
8655
8496
|
}, node_fs), htmlMiddlewareOptions = {
|
|
8656
8497
|
assetsMiddleware,
|
|
8657
|
-
distPaths:
|
|
8498
|
+
distPaths: [
|
|
8499
|
+
...new Set(servedEnvironments.map((environment)=>environment.distPath))
|
|
8500
|
+
],
|
|
8658
8501
|
outputFileSystem: node_fs
|
|
8659
8502
|
};
|
|
8660
8503
|
if (isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger)), cors) {
|
|
@@ -8834,7 +8677,10 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8834
8677
|
api.modifyBundlerChain(async (chain, { environment, env })=>{
|
|
8835
8678
|
let { config } = environment, { buildCache = !1 } = config.performance;
|
|
8836
8679
|
if (!1 === buildCache) return;
|
|
8837
|
-
|
|
8680
|
+
'new' === process.env.RSBUILD_E2E_CACHE && chain.experiments({
|
|
8681
|
+
...chain.get('experiments'),
|
|
8682
|
+
newCache: !0
|
|
8683
|
+
}), cacheEnabled = !0;
|
|
8838
8684
|
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context, environment, cacheConfig.buildDependencies), cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${await helpers_hash(JSON.stringify(cacheConfig.cacheDigest))}` : `${environment.name}-${env}`;
|
|
8839
8685
|
chain.cache({
|
|
8840
8686
|
type: 'persistent',
|
|
@@ -8877,9 +8723,9 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8877
8723
|
{
|
|
8878
8724
|
name: 'rsbuild:output',
|
|
8879
8725
|
setup (api) {
|
|
8880
|
-
api.modifyBundlerChain((chain, { CHAIN_ID, isDev, isProd, isServer, environment, rspack, target })=>{
|
|
8726
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isDev, isProd, isServer, environment, rspack, target })=>{
|
|
8881
8727
|
var jsAsync;
|
|
8882
|
-
let { distPath, config } = environment, publicPath = getPublicPath({
|
|
8728
|
+
let { distPath, config } = environment, publicPath = await getPublicPath({
|
|
8883
8729
|
config,
|
|
8884
8730
|
isDev,
|
|
8885
8731
|
context: api.context
|
|
@@ -9416,7 +9262,45 @@ try {
|
|
|
9416
9262
|
skipMain: !emitCss
|
|
9417
9263
|
});
|
|
9418
9264
|
}
|
|
9419
|
-
let postcssLoaderOptions = await
|
|
9265
|
+
let postcssLoaderOptions = await (async ({ config, root, postcssrcCache })=>{
|
|
9266
|
+
let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
|
|
9267
|
+
userOptions.plugins ||= [];
|
|
9268
|
+
let defaultOptions = {
|
|
9269
|
+
implementation: getCompiledPath('postcss'),
|
|
9270
|
+
postcssOptions: userOptions,
|
|
9271
|
+
sourceMap: getCSSSourceMap(config)
|
|
9272
|
+
}, finalOptions = await reduceConfigsWithContext({
|
|
9273
|
+
initial: defaultOptions,
|
|
9274
|
+
config: config.tools.postcss,
|
|
9275
|
+
ctx: {
|
|
9276
|
+
addPlugins (plugins, options = {}) {
|
|
9277
|
+
let { order = 'post' } = options, list = helpers_castArray(plugins);
|
|
9278
|
+
'pre' === order ? extraPlugins.unshift(...list) : extraPlugins.push(...list);
|
|
9279
|
+
}
|
|
9280
|
+
}
|
|
9281
|
+
});
|
|
9282
|
+
finalOptions.postcssOptions ||= {};
|
|
9283
|
+
let updatePostcssOptions = (options)=>(options.plugins ||= [], extraPlugins.length && options.plugins.push(...extraPlugins), options.plugins = options.plugins.map((plugin)=>'function' == typeof plugin && 'postcss' in plugin && plugin.postcss ? plugin() : plugin), options.config = !1, options), { postcssOptions } = finalOptions;
|
|
9284
|
+
if ('function' == typeof postcssOptions) {
|
|
9285
|
+
let postcssOptionsWrapper = (loaderContext)=>{
|
|
9286
|
+
let options = postcssOptions(loaderContext);
|
|
9287
|
+
if ('object' != typeof options || null === options) throw Error(`${color.dim('[rsbuild:css]')} \`postcssOptions\` function must return a PostCSSOptions object, got ${color.yellow(typeof options)}.`);
|
|
9288
|
+
return updatePostcssOptions({
|
|
9289
|
+
...userOptions,
|
|
9290
|
+
...options,
|
|
9291
|
+
plugins: [
|
|
9292
|
+
...userOptions.plugins || [],
|
|
9293
|
+
...options.plugins || []
|
|
9294
|
+
]
|
|
9295
|
+
});
|
|
9296
|
+
};
|
|
9297
|
+
return postcssOptionsWrapper.config = !1, {
|
|
9298
|
+
...finalOptions,
|
|
9299
|
+
postcssOptions: postcssOptionsWrapper
|
|
9300
|
+
};
|
|
9301
|
+
}
|
|
9302
|
+
return finalOptions.postcssOptions = updatePostcssOptions(postcssOptions), finalOptions;
|
|
9303
|
+
})({
|
|
9420
9304
|
config,
|
|
9421
9305
|
root: api.context.rootPath,
|
|
9422
9306
|
postcssrcCache
|
|
@@ -9430,7 +9314,37 @@ try {
|
|
|
9430
9314
|
skipMain: !emitCss
|
|
9431
9315
|
});
|
|
9432
9316
|
}
|
|
9433
|
-
let localIdentName = config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), cssLoaderOptions = await
|
|
9317
|
+
let localIdentName = config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), cssLoaderOptions = await (async ({ config, localIdentName, emitCss })=>{
|
|
9318
|
+
let { cssModules } = config.output, defaultOptions = {
|
|
9319
|
+
modules: {
|
|
9320
|
+
...cssModules,
|
|
9321
|
+
localIdentName
|
|
9322
|
+
},
|
|
9323
|
+
sourceMap: getCSSSourceMap(config)
|
|
9324
|
+
};
|
|
9325
|
+
return ((options, exportOnlyLocals)=>{
|
|
9326
|
+
if (options.modules && exportOnlyLocals) {
|
|
9327
|
+
let { modules } = options;
|
|
9328
|
+
return modules = !0 === modules ? {
|
|
9329
|
+
exportOnlyLocals: !0
|
|
9330
|
+
} : 'string' == typeof modules ? {
|
|
9331
|
+
mode: modules,
|
|
9332
|
+
exportOnlyLocals: !0
|
|
9333
|
+
} : {
|
|
9334
|
+
...modules,
|
|
9335
|
+
exportOnlyLocals: !0
|
|
9336
|
+
}, {
|
|
9337
|
+
...options,
|
|
9338
|
+
modules
|
|
9339
|
+
};
|
|
9340
|
+
}
|
|
9341
|
+
return options;
|
|
9342
|
+
})(await reduceConfigs({
|
|
9343
|
+
initial: defaultOptions,
|
|
9344
|
+
config: config.tools.cssLoader,
|
|
9345
|
+
mergeFn: cjs_0_default()
|
|
9346
|
+
}), !emitCss);
|
|
9347
|
+
})({
|
|
9434
9348
|
config,
|
|
9435
9349
|
localIdentName,
|
|
9436
9350
|
emitCss
|
|
@@ -9867,7 +9781,7 @@ try {
|
|
|
9867
9781
|
fileName: manifestOptions.filename,
|
|
9868
9782
|
filter,
|
|
9869
9783
|
writeToFileEmit: isDev && !0 !== writeToDisk,
|
|
9870
|
-
generate: (_seed, files, entries, { compilation })=>{
|
|
9784
|
+
generate: (0, (_seed, files, entries, { compilation })=>{
|
|
9871
9785
|
let chunkEntries = new Map(), filePathByName = new Map(), licenseMap = new Map(), publicPath = getPublicPathFromCompiler(compilation), integrity = {}, allFiles = files.map((file)=>{
|
|
9872
9786
|
if (filePathByName.has(file.name) || filePathByName.set(file.name, file.path), file.integrity && (integrity[file.path] = file.integrity), file.chunk) for (let entryName of recursiveChunkEntryNames(file.chunk)){
|
|
9873
9787
|
let chunkFiles = chunkEntries.get(entryName);
|
|
@@ -9923,7 +9837,7 @@ try {
|
|
|
9923
9837
|
throw Error(`${color.dim('[rsbuild:manifest]')} \`manifest.generate\` function must return a valid manifest object.`);
|
|
9924
9838
|
}
|
|
9925
9839
|
return environment.manifest = manifestData, manifestData;
|
|
9926
|
-
}
|
|
9840
|
+
})
|
|
9927
9841
|
};
|
|
9928
9842
|
manifestOptions.prefix || (pluginOptions.publicPath = ''), chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
|
|
9929
9843
|
pluginOptions
|
|
@@ -10068,6 +9982,14 @@ async function createRsbuild(options = {}) {
|
|
|
10068
9982
|
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
10069
9983
|
}) : null, configOrFactory = options.config ?? options.rsbuildConfig, config = isFunction(configOrFactory) ? await configOrFactory() : configOrFactory;
|
|
10070
9984
|
isLoadConfigResult(config) && (loadConfigResult = config, config = config.content), config ||= {};
|
|
9985
|
+
let e2eCache = process.env.RSBUILD_E2E_CACHE;
|
|
9986
|
+
('new' === e2eCache || 'legacy' === e2eCache) && config.performance?.buildCache === void 0 && (config = {
|
|
9987
|
+
...config,
|
|
9988
|
+
performance: {
|
|
9989
|
+
...config.performance,
|
|
9990
|
+
buildCache: !0
|
|
9991
|
+
}
|
|
9992
|
+
});
|
|
10071
9993
|
let logger = config.customLogger ?? logger_createLogger({
|
|
10072
9994
|
...src_logger.options,
|
|
10073
9995
|
level: src_logger.level
|
|
@@ -10089,82 +10011,175 @@ async function createRsbuild(options = {}) {
|
|
|
10089
10011
|
context,
|
|
10090
10012
|
pluginManager,
|
|
10091
10013
|
rsbuildOptions: resolvedOptions
|
|
10092
|
-
})).compiler),
|
|
10093
|
-
context.action = 'preview', process.env.NODE_ENV || setNodeEnv('production');
|
|
10094
|
-
let config = await initRsbuildConfig({
|
|
10095
|
-
context,
|
|
10096
|
-
pluginManager
|
|
10097
|
-
}), { distPath } = context, { checkDistDir = !0 } = options;
|
|
10098
|
-
if (checkDistDir) {
|
|
10099
|
-
if (!existsSync(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
10100
|
-
if (isEmptyDir(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} is empty, please build the project before previewing.`);
|
|
10101
|
-
}
|
|
10102
|
-
return startPreviewServer(context, config, options);
|
|
10103
|
-
}, build = async (options = {})=>(context.action = 'build', process.env.NODE_ENV || setNodeEnv('production'), build_build({
|
|
10104
|
-
context,
|
|
10105
|
-
pluginManager,
|
|
10106
|
-
rsbuildOptions: resolvedOptions
|
|
10107
|
-
}, {
|
|
10108
|
-
...options
|
|
10109
|
-
})), startDevServer = async (options = {})=>{
|
|
10110
|
-
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10111
|
-
let config = await initRsbuildConfig({
|
|
10112
|
-
context,
|
|
10113
|
-
pluginManager
|
|
10114
|
-
});
|
|
10115
|
-
return (await devServer_createDevServer({
|
|
10116
|
-
context,
|
|
10117
|
-
pluginManager,
|
|
10118
|
-
rsbuildOptions: resolvedOptions
|
|
10119
|
-
}, createCompiler, config, options)).listen();
|
|
10120
|
-
}, createDevServer = async (options)=>{
|
|
10121
|
-
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10122
|
-
let config = await initRsbuildConfig({
|
|
10123
|
-
context,
|
|
10124
|
-
pluginManager
|
|
10125
|
-
});
|
|
10126
|
-
return devServer_createDevServer({
|
|
10127
|
-
context,
|
|
10128
|
-
pluginManager,
|
|
10129
|
-
rsbuildOptions: resolvedOptions
|
|
10130
|
-
}, createCompiler, config, options);
|
|
10131
|
-
}, initAction = (mode = config.mode)=>{
|
|
10014
|
+
})).compiler), initAction = (mode = config.mode)=>{
|
|
10132
10015
|
context.action || (context.action = 'development' === mode ? 'dev' : 'build');
|
|
10133
|
-
}, inspectConfig = async (inspectOptions = {})=>{
|
|
10134
|
-
inspectOptions.mode ? setNodeEnv(inspectOptions.mode) : process.env.NODE_ENV || setNodeEnv('development'), initAction(config.mode ?? (process.env.NODE_ENV || ''));
|
|
10135
|
-
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10136
|
-
context,
|
|
10137
|
-
pluginManager,
|
|
10138
|
-
rsbuildOptions: resolvedOptions
|
|
10139
|
-
});
|
|
10140
|
-
return inspectConfig_inspectConfig({
|
|
10141
|
-
context,
|
|
10142
|
-
pluginManager,
|
|
10143
|
-
rsbuildOptions: resolvedOptions,
|
|
10144
|
-
inspectOptions,
|
|
10145
|
-
bundlerConfigs: rspackConfigs
|
|
10146
|
-
});
|
|
10147
|
-
}, initConfigs = async (options)=>{
|
|
10148
|
-
if (context.action && options?.action && context.action !== options.action) throw Error(`\
|
|
10149
|
-
[rsbuild] initConfigs() can only be called with the same action type.
|
|
10150
|
-
- Expected: ${context.action}
|
|
10151
|
-
- Actual: ${options?.action}`);
|
|
10152
|
-
options?.action && (context.action = options.action);
|
|
10153
|
-
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10154
|
-
context,
|
|
10155
|
-
pluginManager,
|
|
10156
|
-
rsbuildOptions: resolvedOptions
|
|
10157
|
-
});
|
|
10158
|
-
return rspackConfigs;
|
|
10159
10016
|
}, rsbuild = {
|
|
10160
10017
|
logger: context.logger,
|
|
10161
|
-
build,
|
|
10162
|
-
|
|
10163
|
-
|
|
10018
|
+
build: async (options = {})=>(context.action = 'build', process.env.NODE_ENV || setNodeEnv('production'), (async (initOptions, buildOptions = {})=>{
|
|
10019
|
+
let stats, closeCompiler, closingPromise, unregisterRestart, restartWatcher, { watch } = buildOptions, { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
10020
|
+
if ((({ context, isWatch, compiler, rspackConfigs, MultiStatsCtor })=>{
|
|
10021
|
+
let isFirstCompile = !0, { environmentList } = context;
|
|
10022
|
+
onBeforeCompile({
|
|
10023
|
+
compiler,
|
|
10024
|
+
beforeCompile: async ()=>context.hooks.onBeforeBuild.callBatch({
|
|
10025
|
+
bundlerConfigs: rspackConfigs,
|
|
10026
|
+
environments: context.environments,
|
|
10027
|
+
isWatch,
|
|
10028
|
+
isFirstCompile
|
|
10029
|
+
}),
|
|
10030
|
+
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
10031
|
+
let environment = environmentList[buildIndex];
|
|
10032
|
+
return context.hooks.onBeforeEnvironmentCompile.callBatch({
|
|
10033
|
+
environment: environment.name,
|
|
10034
|
+
args: [
|
|
10035
|
+
{
|
|
10036
|
+
bundlerConfig: rspackConfigs[buildIndex],
|
|
10037
|
+
environment,
|
|
10038
|
+
isWatch,
|
|
10039
|
+
isFirstCompile
|
|
10040
|
+
}
|
|
10041
|
+
]
|
|
10042
|
+
});
|
|
10043
|
+
},
|
|
10044
|
+
isWatch
|
|
10045
|
+
}), onCompileDone({
|
|
10046
|
+
compiler,
|
|
10047
|
+
onDone: async (stats)=>{
|
|
10048
|
+
let shouldLogWatching = isWatch && isFirstCompile, promise = context.hooks.onAfterBuild.callBatch({
|
|
10049
|
+
isFirstCompile,
|
|
10050
|
+
stats,
|
|
10051
|
+
environments: context.environments,
|
|
10052
|
+
isWatch
|
|
10053
|
+
});
|
|
10054
|
+
isFirstCompile = !1, await promise, shouldLogWatching && context.logger.info('watching for changes...');
|
|
10055
|
+
},
|
|
10056
|
+
onEnvironmentDone: async (index, stats)=>{
|
|
10057
|
+
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
10058
|
+
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
10059
|
+
environment: environment.name,
|
|
10060
|
+
args: [
|
|
10061
|
+
{
|
|
10062
|
+
isFirstCompile,
|
|
10063
|
+
stats,
|
|
10064
|
+
environment,
|
|
10065
|
+
isWatch,
|
|
10066
|
+
time
|
|
10067
|
+
}
|
|
10068
|
+
]
|
|
10069
|
+
});
|
|
10070
|
+
},
|
|
10071
|
+
MultiStatsCtor
|
|
10072
|
+
});
|
|
10073
|
+
})({
|
|
10074
|
+
context,
|
|
10075
|
+
rspackConfigs,
|
|
10076
|
+
compiler,
|
|
10077
|
+
isWatch: !!watch,
|
|
10078
|
+
MultiStatsCtor: core_rspack.MultiStats
|
|
10079
|
+
}), watch) {
|
|
10080
|
+
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
10081
|
+
compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
10082
|
+
err && logger.error(err);
|
|
10083
|
+
}), closeCompiler = ()=>new Promise((resolve)=>{
|
|
10084
|
+
compiler.close(()=>{
|
|
10085
|
+
resolve();
|
|
10086
|
+
});
|
|
10087
|
+
});
|
|
10088
|
+
} else stats = await new Promise((resolve, reject)=>{
|
|
10089
|
+
compiler.run((err, stats)=>{
|
|
10090
|
+
compiler.close((closeErr)=>{
|
|
10091
|
+
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(stats);
|
|
10092
|
+
});
|
|
10093
|
+
});
|
|
10094
|
+
});
|
|
10095
|
+
let closeBuild = ()=>closingPromise ||= (async ()=>{
|
|
10096
|
+
unregisterRestart?.(), unregisterRestart = void 0, await context.hooks.onCloseBuild.callBatch(), await closeCompiler?.();
|
|
10097
|
+
})();
|
|
10098
|
+
return watch && (unregisterRestart = context.restartManager.registerCleanup(closeBuild), restartWatcher = watchFilesForRestart({
|
|
10099
|
+
watchFiles: context.normalizedConfig.dev.watchFiles,
|
|
10100
|
+
context,
|
|
10101
|
+
restartContext: {
|
|
10102
|
+
action: 'build',
|
|
10103
|
+
options: buildOptions
|
|
10104
|
+
}
|
|
10105
|
+
})), {
|
|
10106
|
+
stats,
|
|
10107
|
+
close: async ()=>{
|
|
10108
|
+
await restartWatcher?.close(), await closeBuild();
|
|
10109
|
+
}
|
|
10110
|
+
};
|
|
10111
|
+
})({
|
|
10112
|
+
context,
|
|
10113
|
+
pluginManager,
|
|
10114
|
+
rsbuildOptions: resolvedOptions
|
|
10115
|
+
}, {
|
|
10116
|
+
...options
|
|
10117
|
+
})),
|
|
10118
|
+
preview: async (options = {})=>{
|
|
10119
|
+
context.action = 'preview', process.env.NODE_ENV || setNodeEnv('production');
|
|
10120
|
+
let config = await initRsbuildConfig({
|
|
10121
|
+
context,
|
|
10122
|
+
pluginManager
|
|
10123
|
+
}), { distPath } = context, { checkDistDir = !0 } = options;
|
|
10124
|
+
if (checkDistDir) {
|
|
10125
|
+
if (!existsSync(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
10126
|
+
if (isEmptyDir(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} is empty, please build the project before previewing.`);
|
|
10127
|
+
}
|
|
10128
|
+
return startPreviewServer(context, config, options);
|
|
10129
|
+
},
|
|
10130
|
+
startDevServer: async (options = {})=>{
|
|
10131
|
+
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10132
|
+
let config = await initRsbuildConfig({
|
|
10133
|
+
context,
|
|
10134
|
+
pluginManager
|
|
10135
|
+
});
|
|
10136
|
+
return (await devServer_createDevServer({
|
|
10137
|
+
context,
|
|
10138
|
+
pluginManager,
|
|
10139
|
+
rsbuildOptions: resolvedOptions
|
|
10140
|
+
}, createCompiler, config, options)).listen();
|
|
10141
|
+
},
|
|
10164
10142
|
createCompiler,
|
|
10165
|
-
createDevServer
|
|
10166
|
-
|
|
10167
|
-
|
|
10143
|
+
createDevServer: async (options)=>{
|
|
10144
|
+
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10145
|
+
let config = await initRsbuildConfig({
|
|
10146
|
+
context,
|
|
10147
|
+
pluginManager
|
|
10148
|
+
});
|
|
10149
|
+
return devServer_createDevServer({
|
|
10150
|
+
context,
|
|
10151
|
+
pluginManager,
|
|
10152
|
+
rsbuildOptions: resolvedOptions
|
|
10153
|
+
}, createCompiler, config, options);
|
|
10154
|
+
},
|
|
10155
|
+
inspectConfig: async (inspectOptions = {})=>{
|
|
10156
|
+
inspectOptions.mode ? setNodeEnv(inspectOptions.mode) : process.env.NODE_ENV || setNodeEnv('development'), initAction(config.mode ?? (process.env.NODE_ENV || ''));
|
|
10157
|
+
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10158
|
+
context,
|
|
10159
|
+
pluginManager,
|
|
10160
|
+
rsbuildOptions: resolvedOptions
|
|
10161
|
+
});
|
|
10162
|
+
return inspectConfig_inspectConfig({
|
|
10163
|
+
context,
|
|
10164
|
+
pluginManager,
|
|
10165
|
+
rsbuildOptions: resolvedOptions,
|
|
10166
|
+
inspectOptions,
|
|
10167
|
+
bundlerConfigs: rspackConfigs
|
|
10168
|
+
});
|
|
10169
|
+
},
|
|
10170
|
+
initConfigs: async (options)=>{
|
|
10171
|
+
if (context.action && options?.action && context.action !== options.action) throw Error(`\
|
|
10172
|
+
[rsbuild] initConfigs() can only be called with the same action type.
|
|
10173
|
+
- Expected: ${context.action}
|
|
10174
|
+
- Actual: ${options?.action}`);
|
|
10175
|
+
options?.action && (context.action = options.action);
|
|
10176
|
+
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10177
|
+
context,
|
|
10178
|
+
pluginManager,
|
|
10179
|
+
rsbuildOptions: resolvedOptions
|
|
10180
|
+
});
|
|
10181
|
+
return rspackConfigs;
|
|
10182
|
+
},
|
|
10168
10183
|
...pick(pluginManager, [
|
|
10169
10184
|
'addPlugins',
|
|
10170
10185
|
'getPlugins',
|
|
@@ -10227,50 +10242,11 @@ let canReadExport = (module)=>null !== module && ('object' == typeof module || '
|
|
|
10227
10242
|
return ()=>promise ??= importer().catch((error)=>{
|
|
10228
10243
|
throw promise = void 0, error;
|
|
10229
10244
|
});
|
|
10230
|
-
}, getJiti = cachedImport(()=>import("../compiled/jiti/lib/jiti.mjs")),
|
|
10231
|
-
let createJiti;
|
|
10232
|
-
try {
|
|
10233
|
-
({ createJiti } = await getJiti());
|
|
10234
|
-
} catch (error) {
|
|
10235
|
-
throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
|
|
10236
|
-
cause: error
|
|
10237
|
-
});
|
|
10238
|
-
}
|
|
10239
|
-
let jiti = createJiti(configPath, {
|
|
10240
|
-
moduleCache: !fresh,
|
|
10241
|
-
interopDefault: !0,
|
|
10242
|
-
nativeModules: [
|
|
10243
|
-
"typescript"
|
|
10244
|
-
]
|
|
10245
|
-
});
|
|
10246
|
-
return 'default' === exportName ? {
|
|
10247
|
-
configExport: await jiti.import(configPath, {
|
|
10248
|
-
default: !0
|
|
10249
|
-
}),
|
|
10250
|
-
dependencies: []
|
|
10251
|
-
} : {
|
|
10252
|
-
configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
|
|
10253
|
-
dependencies: []
|
|
10254
|
-
};
|
|
10255
|
-
}, CONFIG_META = Symbol.for('@rstackjs/load-config/meta');
|
|
10245
|
+
}, getJiti = cachedImport(()=>import("../compiled/jiti/lib/jiti.mjs")), CONFIG_META = Symbol.for('@rstackjs/load-config/meta');
|
|
10256
10246
|
function getConfigMeta(config) {
|
|
10257
10247
|
if (null !== config && 'object' == typeof config && Object.hasOwn(config, CONFIG_META)) return config[CONFIG_META];
|
|
10258
10248
|
}
|
|
10259
|
-
let getFreshImport = cachedImport(()=>import("./freshImport.js")), JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)
|
|
10260
|
-
let configFileURL = pathToFileURL(configPath).href;
|
|
10261
|
-
if (!fresh) return {
|
|
10262
|
-
configModule: await import(configFileURL),
|
|
10263
|
-
dependencies: []
|
|
10264
|
-
};
|
|
10265
|
-
let { freshImport } = await getFreshImport(), freshImportResult = await freshImport(configFileURL);
|
|
10266
|
-
return freshImportResult ? {
|
|
10267
|
-
configModule: freshImportResult.result,
|
|
10268
|
-
dependencies: freshImportResult.dependencies.sort()
|
|
10269
|
-
} : {
|
|
10270
|
-
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
10271
|
-
dependencies: []
|
|
10272
|
-
};
|
|
10273
|
-
};
|
|
10249
|
+
let getFreshImport = cachedImport(()=>import("./freshImport.js")), JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/;
|
|
10274
10250
|
async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = [], loader = 'auto', exportName = 'default', configParams = [], fresh = !1 } = {}) {
|
|
10275
10251
|
let loadedConfig, content;
|
|
10276
10252
|
if (!path && 0 === configFileNames.length) throw Error('Either `path` or at least one `configFileNames` entry must be provided.');
|
|
@@ -10294,7 +10270,21 @@ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = []
|
|
|
10294
10270
|
if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || JS_CONFIG_REGEXP.test(configPath)) {
|
|
10295
10271
|
let result;
|
|
10296
10272
|
try {
|
|
10297
|
-
result = await
|
|
10273
|
+
result = await (async (configPath, fresh)=>{
|
|
10274
|
+
let configFileURL = pathToFileURL(configPath).href;
|
|
10275
|
+
if (!fresh) return {
|
|
10276
|
+
configModule: await import(configFileURL),
|
|
10277
|
+
dependencies: []
|
|
10278
|
+
};
|
|
10279
|
+
let { freshImport } = await getFreshImport(), freshImportResult = await freshImport(configFileURL);
|
|
10280
|
+
return freshImportResult ? {
|
|
10281
|
+
configModule: freshImportResult.result,
|
|
10282
|
+
dependencies: freshImportResult.dependencies.sort()
|
|
10283
|
+
} : {
|
|
10284
|
+
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
10285
|
+
dependencies: []
|
|
10286
|
+
};
|
|
10287
|
+
})(configPath, fresh);
|
|
10298
10288
|
} catch (err) {
|
|
10299
10289
|
if ('native' === loader) throw err;
|
|
10300
10290
|
}
|
|
@@ -10303,7 +10293,32 @@ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = []
|
|
|
10303
10293
|
dependencies: result.dependencies
|
|
10304
10294
|
});
|
|
10305
10295
|
}
|
|
10306
|
-
loadedConfig || (loadedConfig = await
|
|
10296
|
+
loadedConfig || (loadedConfig = await (async (configPath, exportName, fresh)=>{
|
|
10297
|
+
let createJiti;
|
|
10298
|
+
try {
|
|
10299
|
+
({ createJiti } = await getJiti());
|
|
10300
|
+
} catch (error) {
|
|
10301
|
+
throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
|
|
10302
|
+
cause: error
|
|
10303
|
+
});
|
|
10304
|
+
}
|
|
10305
|
+
let jiti = createJiti(configPath, {
|
|
10306
|
+
moduleCache: !fresh,
|
|
10307
|
+
interopDefault: !0,
|
|
10308
|
+
nativeModules: [
|
|
10309
|
+
"typescript"
|
|
10310
|
+
]
|
|
10311
|
+
});
|
|
10312
|
+
return 'default' === exportName ? {
|
|
10313
|
+
configExport: await jiti.import(configPath, {
|
|
10314
|
+
default: !0
|
|
10315
|
+
}),
|
|
10316
|
+
dependencies: []
|
|
10317
|
+
} : {
|
|
10318
|
+
configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
|
|
10319
|
+
dependencies: []
|
|
10320
|
+
};
|
|
10321
|
+
})(configPath, exportName, fresh));
|
|
10307
10322
|
let { configExport, dependencies } = loadedConfig;
|
|
10308
10323
|
if ('function' == typeof configExport) {
|
|
10309
10324
|
let result = await configExport(...configParams);
|
|
@@ -10362,30 +10377,6 @@ let cliState = {
|
|
|
10362
10377
|
options: {}
|
|
10363
10378
|
}, initCliAction = (command, options)=>{
|
|
10364
10379
|
process.env.NODE_ENV || (process.env.NODE_ENV = 'build' === command || 'preview' === command ? 'production' : 'development'), options.environment?.some((env)=>env.includes(',')) && (options.environment = options.environment.flatMap((env)=>env.split(','))), cliState.command = command, cliState.options = options;
|
|
10365
|
-
}, init_loadConfig = async (root)=>{
|
|
10366
|
-
let { options, command } = cliState, result = await loadConfig_loadConfig({
|
|
10367
|
-
cwd: root,
|
|
10368
|
-
path: options.config,
|
|
10369
|
-
envMode: options.envMode,
|
|
10370
|
-
loader: options.configLoader,
|
|
10371
|
-
command
|
|
10372
|
-
}), { content: config } = result;
|
|
10373
|
-
if (config.dev ||= {}, config.source ||= {}, config.server ||= {}, options.base && (config.server.base = options.base), options.root && (config.root = root), options.mode && (config.mode = options.mode), options.logLevel && (config.logLevel = options.logLevel), options.open && !config.server?.open && (config.server.open = options.open), void 0 !== options.host && (config.server.host = options.host), void 0 !== options.port && (config.server.port = options.port), void 0 !== options.strictPort && (config.server.strictPort = options.strictPort), void 0 !== options.distPath) {
|
|
10374
|
-
config.output ||= {};
|
|
10375
|
-
let { distPath } = config.output;
|
|
10376
|
-
config.output.distPath = distPath && 'object' == typeof distPath ? {
|
|
10377
|
-
...distPath,
|
|
10378
|
-
root: options.distPath
|
|
10379
|
-
} : {
|
|
10380
|
-
root: options.distPath
|
|
10381
|
-
};
|
|
10382
|
-
}
|
|
10383
|
-
if (void 0 !== options.sourceMap) {
|
|
10384
|
-
let sourceMap = options.sourceMap;
|
|
10385
|
-
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
10386
|
-
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
10387
|
-
}
|
|
10388
|
-
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), result;
|
|
10389
10380
|
}, init_restart = async (context)=>{
|
|
10390
10381
|
let rsbuild = await init_init({
|
|
10391
10382
|
isRestart: !0
|
|
@@ -10398,7 +10389,31 @@ async function init_init({ isRestart } = {}) {
|
|
|
10398
10389
|
var envDir;
|
|
10399
10390
|
let cwd = process.cwd(), root = options.root ? ensureAbsolutePath(cwd, options.root) : cwd, rsbuild = await createRsbuild({
|
|
10400
10391
|
cwd: root,
|
|
10401
|
-
config: ()=>
|
|
10392
|
+
config: ()=>(async (root)=>{
|
|
10393
|
+
let { options, command } = cliState, result = await loadConfig_loadConfig({
|
|
10394
|
+
cwd: root,
|
|
10395
|
+
path: options.config,
|
|
10396
|
+
envMode: options.envMode,
|
|
10397
|
+
loader: options.configLoader,
|
|
10398
|
+
command
|
|
10399
|
+
}), { content: config } = result;
|
|
10400
|
+
if (config.dev ||= {}, config.source ||= {}, config.server ||= {}, options.base && (config.server.base = options.base), options.root && (config.root = root), options.mode && (config.mode = options.mode), options.logLevel && (config.logLevel = options.logLevel), options.open && !config.server?.open && (config.server.open = options.open), void 0 !== options.host && (config.server.host = options.host), void 0 !== options.port && (config.server.port = options.port), void 0 !== options.strictPort && (config.server.strictPort = options.strictPort), void 0 !== options.distPath) {
|
|
10401
|
+
config.output ||= {};
|
|
10402
|
+
let { distPath } = config.output;
|
|
10403
|
+
config.output.distPath = distPath && 'object' == typeof distPath ? {
|
|
10404
|
+
...distPath,
|
|
10405
|
+
root: options.distPath
|
|
10406
|
+
} : {
|
|
10407
|
+
root: options.distPath
|
|
10408
|
+
};
|
|
10409
|
+
}
|
|
10410
|
+
if (void 0 !== options.sourceMap) {
|
|
10411
|
+
let sourceMap = options.sourceMap;
|
|
10412
|
+
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
10413
|
+
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
10414
|
+
}
|
|
10415
|
+
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), result;
|
|
10416
|
+
})(root),
|
|
10402
10417
|
environment: options.environment,
|
|
10403
10418
|
loadEnv: !1 !== options.env && {
|
|
10404
10419
|
cwd: (envDir = options.envDir) ? node_path.isAbsolute(envDir) ? envDir : node_path.join(root, envDir) : root,
|
|
@@ -10417,7 +10432,7 @@ let applyServerOptions = (command)=>{
|
|
|
10417
10432
|
};
|
|
10418
10433
|
function setupCommands(argv) {
|
|
10419
10434
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10420
|
-
cli.version("2.3.
|
|
10435
|
+
cli.version("2.3.2"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
|
|
10421
10436
|
default: 'auto'
|
|
10422
10437
|
}).option('--dist-path <dir>', 'Set the root directory of output files').option('--source-map', 'Enable source map').option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
|
|
10423
10438
|
type: [
|
|
@@ -10482,7 +10497,7 @@ function setupCommands(argv) {
|
|
|
10482
10497
|
}
|
|
10483
10498
|
function showGreeting() {
|
|
10484
10499
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10485
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.
|
|
10500
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.2\n`);
|
|
10486
10501
|
}
|
|
10487
10502
|
function setupLogLevel(argv) {
|
|
10488
10503
|
if (argv.length <= 3) return;
|
|
@@ -10504,5 +10519,5 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
10504
10519
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10505
10520
|
}
|
|
10506
10521
|
}
|
|
10507
|
-
let src_version = "2.3.
|
|
10522
|
+
let src_version = "2.3.2";
|
|
10508
10523
|
export { core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger_createLogger as createLogger, mergeRsbuildConfig, mrmime_lookup, runCLI, src_logger as logger, src_version as version };
|