@rsbuild/core 1.4.3 → 1.4.5
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 +18 -18
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rslog/package.json +1 -1
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/client/hmr.js +3 -5
- package/dist/index.cjs +117 -98
- package/dist/index.js +115 -102
- package/dist-types/constants.d.ts +2 -0
- package/dist-types/index.d.ts +1 -1
- package/dist-types/server/compilationManager.d.ts +4 -3
- package/dist-types/server/compilationMiddleware.d.ts +11 -6
- package/dist-types/server/gzipMiddleware.d.ts +2 -4
- package/dist-types/server/helper.d.ts +1 -2
- package/dist-types/server/socketServer.d.ts +12 -6
- package/dist-types/types/config.d.ts +24 -1
- package/dist-types/types/hooks.d.ts +6 -0
- package/package.json +5 -5
- package/types.d.ts +11 -1
package/dist/index.cjs
CHANGED
|
@@ -866,6 +866,12 @@ var __webpack_modules__ = {
|
|
|
866
866
|
module.exports = import("node:vm").then(function(module) {
|
|
867
867
|
return module;
|
|
868
868
|
});
|
|
869
|
+
},
|
|
870
|
+
"node:zlib": function(module) {
|
|
871
|
+
"use strict";
|
|
872
|
+
module.exports = import("node:zlib").then(function(module) {
|
|
873
|
+
return module;
|
|
874
|
+
});
|
|
869
875
|
}
|
|
870
876
|
}, __webpack_module_cache__ = {};
|
|
871
877
|
function __webpack_require__(moduleId) {
|
|
@@ -946,7 +952,7 @@ for(var __webpack_i__ in (()=>{
|
|
|
946
952
|
node: [
|
|
947
953
|
'node >= 16'
|
|
948
954
|
]
|
|
949
|
-
}, HTML_REGEX = /\.html$/, JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/, SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, CSS_REGEX = /\.css$/, NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, PLUGIN_SWC_NAME = 'rsbuild:swc', PLUGIN_CSS_NAME = 'rsbuild:css', FONT_EXTENSIONS = [
|
|
955
|
+
}, HTML_REGEX = /\.html$/, JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/, SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, CSS_REGEX = /\.css$/, RAW_QUERY_REGEX = /^\?raw$/, INLINE_QUERY_REGEX = /^\?inline$/, NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, PLUGIN_SWC_NAME = 'rsbuild:swc', PLUGIN_CSS_NAME = 'rsbuild:css', FONT_EXTENSIONS = [
|
|
950
956
|
'woff',
|
|
951
957
|
'woff2',
|
|
952
958
|
'eot',
|
|
@@ -1268,8 +1274,10 @@ for(var __webpack_i__ in (()=>{
|
|
|
1268
1274
|
return `${format(seconds.toFixed(digits))} s`;
|
|
1269
1275
|
}
|
|
1270
1276
|
if (seconds < 60) return `${format(seconds.toFixed(1))} s`;
|
|
1271
|
-
let minutes = seconds / 60;
|
|
1272
|
-
|
|
1277
|
+
let minutes = Math.floor(seconds / 60), minutesLabel = `${format(minutes.toFixed(0))} m`, remainingSeconds = seconds % 60;
|
|
1278
|
+
if (0 === remainingSeconds) return minutesLabel;
|
|
1279
|
+
let secondsLabel = `${format(remainingSeconds.toFixed(+(remainingSeconds % 1 != 0)))} s`;
|
|
1280
|
+
return `${minutesLabel} ${secondsLabel}`;
|
|
1273
1281
|
}, isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI, addCompilationError = (compilation, message)=>{
|
|
1274
1282
|
compilation.errors.push(new compilation.compiler.webpack.WebpackError(message));
|
|
1275
1283
|
};
|
|
@@ -2219,7 +2227,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2219
2227
|
}, {});
|
|
2220
2228
|
async function updateEnvironmentContext(context, configs) {
|
|
2221
2229
|
for (let [index, [name, config]] of (context.environments ||= {}, Object.entries(configs).entries())){
|
|
2222
|
-
let browserslist = await getBrowserslistByEnvironment(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config), environmentContext = {
|
|
2230
|
+
let browserslist = await getBrowserslistByEnvironment(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config), webSocketToken = 'dev' === context.action ? await helpers_hash(context.rootPath + name) : '', environmentContext = {
|
|
2223
2231
|
index,
|
|
2224
2232
|
name,
|
|
2225
2233
|
distPath: function(cwd, config) {
|
|
@@ -2230,7 +2238,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2230
2238
|
browserslist,
|
|
2231
2239
|
htmlPaths,
|
|
2232
2240
|
tsconfigPath,
|
|
2233
|
-
config
|
|
2241
|
+
config,
|
|
2242
|
+
webSocketToken
|
|
2234
2243
|
};
|
|
2235
2244
|
context.environments[name] = new Proxy(environmentContext, {
|
|
2236
2245
|
get: (target, prop)=>target[prop],
|
|
@@ -2241,7 +2250,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2241
2250
|
async function createContext(options, userConfig) {
|
|
2242
2251
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
|
|
2243
2252
|
return {
|
|
2244
|
-
version: "1.4.
|
|
2253
|
+
version: "1.4.5",
|
|
2245
2254
|
rootPath,
|
|
2246
2255
|
distPath: '',
|
|
2247
2256
|
cachePath,
|
|
@@ -2817,7 +2826,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2817
2826
|
}
|
|
2818
2827
|
index_js_namespaceObject.logger.start('build started...');
|
|
2819
2828
|
}(compiler, context), isCompiling = !0;
|
|
2820
|
-
}), 'build' === context.action && compiler.hooks.run.tap('rsbuild:run', ()=>{
|
|
2829
|
+
}), 'build' === context.action && (isMultiCompiler ? compiler.compilers[0] : compiler).hooks.run.tap('rsbuild:run', ()=>{
|
|
2821
2830
|
index_js_namespaceObject.logger.info('build started...'), logRspackVersion();
|
|
2822
2831
|
}), compiler.hooks.done.tap('rsbuild:done', (stats)=>{
|
|
2823
2832
|
((stats)=>{
|
|
@@ -2938,7 +2947,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2938
2947
|
let generatorOptions = {
|
|
2939
2948
|
filename
|
|
2940
2949
|
};
|
|
2941
|
-
!1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(
|
|
2950
|
+
!1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/^\?(__inline=false|url)$/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(INLINE_QUERY_REGEX), rule.oneOf(`${assetType}-asset-raw`).type('asset/source').resourceQuery(RAW_QUERY_REGEX), rule.oneOf(`${assetType}-asset`).type('asset').parser({
|
|
2942
2951
|
dataUrlCondition: {
|
|
2943
2952
|
maxSize
|
|
2944
2953
|
}
|
|
@@ -3828,8 +3837,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3828
3837
|
return isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host;
|
|
3829
3838
|
}, concatUrl = ({ host, port, protocol })=>`${protocol}://${host}:${port}`, LOCAL_LABEL = 'Local: ', NETWORK_LABEL = 'Network: ', getUrlLabel = (url)=>{
|
|
3830
3839
|
try {
|
|
3831
|
-
let {
|
|
3832
|
-
return isLoopbackHost(
|
|
3840
|
+
let { hostname } = new URL(url);
|
|
3841
|
+
return isLoopbackHost(hostname) ? LOCAL_LABEL : NETWORK_LABEL;
|
|
3833
3842
|
} catch {
|
|
3834
3843
|
return NETWORK_LABEL;
|
|
3835
3844
|
}
|
|
@@ -3874,9 +3883,6 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3874
3883
|
})
|
|
3875
3884
|
});
|
|
3876
3885
|
return addressUrls;
|
|
3877
|
-
}, COMPILATION_ID_REGEX = /[^a-zA-Z0-9_-]/g, getCompilationId = (compiler)=>{
|
|
3878
|
-
let uniqueName = compiler.options.output.uniqueName ?? '';
|
|
3879
|
-
return `${compiler.name ?? ''}_${uniqueName.replace(COMPILATION_ID_REGEX, '_')}`;
|
|
3880
3886
|
};
|
|
3881
3887
|
function getServerTerminator(server) {
|
|
3882
3888
|
let listened = !1, pendingSockets = new Set(), onConnection = (socket)=>{
|
|
@@ -4349,13 +4355,15 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4349
4355
|
}
|
|
4350
4356
|
let getCompilationMiddleware = async (compiler, options)=>{
|
|
4351
4357
|
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js")), { clientPaths, callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
|
|
4352
|
-
return applyToCompiler(compiler, (compiler)=>{
|
|
4353
|
-
|
|
4358
|
+
return applyToCompiler(compiler, (compiler, index)=>{
|
|
4359
|
+
var _Object_values_find;
|
|
4360
|
+
let token = null == (_Object_values_find = Object.values(options.environments).find((env)=>env.index === index)) ? void 0 : _Object_values_find.webSocketToken;
|
|
4361
|
+
token && (clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig, token }) {
|
|
4354
4362
|
if (((compiler)=>{
|
|
4355
4363
|
let { target } = compiler.options;
|
|
4356
4364
|
return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
|
|
4357
4365
|
})(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
|
|
4358
|
-
|
|
4366
|
+
RSBUILD_WEB_SOCKET_TOKEN: JSON.stringify(token),
|
|
4359
4367
|
RSBUILD_CLIENT_CONFIG: JSON.stringify(devConfig.client),
|
|
4360
4368
|
RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
|
|
4361
4369
|
RSBUILD_DEV_LIVE_RELOAD: devConfig.liveReload
|
|
@@ -4366,19 +4374,26 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4366
4374
|
compiler,
|
|
4367
4375
|
clientPaths,
|
|
4368
4376
|
devConfig,
|
|
4369
|
-
resolvedClientConfig
|
|
4370
|
-
|
|
4377
|
+
resolvedClientConfig,
|
|
4378
|
+
token
|
|
4379
|
+
}), (({ compiler, token, callbacks: { onDone, onInvalid } })=>{
|
|
4371
4380
|
if (((compiler)=>{
|
|
4372
4381
|
let { target } = compiler.options;
|
|
4373
4382
|
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
4374
4383
|
})(compiler)) return;
|
|
4375
4384
|
let { compile, invalid, done } = compiler.hooks;
|
|
4376
4385
|
compile.tap('rsbuild-dev-server', ()=>{
|
|
4377
|
-
onInvalid(
|
|
4386
|
+
onInvalid(token);
|
|
4378
4387
|
}), invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
4379
|
-
onInvalid(
|
|
4380
|
-
}), done.tap('rsbuild-dev-server',
|
|
4381
|
-
|
|
4388
|
+
onInvalid(token, fileName);
|
|
4389
|
+
}), done.tap('rsbuild-dev-server', (stats)=>{
|
|
4390
|
+
onDone(token, stats);
|
|
4391
|
+
});
|
|
4392
|
+
})({
|
|
4393
|
+
compiler,
|
|
4394
|
+
callbacks,
|
|
4395
|
+
token
|
|
4396
|
+
}));
|
|
4382
4397
|
}), rsbuildDevMiddleware(compiler, {
|
|
4383
4398
|
etag: 'weak',
|
|
4384
4399
|
publicPath: '/',
|
|
@@ -4424,6 +4439,10 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4424
4439
|
writable: !0
|
|
4425
4440
|
}) : obj[key] = value, obj;
|
|
4426
4441
|
}
|
|
4442
|
+
let parseQueryString = (req)=>{
|
|
4443
|
+
let queryStr = req.url ? req.url.split('?')[1] : '';
|
|
4444
|
+
return queryStr ? Object.fromEntries(new URLSearchParams(queryStr)) : {};
|
|
4445
|
+
};
|
|
4427
4446
|
class SocketServer {
|
|
4428
4447
|
clearHeartbeatTimer() {
|
|
4429
4448
|
this.heartbeatTimer && (clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
@@ -4438,51 +4457,44 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4438
4457
|
}), this.wsServer.on('error', (err)=>{
|
|
4439
4458
|
index_js_namespaceObject.logger.error(err);
|
|
4440
4459
|
}), this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref(), this.wsServer.on('connection', (socket, req)=>{
|
|
4441
|
-
let
|
|
4442
|
-
this.onConnect(socket,
|
|
4460
|
+
let query = parseQueryString(req);
|
|
4461
|
+
this.onConnect(socket, query.token);
|
|
4443
4462
|
});
|
|
4444
4463
|
}
|
|
4445
|
-
updateStats(stats) {
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
compilationId
|
|
4464
|
+
updateStats(stats, token) {
|
|
4465
|
+
this.stats[token] = stats, this.sockets.size && this.sendStats({
|
|
4466
|
+
token
|
|
4449
4467
|
});
|
|
4450
4468
|
}
|
|
4451
|
-
sockWrite(
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
}));
|
|
4469
|
+
sockWrite(message, token) {
|
|
4470
|
+
let messageStr = JSON.stringify(message);
|
|
4471
|
+
if (token) {
|
|
4472
|
+
let socket = this.sockets.get(token);
|
|
4473
|
+
socket && this.send(socket, messageStr);
|
|
4474
|
+
} else for (let socket of this.sockets.values())this.send(socket, messageStr);
|
|
4457
4475
|
}
|
|
4458
|
-
singleWrite(socket,
|
|
4459
|
-
this.send(socket, JSON.stringify(
|
|
4460
|
-
type,
|
|
4461
|
-
data,
|
|
4462
|
-
compilationId
|
|
4463
|
-
}));
|
|
4476
|
+
singleWrite(socket, message) {
|
|
4477
|
+
this.send(socket, JSON.stringify(message));
|
|
4464
4478
|
}
|
|
4465
4479
|
async close() {
|
|
4466
4480
|
for (let socket of (this.clearHeartbeatTimer(), this.wsServer.removeAllListeners(), this.wsServer.clients))socket.terminate();
|
|
4467
|
-
for (let socket of this.sockets)socket.close();
|
|
4468
|
-
return this.stats = {}, this.initialChunks = {}, this.sockets.
|
|
4481
|
+
for (let socket of this.sockets.values())socket.close();
|
|
4482
|
+
return this.stats = {}, this.initialChunks = {}, this.sockets.clear(), new Promise((resolve, reject)=>{
|
|
4469
4483
|
this.wsServer.close((err)=>{
|
|
4470
4484
|
err ? reject(err) : resolve();
|
|
4471
4485
|
});
|
|
4472
4486
|
});
|
|
4473
4487
|
}
|
|
4474
|
-
onConnect(socket,
|
|
4488
|
+
onConnect(socket, token) {
|
|
4475
4489
|
socket.isAlive = !0, socket.on('pong', ()=>{
|
|
4476
4490
|
socket.isAlive = !0;
|
|
4477
|
-
}), this.sockets.
|
|
4478
|
-
|
|
4479
|
-
index >= 0 && this.sockets.splice(index, 1);
|
|
4491
|
+
}), this.sockets.set(token, socket), socket.on('close', ()=>{
|
|
4492
|
+
this.sockets.delete(token);
|
|
4480
4493
|
}), (this.options.hmr || this.options.liveReload) && this.singleWrite(socket, {
|
|
4481
|
-
type: 'hot'
|
|
4482
|
-
compilationId: params.compilationId
|
|
4494
|
+
type: 'hot'
|
|
4483
4495
|
}), this.stats && this.sendStats({
|
|
4484
4496
|
force: !0,
|
|
4485
|
-
|
|
4497
|
+
token
|
|
4486
4498
|
});
|
|
4487
4499
|
}
|
|
4488
4500
|
getStats(name) {
|
|
@@ -4507,38 +4519,34 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4507
4519
|
root: curStats.compilation.compiler.options.context
|
|
4508
4520
|
} : null;
|
|
4509
4521
|
}
|
|
4510
|
-
sendStats({ force = !1,
|
|
4522
|
+
sendStats({ force = !1, token }) {
|
|
4511
4523
|
var a, b;
|
|
4512
|
-
let result = this.getStats(
|
|
4524
|
+
let result = this.getStats(token);
|
|
4513
4525
|
if (!result) return null;
|
|
4514
4526
|
let { statsJson, root } = result, newInitialChunks = new Set();
|
|
4515
4527
|
if (statsJson.entrypoints) for (let entrypoint of Object.values(statsJson.entrypoints)){
|
|
4516
4528
|
let chunks = entrypoint.chunks;
|
|
4517
4529
|
if (Array.isArray(chunks)) for (let chunkName of chunks)chunkName && newInitialChunks.add(String(chunkName));
|
|
4518
4530
|
}
|
|
4519
|
-
let initialChunks = this.initialChunks[
|
|
4531
|
+
let initialChunks = this.initialChunks[token], shouldReload = !!statsJson.entrypoints && !!initialChunks && (a = initialChunks, b = newInitialChunks, !(a.size === b.size && [
|
|
4520
4532
|
...a
|
|
4521
4533
|
].every((value)=>b.has(value))));
|
|
4522
|
-
if (this.initialChunks[
|
|
4523
|
-
type: 'static-changed'
|
|
4524
|
-
|
|
4525
|
-
});
|
|
4534
|
+
if (this.initialChunks[token] = newInitialChunks, shouldReload) return this.sockWrite({
|
|
4535
|
+
type: 'static-changed'
|
|
4536
|
+
}, token);
|
|
4526
4537
|
if (!force && statsJson && !statsJson.errorsCount && statsJson.assets && statsJson.assets.every((asset)=>!asset.emitted)) return this.sockWrite({
|
|
4527
|
-
type: 'ok'
|
|
4528
|
-
|
|
4529
|
-
});
|
|
4538
|
+
type: 'ok'
|
|
4539
|
+
}, token);
|
|
4530
4540
|
if (this.sockWrite({
|
|
4531
4541
|
type: 'hash',
|
|
4532
|
-
compilationId,
|
|
4533
4542
|
data: statsJson.hash
|
|
4534
|
-
}), statsJson.errorsCount) {
|
|
4543
|
+
}, token), statsJson.errorsCount) {
|
|
4535
4544
|
let { errors: formattedErrors } = formatStatsMessages({
|
|
4536
4545
|
errors: getAllStatsErrors(statsJson),
|
|
4537
4546
|
warnings: []
|
|
4538
4547
|
});
|
|
4539
4548
|
return this.sockWrite({
|
|
4540
4549
|
type: 'errors',
|
|
4541
|
-
compilationId,
|
|
4542
4550
|
data: {
|
|
4543
4551
|
text: formattedErrors,
|
|
4544
4552
|
html: function(errors, root) {
|
|
@@ -4696,7 +4704,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4696
4704
|
`;
|
|
4697
4705
|
}(formattedErrors, root)
|
|
4698
4706
|
}
|
|
4699
|
-
});
|
|
4707
|
+
}, token);
|
|
4700
4708
|
}
|
|
4701
4709
|
if (statsJson.warningsCount) {
|
|
4702
4710
|
let { warnings: formattedWarnings } = formatStatsMessages({
|
|
@@ -4705,29 +4713,30 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4705
4713
|
});
|
|
4706
4714
|
return this.sockWrite({
|
|
4707
4715
|
type: 'warnings',
|
|
4708
|
-
compilationId,
|
|
4709
4716
|
data: {
|
|
4710
4717
|
text: formattedWarnings
|
|
4711
4718
|
}
|
|
4712
|
-
});
|
|
4719
|
+
}, token);
|
|
4713
4720
|
}
|
|
4714
4721
|
return this.sockWrite({
|
|
4715
|
-
type: 'ok'
|
|
4716
|
-
|
|
4717
|
-
});
|
|
4722
|
+
type: 'ok'
|
|
4723
|
+
}, token);
|
|
4718
4724
|
}
|
|
4719
4725
|
send(connection, message) {
|
|
4720
4726
|
1 === connection.readyState && connection.send(message);
|
|
4721
4727
|
}
|
|
4722
|
-
constructor(options){
|
|
4723
|
-
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets",
|
|
4724
|
-
this.wsServer.shouldHandle(req)
|
|
4728
|
+
constructor(options, environments){
|
|
4729
|
+
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", new Map()), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "environments", void 0), socketServer_define_property(this, "upgrade", (req, socket, head)=>{
|
|
4730
|
+
if (!this.wsServer.shouldHandle(req)) return;
|
|
4731
|
+
let query = parseQueryString(req);
|
|
4732
|
+
if (!Object.values(this.environments).map((env)=>env.webSocketToken).includes(query.token)) return void socket.destroy();
|
|
4733
|
+
this.wsServer.handleUpgrade(req, socket, head, (connection)=>{
|
|
4725
4734
|
this.wsServer.emit('connection', connection, req);
|
|
4726
4735
|
});
|
|
4727
4736
|
}), socketServer_define_property(this, "checkSockets", ()=>{
|
|
4728
4737
|
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
4729
4738
|
null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref());
|
|
4730
|
-
}), this.options = options, this.stats = {}, this.initialChunks = {};
|
|
4739
|
+
}), this.options = options, this.stats = {}, this.initialChunks = {}, this.environments = environments;
|
|
4731
4740
|
}
|
|
4732
4741
|
}
|
|
4733
4742
|
function compilationManager_define_property(obj, key, value) {
|
|
@@ -4760,29 +4769,28 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4760
4769
|
});
|
|
4761
4770
|
}
|
|
4762
4771
|
async setupCompilationMiddleware() {
|
|
4763
|
-
let { devConfig, serverConfig, publicPaths } = this, clientPaths = function(devConfig) {
|
|
4772
|
+
let { devConfig, serverConfig, publicPaths, environments } = this, clientPaths = function(devConfig) {
|
|
4764
4773
|
var _devConfig_client;
|
|
4765
4774
|
let clientPaths = [];
|
|
4766
4775
|
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/hmr')), (null == (_devConfig_client = devConfig.client) ? void 0 : _devConfig_client.overlay) && clientPaths.push(`${compilationManager_require.resolve('@rsbuild/core/client/overlay')}`)), clientPaths;
|
|
4767
4776
|
}(devConfig), middleware = await getCompilationMiddleware(this.compiler, {
|
|
4768
4777
|
callbacks: {
|
|
4769
|
-
onInvalid: (
|
|
4778
|
+
onInvalid: (token, fileName)=>{
|
|
4770
4779
|
if ('string' == typeof fileName && HTML_REGEX.test(fileName)) return void this.socketServer.sockWrite({
|
|
4771
|
-
type: 'static-changed'
|
|
4772
|
-
|
|
4773
|
-
});
|
|
4780
|
+
type: 'static-changed'
|
|
4781
|
+
}, token);
|
|
4774
4782
|
this.socketServer.sockWrite({
|
|
4775
|
-
type: 'invalid'
|
|
4776
|
-
|
|
4777
|
-
});
|
|
4783
|
+
type: 'invalid'
|
|
4784
|
+
}, token);
|
|
4778
4785
|
},
|
|
4779
|
-
onDone: (stats)=>{
|
|
4780
|
-
this.socketServer.updateStats(stats);
|
|
4786
|
+
onDone: (token, stats)=>{
|
|
4787
|
+
this.socketServer.updateStats(stats, token);
|
|
4781
4788
|
}
|
|
4782
4789
|
},
|
|
4783
4790
|
clientPaths,
|
|
4784
4791
|
devConfig,
|
|
4785
|
-
serverConfig
|
|
4792
|
+
serverConfig,
|
|
4793
|
+
environments
|
|
4786
4794
|
}), { base } = serverConfig, assetPrefixes = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
4787
4795
|
let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
|
|
4788
4796
|
assetPrefix && '/' !== assetPrefix ? (req.url = url.slice(assetPrefix.length - 1), middleware(req, res, (...args)=>{
|
|
@@ -4792,7 +4800,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4792
4800
|
wrapper.close = middleware.close, wrapper.watch = middleware.watch, this.middleware = wrapper;
|
|
4793
4801
|
}
|
|
4794
4802
|
constructor({ dev, server, compiler, publicPaths, environments }){
|
|
4795
|
-
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "devConfig", void 0), compilationManager_define_property(this, "serverConfig", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : external_node_fs_default().readFileSync(fileName, 'utf-8')), this.devConfig = ((config, environments)=>{
|
|
4803
|
+
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "devConfig", void 0), compilationManager_define_property(this, "serverConfig", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "environments", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : external_node_fs_default().readFileSync(fileName, 'utf-8')), this.devConfig = ((config, environments)=>{
|
|
4796
4804
|
let writeToDiskValues = Object.values(environments).map((env)=>env.config.dev.writeToDisk);
|
|
4797
4805
|
return 1 === new Set(writeToDiskValues).size ? {
|
|
4798
4806
|
...config,
|
|
@@ -4804,11 +4812,13 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4804
4812
|
return compilationName && environments[compilationName] && (writeToDisk = environments[compilationName].config.dev.writeToDisk ?? writeToDisk), 'function' == typeof writeToDisk ? writeToDisk(filePath) : writeToDisk;
|
|
4805
4813
|
}
|
|
4806
4814
|
};
|
|
4807
|
-
})(dev, environments), this.serverConfig = server, this.compiler = compiler, this.publicPaths = publicPaths, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(dev);
|
|
4815
|
+
})(dev, environments), this.serverConfig = server, this.compiler = compiler, this.environments = environments, this.publicPaths = publicPaths, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(dev, environments);
|
|
4808
4816
|
}
|
|
4809
4817
|
}
|
|
4810
|
-
let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, gzipMiddleware = ({ level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
4811
|
-
let gzip, writeHeadStatus
|
|
4818
|
+
let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, gzipMiddleware = ({ filter, level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
4819
|
+
let gzip, writeHeadStatus;
|
|
4820
|
+
if (filter && !1 === filter(req, res)) return void next();
|
|
4821
|
+
let accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
|
|
4812
4822
|
if ('HEAD' === req.method || !encoding) return void next();
|
|
4813
4823
|
let started = !1, { end, write, on, writeHead } = res, listeners = [], start = ()=>{
|
|
4814
4824
|
if (!started) {
|
|
@@ -4932,7 +4942,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
4932
4942
|
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy);
|
|
4933
4943
|
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.push(middleware);
|
|
4934
4944
|
}
|
|
4935
|
-
|
|
4945
|
+
let { compress } = server;
|
|
4946
|
+
if (compress && middlewares.push(gzipMiddleware('object' == typeof compress ? compress : void 0)), 'dev' === context.action && 'rspack' === context.bundlerType && compilationManager) {
|
|
4936
4947
|
let { compiler } = compilationManager;
|
|
4937
4948
|
(()=>{
|
|
4938
4949
|
var _compiler_options_experiments;
|
|
@@ -5692,9 +5703,14 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5692
5703
|
for (let middleware of middlewares)this.middlewares.use(middleware);
|
|
5693
5704
|
this.app.on('upgrade', upgrade);
|
|
5694
5705
|
}
|
|
5695
|
-
if (compress
|
|
5696
|
-
|
|
5697
|
-
|
|
5706
|
+
if (compress) {
|
|
5707
|
+
let { constants } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "node:zlib"));
|
|
5708
|
+
this.middlewares.use(gzipMiddleware({
|
|
5709
|
+
level: constants.Z_DEFAULT_COMPRESSION,
|
|
5710
|
+
...'object' == typeof compress ? compress : void 0
|
|
5711
|
+
}));
|
|
5712
|
+
}
|
|
5713
|
+
if (base && '/' !== base && this.middlewares.use(getBaseMiddleware({
|
|
5698
5714
|
base
|
|
5699
5715
|
})), await this.applyStaticAssetMiddleware(), historyApiFallback) {
|
|
5700
5716
|
let { default: connectHistoryApiFallback } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/connect-history-api-fallback/index.js")), historyApiFallbackMiddleware = connectHistoryApiFallback(!0 === historyApiFallback ? {} : historyApiFallback);
|
|
@@ -6482,8 +6498,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6482
6498
|
rule.test(CSS_REGEX).type("javascript/auto").dependency({
|
|
6483
6499
|
not: 'url'
|
|
6484
6500
|
}).resourceQuery({
|
|
6485
|
-
not:
|
|
6486
|
-
|
|
6501
|
+
not: [
|
|
6502
|
+
RAW_QUERY_REGEX,
|
|
6503
|
+
INLINE_QUERY_REGEX
|
|
6504
|
+
]
|
|
6505
|
+
}), inlineRule.test(CSS_REGEX).type("javascript/auto").resourceQuery(INLINE_QUERY_REGEX), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(RAW_QUERY_REGEX);
|
|
6487
6506
|
let emitCss = config1.output.emitCss ?? 'web' === target;
|
|
6488
6507
|
if (emitCss) if (config1.output.injectStyles) {
|
|
6489
6508
|
let styleLoaderOptions = reduceConfigs({
|
|
@@ -6666,9 +6685,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6666
6685
|
let { config, browserslist } = environment, cacheRoot = external_node_path_default().join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto").dependency({
|
|
6667
6686
|
not: 'url'
|
|
6668
6687
|
}).resourceQuery({
|
|
6669
|
-
not:
|
|
6688
|
+
not: RAW_QUERY_REGEX
|
|
6670
6689
|
});
|
|
6671
|
-
chain.module.rule(CHAIN_ID.RULE.JS_RAW).test(SCRIPT_REGEX).type('asset/source').resourceQuery(
|
|
6690
|
+
chain.module.rule(CHAIN_ID.RULE.JS_RAW).test(SCRIPT_REGEX).type('asset/source').resourceQuery(RAW_QUERY_REGEX);
|
|
6672
6691
|
let dataUriRule = chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
6673
6692
|
or: [
|
|
6674
6693
|
"text/javascript",
|
|
@@ -7845,11 +7864,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7845
7864
|
].includes(level) && (index_js_namespaceObject.logger.level = level);
|
|
7846
7865
|
}
|
|
7847
7866
|
let { npm_execpath } = process.env;
|
|
7848
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && index_js_namespaceObject.logger.log(), index_js_namespaceObject.logger.greet(` Rsbuild v1.4.
|
|
7867
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && index_js_namespaceObject.logger.log(), index_js_namespaceObject.logger.greet(` Rsbuild v1.4.5\n`);
|
|
7849
7868
|
try {
|
|
7850
7869
|
!function() {
|
|
7851
7870
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
7852
|
-
cli.help(), cli.version("1.4.
|
|
7871
|
+
cli.help(), cli.version("1.4.5"), cli.option('--base <base>', 'specify the base path of the server').option('-c, --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'specify the loader to load the config file, can be `jiti` or `native`', {
|
|
7853
7872
|
default: 'jiti'
|
|
7854
7873
|
}).option('-r, --root <root>', 'specify the project root directory, can be an absolute path or a path relative to cwd').option('-m, --mode <mode>', 'specify the build mode, can be `development`, `production` or `none`').option('--log-level <level>', 'specify the log level, can be `info`, `warn`, `error` or `silent`').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--environment <name>', 'specify the name of environment to build', {
|
|
7855
7874
|
type: [
|
|
@@ -7907,7 +7926,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7907
7926
|
index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), index_js_namespaceObject.logger.error(err);
|
|
7908
7927
|
}
|
|
7909
7928
|
}
|
|
7910
|
-
let src_version = "1.4.
|
|
7929
|
+
let src_version = "1.4.5";
|
|
7911
7930
|
})(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, exports.defaultAllowedOrigins = __webpack_exports__.defaultAllowedOrigins, exports.defineConfig = __webpack_exports__.defineConfig, exports.ensureAssetPrefix = __webpack_exports__.ensureAssetPrefix, exports.loadConfig = __webpack_exports__.loadConfig, exports.loadEnv = __webpack_exports__.loadEnv, exports.logger = __webpack_exports__.logger, exports.mergeRsbuildConfig = __webpack_exports__.mergeRsbuildConfig, exports.rspack = __webpack_exports__.rspack, exports.runCLI = __webpack_exports__.runCLI, exports.version = __webpack_exports__.version, __webpack_exports__)-1 === [
|
|
7912
7931
|
"PLUGIN_CSS_NAME",
|
|
7913
7932
|
"PLUGIN_SWC_NAME",
|