@rsbuild/core 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/cors/index.d.ts +1 -0
- package/compiled/cors/index.js +371 -0
- package/compiled/cors/license +22 -0
- package/compiled/cors/package.json +1 -0
- package/compiled/css-loader/index.js +20 -20
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/postcss-loader/index.js +8 -8
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/client/hmr.js +3 -35
- package/dist/client/overlay.js +0 -3
- package/dist/index.cjs +48 -17
- package/dist/index.js +44 -17
- package/dist/transformLoader.mjs +3 -2
- package/dist/transformRawLoader.mjs +3 -2
- package/dist-types/server/devMiddleware.d.ts +1 -1
- package/dist-types/types/config.d.ts +11 -1
- package/dist-types/types/plugin.d.ts +5 -1
- package/package.json +5 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
"use strict";
|
|
3
3
|
var __webpack_modules__ = {
|
|
4
|
-
|
|
4
|
+
44: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.transformFiles =
|
|
7
7
|
exports.reduceChunk =
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
.map(standardizeFilePaths);
|
|
121
121
|
exports.transformFiles = transformFiles;
|
|
122
122
|
},
|
|
123
|
-
|
|
123
|
+
469: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
124
124
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
125
125
|
exports.normalModuleLoaderHook =
|
|
126
126
|
exports.getCompilerHooks =
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
const fs_1 = __nccwpck_require__(147);
|
|
131
131
|
const path_1 = __nccwpck_require__(17);
|
|
132
132
|
const lite_tapable_1 = __nccwpck_require__(348);
|
|
133
|
-
const helpers_1 = __nccwpck_require__(
|
|
133
|
+
const helpers_1 = __nccwpck_require__(44);
|
|
134
134
|
const compilerHookMap = new WeakMap();
|
|
135
135
|
const getCompilerHooks = (compiler) => {
|
|
136
136
|
let hooks = compilerHookMap.get(compiler);
|
|
@@ -312,7 +312,7 @@
|
|
|
312
312
|
exports.getCompilerHooks =
|
|
313
313
|
void 0;
|
|
314
314
|
const path_1 = __nccwpck_require__(17);
|
|
315
|
-
const hooks_1 = __nccwpck_require__(
|
|
315
|
+
const hooks_1 = __nccwpck_require__(469);
|
|
316
316
|
Object.defineProperty(exports, "getCompilerHooks", {
|
|
317
317
|
enumerable: true,
|
|
318
318
|
get: function () {
|
package/dist/client/hmr.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
function resolveFileName(stats) {
|
|
2
|
-
// Get the real source file path with stats.moduleIdentifier.
|
|
3
|
-
// e.g. moduleIdentifier is "builtin:react-refresh-loader!/Users/x/src/App.jsx"
|
|
4
2
|
if (stats.moduleIdentifier) {
|
|
5
3
|
const regex = /(?:\!|^)([^!]+)$/;
|
|
6
4
|
const matched = stats.moduleIdentifier.match(regex);
|
|
7
5
|
if (matched) {
|
|
8
6
|
const fileName = matched.pop();
|
|
9
|
-
if (fileName)
|
|
10
|
-
return `File: ${fileName}:1:1\n`;
|
|
7
|
+
if (fileName) return `File: ${fileName}:1:1\n`;
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
// fallback to file or moduleName if moduleIdentifier parse failed
|
|
14
10
|
const file = stats.file || stats.moduleName;
|
|
15
11
|
return file ? `File: ${file}\n` : '';
|
|
16
12
|
}
|
|
17
13
|
function resolveModuleTrace(stats) {
|
|
18
14
|
let traceStr = '';
|
|
19
15
|
if (stats.moduleTrace) {
|
|
20
|
-
for (const trace of stats.moduleTrace)if (trace.originName)
|
|
21
|
-
traceStr += `\n @ ${trace.originName}`;
|
|
16
|
+
for (const trace of stats.moduleTrace)if (trace.originName) traceStr += `\n @ ${trace.originName}`;
|
|
22
17
|
}
|
|
23
18
|
return traceStr;
|
|
24
19
|
}
|
|
@@ -30,11 +25,9 @@ function hintUnknownFiles(message) {
|
|
|
30
25
|
if (/File: .+\.styl(us)?/.test(message)) return message.replace(hint, 'To enable support for Stylus, use "@rsbuild/plugin-stylus".');
|
|
31
26
|
return message;
|
|
32
27
|
}
|
|
33
|
-
// Cleans up Rspack error messages.
|
|
34
28
|
function formatMessage(stats, verbose) {
|
|
35
29
|
let lines = [];
|
|
36
30
|
let message;
|
|
37
|
-
// Stats error object
|
|
38
31
|
if ('object' == typeof stats) {
|
|
39
32
|
const fileName = resolveFileName(stats);
|
|
40
33
|
const mainMessage = stats.message;
|
|
@@ -45,9 +38,7 @@ function formatMessage(stats, verbose) {
|
|
|
45
38
|
} else message = stats;
|
|
46
39
|
message = hintUnknownFiles(message);
|
|
47
40
|
lines = message.split('\n');
|
|
48
|
-
// Remove duplicated newlines
|
|
49
41
|
lines = lines.filter((line, index, arr)=>0 === index || '' !== line.trim() || line.trim() !== arr[index - 1].trim());
|
|
50
|
-
// Reassemble the message
|
|
51
42
|
message = lines.join('\n');
|
|
52
43
|
const innerError = '-- inner error --';
|
|
53
44
|
if (!verbose && message.includes(innerError)) message = message.split(innerError)[0];
|
|
@@ -75,16 +66,13 @@ function formatURL(param) {
|
|
|
75
66
|
url.searchParams.append('compilationId', compilationId);
|
|
76
67
|
return url.toString();
|
|
77
68
|
}
|
|
78
|
-
// compatible with IE11
|
|
79
69
|
const colon = -1 === protocol.indexOf(':') ? ':' : '';
|
|
80
70
|
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
81
71
|
}
|
|
82
|
-
// Remember some state related to hot module replacement.
|
|
83
72
|
let isFirstCompilation = true;
|
|
84
73
|
let lastCompilationHash = null;
|
|
85
74
|
let hasCompileErrors = false;
|
|
86
75
|
function clearOutdatedErrors() {
|
|
87
|
-
// Clean up outdated compile errors, if any.
|
|
88
76
|
if (console.clear && hasCompileErrors) console.clear();
|
|
89
77
|
}
|
|
90
78
|
let createOverlay;
|
|
@@ -93,16 +81,13 @@ const registerOverlay = (createFn, clearFn)=>{
|
|
|
93
81
|
createOverlay = createFn;
|
|
94
82
|
clearOverlay = clearFn;
|
|
95
83
|
};
|
|
96
|
-
// Successful compilation.
|
|
97
84
|
function handleSuccess() {
|
|
98
85
|
clearOutdatedErrors();
|
|
99
86
|
const isHotUpdate = !isFirstCompilation;
|
|
100
87
|
isFirstCompilation = false;
|
|
101
88
|
hasCompileErrors = false;
|
|
102
|
-
// Attempt to apply hot updates or reload.
|
|
103
89
|
if (isHotUpdate) tryApplyUpdates();
|
|
104
90
|
}
|
|
105
|
-
// Compilation with warnings (e.g. ESLint).
|
|
106
91
|
function handleWarnings(warnings) {
|
|
107
92
|
clearOutdatedErrors();
|
|
108
93
|
const isHotUpdate = !isFirstCompilation;
|
|
@@ -119,10 +104,8 @@ function handleWarnings(warnings) {
|
|
|
119
104
|
}
|
|
120
105
|
console.warn(formatted.warnings[i]);
|
|
121
106
|
}
|
|
122
|
-
// Attempt to apply hot updates or reload.
|
|
123
107
|
if (isHotUpdate) tryApplyUpdates();
|
|
124
108
|
}
|
|
125
|
-
// Compilation with errors (e.g. syntax error or missing modules).
|
|
126
109
|
function handleErrors(errors) {
|
|
127
110
|
clearOutdatedErrors();
|
|
128
111
|
isFirstCompilation = false;
|
|
@@ -131,23 +114,16 @@ function handleErrors(errors) {
|
|
|
131
114
|
errors,
|
|
132
115
|
warnings: []
|
|
133
116
|
});
|
|
134
|
-
// Also log them to the console.
|
|
135
117
|
for (const error of formatted.errors)console.error(error);
|
|
136
118
|
if (createOverlay) createOverlay(formatted.errors);
|
|
137
119
|
}
|
|
138
|
-
// __webpack_hash__ is the hash of the current compilation.
|
|
139
|
-
// It's a global variable injected by Rspack.
|
|
140
120
|
const isUpdateAvailable = ()=>lastCompilationHash !== __webpack_hash__;
|
|
141
|
-
// Attempt to update code on the fly, fall back to a hard reload.
|
|
142
121
|
function tryApplyUpdates() {
|
|
143
|
-
// detect is there a newer version of this code available
|
|
144
122
|
if (!isUpdateAvailable()) return;
|
|
145
123
|
if (!import.meta.webpackHot) {
|
|
146
|
-
// HotModuleReplacementPlugin is not in Rspack configuration.
|
|
147
124
|
reloadPage();
|
|
148
125
|
return;
|
|
149
126
|
}
|
|
150
|
-
// Rspack disallows updates in other states.
|
|
151
127
|
if ('idle' !== import.meta.webpackHot.status()) return;
|
|
152
128
|
const handleApplyUpdates = (err, updatedModules)=>{
|
|
153
129
|
const forcedReload = err || !updatedModules;
|
|
@@ -156,16 +132,13 @@ function tryApplyUpdates() {
|
|
|
156
132
|
reloadPage();
|
|
157
133
|
return;
|
|
158
134
|
}
|
|
159
|
-
if (isUpdateAvailable())
|
|
160
|
-
tryApplyUpdates();
|
|
135
|
+
if (isUpdateAvailable()) tryApplyUpdates();
|
|
161
136
|
};
|
|
162
|
-
// https://rspack.dev/api/runtime-api/module-variables#importmetawebpackhot
|
|
163
137
|
import.meta.webpackHot.check(true).then((updatedModules)=>handleApplyUpdates(null, updatedModules), (err)=>handleApplyUpdates(err, null));
|
|
164
138
|
}
|
|
165
139
|
let connection = null;
|
|
166
140
|
let reconnectCount = 0;
|
|
167
141
|
function onOpen() {
|
|
168
|
-
// Notify users that the HMR has successfully connected.
|
|
169
142
|
console.info('[HMR] connected.');
|
|
170
143
|
}
|
|
171
144
|
function onMessage(e) {
|
|
@@ -173,7 +146,6 @@ function onMessage(e) {
|
|
|
173
146
|
if (message.compilationId && message.compilationId !== compilationId) return;
|
|
174
147
|
switch(message.type){
|
|
175
148
|
case 'hash':
|
|
176
|
-
// Update the last compilation hash
|
|
177
149
|
lastCompilationHash = message.data;
|
|
178
150
|
if (clearOverlay && isUpdateAvailable()) clearOverlay();
|
|
179
151
|
break;
|
|
@@ -181,7 +153,6 @@ function onMessage(e) {
|
|
|
181
153
|
case 'ok':
|
|
182
154
|
handleSuccess();
|
|
183
155
|
break;
|
|
184
|
-
// Triggered when static files changed
|
|
185
156
|
case 'static-changed':
|
|
186
157
|
case 'content-changed':
|
|
187
158
|
reloadPage();
|
|
@@ -205,7 +176,6 @@ function onClose() {
|
|
|
205
176
|
reconnectCount++;
|
|
206
177
|
setTimeout(connect, 1000 * 1.5 ** reconnectCount);
|
|
207
178
|
}
|
|
208
|
-
// Establishing a WebSocket connection with the server.
|
|
209
179
|
function connect() {
|
|
210
180
|
const { location } = self;
|
|
211
181
|
const { host, port, path, protocol } = config;
|
|
@@ -217,9 +187,7 @@ function connect() {
|
|
|
217
187
|
});
|
|
218
188
|
connection = new WebSocket(socketUrl);
|
|
219
189
|
connection.addEventListener('open', onOpen);
|
|
220
|
-
// Attempt to reconnect after disconnection
|
|
221
190
|
connection.addEventListener('close', onClose);
|
|
222
|
-
// Handle messages from the server.
|
|
223
191
|
connection.addEventListener('message', onMessage);
|
|
224
192
|
}
|
|
225
193
|
function removeListeners() {
|
package/dist/client/overlay.js
CHANGED
|
@@ -191,7 +191,6 @@ class ErrorOverlay extends HTMLElement {
|
|
|
191
191
|
root.innerHTML = overlayTemplate;
|
|
192
192
|
linkedText(root, '.content', stripAnsi(message.join('\n')).trim());
|
|
193
193
|
null === (_root_querySelector = root.querySelector('.close')) || void 0 === _root_querySelector || _root_querySelector.addEventListener('click', this.close);
|
|
194
|
-
// close overlay when click outside
|
|
195
194
|
this.addEventListener('click', this.close);
|
|
196
195
|
root.querySelector('.container').addEventListener('click', (e)=>{
|
|
197
196
|
e.stopPropagation();
|
|
@@ -210,8 +209,6 @@ function createOverlay(err) {
|
|
|
210
209
|
document.body.appendChild(new ErrorOverlay(err));
|
|
211
210
|
}
|
|
212
211
|
function clearOverlay() {
|
|
213
|
-
// use NodeList's forEach api instead of dom.iterable
|
|
214
|
-
// biome-ignore lint/complexity/noForEach: <explanation>
|
|
215
212
|
document.querySelectorAll(overlayId).forEach((n)=>n.close());
|
|
216
213
|
}
|
|
217
214
|
if ('undefined' != typeof document) (0, __WEBPACK_EXTERNAL_MODULE__hmr__.registerOverlay)(createOverlay, clearOverlay);
|
package/dist/index.cjs
CHANGED
|
@@ -280,6 +280,10 @@ var __webpack_modules__ = {
|
|
|
280
280
|
"use strict";
|
|
281
281
|
module.exports = import("../compiled/connect/index.js");
|
|
282
282
|
},
|
|
283
|
+
"../../compiled/cors/index.js": function(module) {
|
|
284
|
+
"use strict";
|
|
285
|
+
module.exports = import("../compiled/cors/index.js");
|
|
286
|
+
},
|
|
283
287
|
"../../compiled/http-proxy-middleware/index.js": function(module) {
|
|
284
288
|
"use strict";
|
|
285
289
|
module.exports = import("../compiled/http-proxy-middleware/index.js");
|
|
@@ -2101,7 +2105,8 @@ var __webpack_exports__ = {};
|
|
|
2101
2105
|
htmlFallback: 'index',
|
|
2102
2106
|
compress: !0,
|
|
2103
2107
|
printUrls: !0,
|
|
2104
|
-
strictPort: !1
|
|
2108
|
+
strictPort: !1,
|
|
2109
|
+
cors: !0
|
|
2105
2110
|
}), getDefaultSourceConfig = ()=>({
|
|
2106
2111
|
alias: {},
|
|
2107
2112
|
define: {},
|
|
@@ -2736,7 +2741,7 @@ var __webpack_exports__ = {};
|
|
|
2736
2741
|
async function createContext(options, userConfig, bundlerType) {
|
|
2737
2742
|
let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache');
|
|
2738
2743
|
return {
|
|
2739
|
-
version: "1.1.
|
|
2744
|
+
version: "1.1.11",
|
|
2740
2745
|
rootPath,
|
|
2741
2746
|
distPath: '',
|
|
2742
2747
|
cachePath,
|
|
@@ -2938,7 +2943,10 @@ var __webpack_exports__ = {};
|
|
|
2938
2943
|
javascript: {
|
|
2939
2944
|
exportsPresence: 'error'
|
|
2940
2945
|
}
|
|
2941
|
-
}), isDev && config.dev.hmr && 'web' === target && chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin), 'development' === env && chain.output.devtoolModuleFilenameTemplate((info)=>external_node_path_default().resolve(info.absoluteResourcePath).replace(/\\/g, '/')), process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-unrecognized-keys', process.env.WATCHPACK_WATCHER_LIMIT ||= '20'
|
|
2946
|
+
}), isDev && config.dev.hmr && 'web' === target && chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin), 'development' === env && chain.output.devtoolModuleFilenameTemplate((info)=>external_node_path_default().resolve(info.absoluteResourcePath).replace(/\\/g, '/')), process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-unrecognized-keys', process.env.WATCHPACK_WATCHER_LIMIT ||= '20', process.env.EXPERIMENTAL_RSPACK_INCREMENTAL && chain.experiments({
|
|
2947
|
+
...chain.get('experiments'),
|
|
2948
|
+
incremental: isDev
|
|
2949
|
+
});
|
|
2942
2950
|
});
|
|
2943
2951
|
}
|
|
2944
2952
|
}), isUseAnalyzer = (config)=>{
|
|
@@ -4631,16 +4639,20 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4631
4639
|
});
|
|
4632
4640
|
}
|
|
4633
4641
|
};
|
|
4634
|
-
api.onAfterStartDevServer(onStartServer), api.onAfterStartProdServer(onStartServer), api.onBeforeBuild(async ({ isFirstCompile })=>{
|
|
4642
|
+
api.onAfterStartDevServer(onStartServer), api.onAfterStartProdServer(onStartServer), api.onBeforeBuild(async ({ isFirstCompile, environments })=>{
|
|
4635
4643
|
if (!!isFirstCompile) for (let publicDir of normalizePublicDirs(api.getNormalizedConfig().server.publicDir)){
|
|
4636
4644
|
let { name, copyOnBuild } = publicDir;
|
|
4637
4645
|
if (!copyOnBuild || !name) continue;
|
|
4638
4646
|
let normalizedPath = (0, external_node_path_.isAbsolute)(name) ? name : (0, external_node_path_.join)(api.context.rootPath, name);
|
|
4639
|
-
if (
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4647
|
+
if (!external_node_fs_default().existsSync(normalizedPath)) continue;
|
|
4648
|
+
let distPaths = [
|
|
4649
|
+
...new Set(Object.values(environments).map((e)=>e.distPath))
|
|
4650
|
+
];
|
|
4651
|
+
try {
|
|
4652
|
+
await Promise.all(distPaths.map((distPath)=>external_node_fs_default().promises.cp(normalizedPath, distPath, {
|
|
4653
|
+
recursive: !0,
|
|
4654
|
+
dereference: !0
|
|
4655
|
+
})));
|
|
4644
4656
|
} catch (err) {
|
|
4645
4657
|
throw err instanceof Error && (err.message = `Copy public dir (${normalizedPath}) to dist failed:\n${err.message}`), err;
|
|
4646
4658
|
}
|
|
@@ -5433,7 +5445,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5433
5445
|
}, setupServerHooks = (compiler, hookCallbacks)=>{
|
|
5434
5446
|
if (isNodeCompiler(compiler)) return;
|
|
5435
5447
|
let { compile, invalid, done } = compiler.hooks;
|
|
5436
|
-
compile.tap('rsbuild-dev-server', ()=>
|
|
5448
|
+
compile.tap('rsbuild-dev-server', ()=>{
|
|
5449
|
+
hookCallbacks.onInvalid(getCompilationId(compiler));
|
|
5450
|
+
}), invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
5451
|
+
hookCallbacks.onInvalid(getCompilationId(compiler), fileName);
|
|
5452
|
+
}), done.tap('rsbuild-dev-server', hookCallbacks.onDone);
|
|
5437
5453
|
}, getDevMiddleware = async (multiCompiler)=>{
|
|
5438
5454
|
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js"));
|
|
5439
5455
|
return (options)=>{
|
|
@@ -5633,7 +5649,14 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5633
5649
|
publicPath: '/',
|
|
5634
5650
|
stats: !1,
|
|
5635
5651
|
callbacks: {
|
|
5636
|
-
onInvalid: (compilationId)=>{
|
|
5652
|
+
onInvalid: (compilationId, fileName)=>{
|
|
5653
|
+
if ('string' == typeof fileName && HTML_REGEX.test(fileName)) {
|
|
5654
|
+
this.socketServer.sockWrite({
|
|
5655
|
+
type: 'content-changed',
|
|
5656
|
+
compilationId
|
|
5657
|
+
});
|
|
5658
|
+
return;
|
|
5659
|
+
}
|
|
5637
5660
|
this.socketServer.sockWrite({
|
|
5638
5661
|
type: 'invalid',
|
|
5639
5662
|
compilationId
|
|
@@ -6113,7 +6136,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6113
6136
|
let confHeaders = server.headers;
|
|
6114
6137
|
if (confHeaders) for (let [key, value] of Object.entries(confHeaders))res.setHeader(key, value);
|
|
6115
6138
|
next();
|
|
6116
|
-
}), server.
|
|
6139
|
+
}), server.cors) {
|
|
6140
|
+
let { default: corsMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/cors/index.js"));
|
|
6141
|
+
middlewares.push(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
6142
|
+
}
|
|
6143
|
+
if (server.proxy) {
|
|
6117
6144
|
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy);
|
|
6118
6145
|
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.push(middleware);
|
|
6119
6146
|
}
|
|
@@ -6497,13 +6524,17 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6497
6524
|
this.app = app, await this.applyDefaultMiddlewares();
|
|
6498
6525
|
}
|
|
6499
6526
|
async applyDefaultMiddlewares() {
|
|
6500
|
-
let { headers, proxy, historyApiFallback, compress, base } = this.options.serverConfig;
|
|
6527
|
+
let { headers, proxy, historyApiFallback, compress, base, cors } = this.options.serverConfig;
|
|
6501
6528
|
if ('verbose' === rslog_index_js_namespaceObject.logger.level && this.middlewares.use(await getRequestLoggerMiddleware()), compress && this.middlewares.use(gzipMiddleware({
|
|
6502
6529
|
level: 6
|
|
6503
6530
|
})), headers && this.middlewares.use((_req, res, next)=>{
|
|
6504
6531
|
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
6505
6532
|
next();
|
|
6506
|
-
}),
|
|
6533
|
+
}), cors) {
|
|
6534
|
+
let { default: corsMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/cors/index.js"));
|
|
6535
|
+
this.middlewares.use(corsMiddleware('boolean' == typeof cors ? {} : cors));
|
|
6536
|
+
}
|
|
6537
|
+
if (proxy) {
|
|
6507
6538
|
let { middlewares, upgrade } = await createProxyMiddleware(proxy);
|
|
6508
6539
|
for (let middleware of middlewares)this.middlewares.use(middleware);
|
|
6509
6540
|
this.app.on('upgrade', upgrade);
|
|
@@ -7045,11 +7076,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7045
7076
|
}
|
|
7046
7077
|
}(), process.title = 'rsbuild-node';
|
|
7047
7078
|
let { npm_execpath } = process.env;
|
|
7048
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.1.
|
|
7079
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.1.11\n`);
|
|
7049
7080
|
}();
|
|
7050
7081
|
try {
|
|
7051
7082
|
!function() {
|
|
7052
|
-
program.name('rsbuild').usage('<command> [options]').version("1.1.
|
|
7083
|
+
program.name('rsbuild').usage('<command> [options]').version("1.1.11");
|
|
7053
7084
|
let devCommand = program.command('dev'), buildCommand = program.command('build'), previewCommand = program.command('preview'), inspectCommand = program.command('inspect');
|
|
7054
7085
|
[
|
|
7055
7086
|
devCommand,
|
|
@@ -7108,7 +7139,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7108
7139
|
rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
|
|
7109
7140
|
}
|
|
7110
7141
|
}
|
|
7111
|
-
let src_rslib_entry_version = "1.1.
|
|
7142
|
+
let src_rslib_entry_version = "1.1.11";
|
|
7112
7143
|
})();
|
|
7113
7144
|
var __webpack_export_target__ = exports;
|
|
7114
7145
|
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
package/dist/index.js
CHANGED
|
@@ -2011,7 +2011,8 @@ let config_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(
|
|
|
2011
2011
|
htmlFallback: 'index',
|
|
2012
2012
|
compress: !0,
|
|
2013
2013
|
printUrls: !0,
|
|
2014
|
-
strictPort: !1
|
|
2014
|
+
strictPort: !1,
|
|
2015
|
+
cors: !0
|
|
2015
2016
|
}), getDefaultSourceConfig = ()=>({
|
|
2016
2017
|
alias: {},
|
|
2017
2018
|
define: {},
|
|
@@ -2646,7 +2647,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
2646
2647
|
async function createContext(options, userConfig, bundlerType) {
|
|
2647
2648
|
let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache');
|
|
2648
2649
|
return {
|
|
2649
|
-
version: "1.1.
|
|
2650
|
+
version: "1.1.11",
|
|
2650
2651
|
rootPath,
|
|
2651
2652
|
distPath: '',
|
|
2652
2653
|
cachePath,
|
|
@@ -2848,7 +2849,10 @@ let pluginAppIcon = ()=>({
|
|
|
2848
2849
|
javascript: {
|
|
2849
2850
|
exportsPresence: 'error'
|
|
2850
2851
|
}
|
|
2851
|
-
}), isDev && config.dev.hmr && 'web' === target && chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin), 'development' === env && chain.output.devtoolModuleFilenameTemplate((info)=>external_node_path_.default.resolve(info.absoluteResourcePath).replace(/\\/g, '/')), process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-unrecognized-keys', process.env.WATCHPACK_WATCHER_LIMIT ||= '20'
|
|
2852
|
+
}), isDev && config.dev.hmr && 'web' === target && chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin), 'development' === env && chain.output.devtoolModuleFilenameTemplate((info)=>external_node_path_.default.resolve(info.absoluteResourcePath).replace(/\\/g, '/')), process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-unrecognized-keys', process.env.WATCHPACK_WATCHER_LIMIT ||= '20', process.env.EXPERIMENTAL_RSPACK_INCREMENTAL && chain.experiments({
|
|
2853
|
+
...chain.get('experiments'),
|
|
2854
|
+
incremental: isDev
|
|
2855
|
+
});
|
|
2852
2856
|
});
|
|
2853
2857
|
}
|
|
2854
2858
|
}), isUseAnalyzer = (config)=>{
|
|
@@ -4531,16 +4535,20 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
|
4531
4535
|
});
|
|
4532
4536
|
}
|
|
4533
4537
|
};
|
|
4534
|
-
api.onAfterStartDevServer(onStartServer), api.onAfterStartProdServer(onStartServer), api.onBeforeBuild(async ({ isFirstCompile })=>{
|
|
4538
|
+
api.onAfterStartDevServer(onStartServer), api.onAfterStartProdServer(onStartServer), api.onBeforeBuild(async ({ isFirstCompile, environments })=>{
|
|
4535
4539
|
if (!!isFirstCompile) for (let publicDir of normalizePublicDirs(api.getNormalizedConfig().server.publicDir)){
|
|
4536
4540
|
let { name, copyOnBuild } = publicDir;
|
|
4537
4541
|
if (!copyOnBuild || !name) continue;
|
|
4538
4542
|
let normalizedPath = (0, external_node_path_.isAbsolute)(name) ? name : (0, external_node_path_.join)(api.context.rootPath, name);
|
|
4539
|
-
if (
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4543
|
+
if (!external_node_fs_.default.existsSync(normalizedPath)) continue;
|
|
4544
|
+
let distPaths = [
|
|
4545
|
+
...new Set(Object.values(environments).map((e)=>e.distPath))
|
|
4546
|
+
];
|
|
4547
|
+
try {
|
|
4548
|
+
await Promise.all(distPaths.map((distPath)=>external_node_fs_.default.promises.cp(normalizedPath, distPath, {
|
|
4549
|
+
recursive: !0,
|
|
4550
|
+
dereference: !0
|
|
4551
|
+
})));
|
|
4544
4552
|
} catch (err) {
|
|
4545
4553
|
throw err instanceof Error && (err.message = `Copy public dir (${normalizedPath}) to dist failed:\n${err.message}`), err;
|
|
4546
4554
|
}
|
|
@@ -5329,7 +5337,11 @@ let isClientCompiler = (compiler)=>{
|
|
|
5329
5337
|
}, setupServerHooks = (compiler, hookCallbacks)=>{
|
|
5330
5338
|
if (isNodeCompiler(compiler)) return;
|
|
5331
5339
|
let { compile, invalid, done } = compiler.hooks;
|
|
5332
|
-
compile.tap('rsbuild-dev-server', ()=>
|
|
5340
|
+
compile.tap('rsbuild-dev-server', ()=>{
|
|
5341
|
+
hookCallbacks.onInvalid(getCompilationId(compiler));
|
|
5342
|
+
}), invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
5343
|
+
hookCallbacks.onInvalid(getCompilationId(compiler), fileName);
|
|
5344
|
+
}), done.tap('rsbuild-dev-server', hookCallbacks.onDone);
|
|
5333
5345
|
}, getDevMiddleware = async (multiCompiler)=>{
|
|
5334
5346
|
let { default: rsbuildDevMiddleware } = await import("../compiled/rsbuild-dev-middleware/index.js");
|
|
5335
5347
|
return (options)=>{
|
|
@@ -5529,7 +5541,14 @@ class CompilerDevMiddleware {
|
|
|
5529
5541
|
publicPath: '/',
|
|
5530
5542
|
stats: !1,
|
|
5531
5543
|
callbacks: {
|
|
5532
|
-
onInvalid: (compilationId)=>{
|
|
5544
|
+
onInvalid: (compilationId, fileName)=>{
|
|
5545
|
+
if ('string' == typeof fileName && HTML_REGEX.test(fileName)) {
|
|
5546
|
+
this.socketServer.sockWrite({
|
|
5547
|
+
type: 'content-changed',
|
|
5548
|
+
compilationId
|
|
5549
|
+
});
|
|
5550
|
+
return;
|
|
5551
|
+
}
|
|
5533
5552
|
this.socketServer.sockWrite({
|
|
5534
5553
|
type: 'invalid',
|
|
5535
5554
|
compilationId
|
|
@@ -6004,7 +6023,11 @@ let run = async (bundlePath, outputPath, compilerOptions, readFileSync)=>new Bas
|
|
|
6004
6023
|
let confHeaders = server.headers;
|
|
6005
6024
|
if (confHeaders) for (let [key, value] of Object.entries(confHeaders))res.setHeader(key, value);
|
|
6006
6025
|
next();
|
|
6007
|
-
}), server.
|
|
6026
|
+
}), server.cors) {
|
|
6027
|
+
let { default: corsMiddleware } = await import("../compiled/cors/index.js");
|
|
6028
|
+
middlewares.push(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
6029
|
+
}
|
|
6030
|
+
if (server.proxy) {
|
|
6008
6031
|
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy);
|
|
6009
6032
|
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.push(middleware);
|
|
6010
6033
|
}
|
|
@@ -6388,13 +6411,17 @@ class RsbuildProdServer {
|
|
|
6388
6411
|
this.app = app, await this.applyDefaultMiddlewares();
|
|
6389
6412
|
}
|
|
6390
6413
|
async applyDefaultMiddlewares() {
|
|
6391
|
-
let { headers, proxy, historyApiFallback, compress, base } = this.options.serverConfig;
|
|
6414
|
+
let { headers, proxy, historyApiFallback, compress, base, cors } = this.options.serverConfig;
|
|
6392
6415
|
if ('verbose' === __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level && this.middlewares.use(await getRequestLoggerMiddleware()), compress && this.middlewares.use(gzipMiddleware({
|
|
6393
6416
|
level: 6
|
|
6394
6417
|
})), headers && this.middlewares.use((_req, res, next)=>{
|
|
6395
6418
|
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
6396
6419
|
next();
|
|
6397
|
-
}),
|
|
6420
|
+
}), cors) {
|
|
6421
|
+
let { default: corsMiddleware } = await import("../compiled/cors/index.js");
|
|
6422
|
+
this.middlewares.use(corsMiddleware('boolean' == typeof cors ? {} : cors));
|
|
6423
|
+
}
|
|
6424
|
+
if (proxy) {
|
|
6398
6425
|
let { middlewares, upgrade } = await createProxyMiddleware(proxy);
|
|
6399
6426
|
for (let middleware of middlewares)this.middlewares.use(middleware);
|
|
6400
6427
|
this.app.on('upgrade', upgrade);
|
|
@@ -6936,11 +6963,11 @@ async function runCLI() {
|
|
|
6936
6963
|
}
|
|
6937
6964
|
}(), process.title = 'rsbuild-node';
|
|
6938
6965
|
let { npm_execpath } = process.env;
|
|
6939
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rsbuild v1.1.
|
|
6966
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rsbuild v1.1.11\n`);
|
|
6940
6967
|
}();
|
|
6941
6968
|
try {
|
|
6942
6969
|
!function() {
|
|
6943
|
-
program.name('rsbuild').usage('<command> [options]').version("1.1.
|
|
6970
|
+
program.name('rsbuild').usage('<command> [options]').version("1.1.11");
|
|
6944
6971
|
let devCommand = program.command('dev'), buildCommand = program.command('build'), previewCommand = program.command('preview'), inspectCommand = program.command('inspect');
|
|
6945
6972
|
[
|
|
6946
6973
|
devCommand,
|
|
@@ -6999,6 +7026,6 @@ async function runCLI() {
|
|
|
6999
7026
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to start Rsbuild CLI.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
|
|
7000
7027
|
}
|
|
7001
7028
|
}
|
|
7002
|
-
let src_version = "1.1.
|
|
7029
|
+
let src_version = "1.1.11";
|
|
7003
7030
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core__.rspack;
|
|
7004
7031
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, internal_namespaceObject as __internalHelper, createRsbuild, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
|
package/dist/transformLoader.mjs
CHANGED
|
@@ -10,8 +10,9 @@ async function transformLoader_rslib_entry_transform(source, map) {
|
|
|
10
10
|
resourcePath: this.resourcePath,
|
|
11
11
|
resourceQuery: this.resourceQuery,
|
|
12
12
|
environment: getEnvironment(),
|
|
13
|
-
addDependency: this.addDependency,
|
|
14
|
-
emitFile: this.emitFile
|
|
13
|
+
addDependency: this.addDependency.bind(this),
|
|
14
|
+
emitFile: this.emitFile.bind(this),
|
|
15
|
+
importModule: this.importModule.bind(this)
|
|
15
16
|
});
|
|
16
17
|
if (null == result) return bypass();
|
|
17
18
|
if ('string' == typeof result) return callback(null, result, map);
|
|
@@ -10,8 +10,9 @@ let transformRawLoader_rslib_entry_ = async function transformLoader_transform(s
|
|
|
10
10
|
resourcePath: this.resourcePath,
|
|
11
11
|
resourceQuery: this.resourceQuery,
|
|
12
12
|
environment: getEnvironment(),
|
|
13
|
-
addDependency: this.addDependency,
|
|
14
|
-
emitFile: this.emitFile
|
|
13
|
+
addDependency: this.addDependency.bind(this),
|
|
14
|
+
emitFile: this.emitFile.bind(this),
|
|
15
|
+
importModule: this.importModule.bind(this)
|
|
15
16
|
});
|
|
16
17
|
if (null == result) return bypass();
|
|
17
18
|
if ('string' == typeof result) return callback(null, result, map);
|
|
@@ -3,7 +3,7 @@ import type { Compiler, MultiCompiler } from '@rspack/core';
|
|
|
3
3
|
import type { DevMiddlewareOptions } from '../provider/createCompiler';
|
|
4
4
|
import type { NextFunction } from '../types';
|
|
5
5
|
type ServerCallbacks = {
|
|
6
|
-
onInvalid: (compilationId?: string) => void;
|
|
6
|
+
onInvalid: (compilationId?: string, fileName?: string | null) => void;
|
|
7
7
|
onDone: (stats: any) => void;
|
|
8
8
|
};
|
|
9
9
|
export declare const isClientCompiler: (compiler: {
|
|
@@ -3,6 +3,7 @@ import type { SecureServerSessionOptions } from 'node:http2';
|
|
|
3
3
|
import type { ServerOptions as HttpsServerOptions } from 'node:https';
|
|
4
4
|
import type { Configuration, CopyRspackPluginOptions, Externals, LightningCssMinimizerRspackPluginOptions, ModuleFederationPluginOptions, RuleSetCondition, SwcJsMinimizerRspackPluginOptions, SwcLoaderOptions, rspack } from '@rspack/core';
|
|
5
5
|
import type { ChokidarOptions } from '../../compiled/chokidar/index.js';
|
|
6
|
+
import type cors from '../../compiled/cors/index.js';
|
|
6
7
|
import type { Options as HttpProxyOptions, Filter as ProxyFilter } from '../../compiled/http-proxy-middleware/index.js';
|
|
7
8
|
import type RspackChain from '../../compiled/rspack-chain/index.js';
|
|
8
9
|
import type { BundleAnalyzerPlugin } from '../../compiled/webpack-bundle-analyzer/index.js';
|
|
@@ -275,6 +276,15 @@ export interface ServerConfig {
|
|
|
275
276
|
target?: string | string[];
|
|
276
277
|
before?: () => Promise<void> | void;
|
|
277
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Configure CORS for the dev server or preview server.
|
|
281
|
+
* - true: enable CORS with default options.
|
|
282
|
+
* - false: disable CORS.
|
|
283
|
+
* - object: enable CORS with the specified options.
|
|
284
|
+
* @default true
|
|
285
|
+
* @link https://github.com/expressjs/cors
|
|
286
|
+
*/
|
|
287
|
+
cors?: boolean | cors.CorsOptions;
|
|
278
288
|
/**
|
|
279
289
|
* Configure proxy rules for the dev server or preview server to proxy requests to the specified service.
|
|
280
290
|
*/
|
|
@@ -288,7 +298,7 @@ export interface ServerConfig {
|
|
|
288
298
|
*/
|
|
289
299
|
printUrls?: PrintUrls;
|
|
290
300
|
}
|
|
291
|
-
export type NormalizedServerConfig = ServerConfig & Required<Pick<ServerConfig, 'htmlFallback' | 'port' | 'host' | 'compress' | 'strictPort' | 'printUrls' | 'open' | 'base'>>;
|
|
301
|
+
export type NormalizedServerConfig = ServerConfig & Required<Pick<ServerConfig, 'htmlFallback' | 'port' | 'host' | 'compress' | 'strictPort' | 'printUrls' | 'open' | 'base' | 'cors'>>;
|
|
292
302
|
export type SriAlgorithm = 'sha256' | 'sha384' | 'sha512';
|
|
293
303
|
export type SriOptions = {
|
|
294
304
|
algorithm?: SriAlgorithm;
|
|
@@ -180,7 +180,11 @@ export type TransformContext = {
|
|
|
180
180
|
* @param sourceMap source map of the asset
|
|
181
181
|
* @param assetInfo additional asset information
|
|
182
182
|
*/
|
|
183
|
-
emitFile:
|
|
183
|
+
emitFile: Rspack.LoaderContext['emitFile'];
|
|
184
|
+
/**
|
|
185
|
+
* Compile and execute a module at the build time.
|
|
186
|
+
*/
|
|
187
|
+
importModule: Rspack.LoaderContext['importModule'];
|
|
184
188
|
};
|
|
185
189
|
export type TransformHandler = (context: TransformContext) => MaybePromise<TransformResult>;
|
|
186
190
|
export type TransformDescriptor = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "The Rspack-based build tool.",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"types.d.ts"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@rspack/core": "
|
|
49
|
+
"@rspack/core": "1.1.8",
|
|
50
50
|
"@rspack/lite-tapable": "~1.0.1",
|
|
51
51
|
"@swc/helpers": "^0.5.15",
|
|
52
52
|
"core-js": "~3.39.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@rslib/core": "0.1.
|
|
55
|
+
"@rslib/core": "0.1.4",
|
|
56
56
|
"@types/connect": "3.4.38",
|
|
57
|
-
"@types/node": "^22.10.
|
|
57
|
+
"@types/node": "^22.10.2",
|
|
58
58
|
"@types/on-finished": "2.3.4",
|
|
59
59
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
60
60
|
"@types/ws": "^8.5.13",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"commander": "^12.1.0",
|
|
64
64
|
"connect": "3.7.0",
|
|
65
65
|
"connect-history-api-fallback": "^2.0.0",
|
|
66
|
+
"cors": "^2.8.5",
|
|
66
67
|
"css-loader": "7.1.2",
|
|
67
68
|
"deepmerge": "^4.3.1",
|
|
68
69
|
"dotenv": "16.4.7",
|