@rsbuild/core 2.1.1 → 2.1.3
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/postcss-loader/index.js +6 -6
- package/dist/756.js +135 -84
- package/dist/client/hmr.js +1 -1
- package/dist/cssUrlLoader.mjs +1 -1
- package/dist/fresh-import.js +90 -0
- package/dist/{rspack-manifest-plugin.js → manifest-plugin.js} +6 -6
- package/dist-types/cli/commands.d.ts +4 -1
- package/dist-types/cli/index.d.ts +7 -1
- package/dist-types/cli/init.d.ts +3 -2
- package/dist-types/configChain.d.ts +3 -0
- package/dist-types/index.d.ts +2 -2
- package/dist-types/loadConfig.d.ts +15 -3
- package/dist-types/plugins/fileSize.d.ts +1 -1
- package/dist-types/types/config.d.ts +1 -1
- package/package.json +4 -3
- /package/dist/{build.js → sirv.js} +0 -0
- /package/dist/{wrapper.js → ws.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
|
|
3
|
+
776: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
4
4
|
"use strict";
|
|
5
|
-
const { HtmlWebpackChildCompiler } = __nccwpck_require__(
|
|
5
|
+
const { HtmlWebpackChildCompiler } = __nccwpck_require__(469);
|
|
6
6
|
const compilerMap = new WeakMap();
|
|
7
7
|
class CachedChildCompilation {
|
|
8
8
|
constructor(compiler) {
|
|
@@ -311,7 +311,7 @@
|
|
|
311
311
|
}
|
|
312
312
|
module.exports = { CachedChildCompilation };
|
|
313
313
|
},
|
|
314
|
-
|
|
314
|
+
469: (module) => {
|
|
315
315
|
"use strict";
|
|
316
316
|
class HtmlWebpackChildCompiler {
|
|
317
317
|
constructor(templates) {
|
|
@@ -480,7 +480,7 @@
|
|
|
480
480
|
}
|
|
481
481
|
module.exports = { HtmlWebpackChildCompiler };
|
|
482
482
|
},
|
|
483
|
-
|
|
483
|
+
67: (module) => {
|
|
484
484
|
"use strict";
|
|
485
485
|
module.exports = {};
|
|
486
486
|
module.exports.none = (chunks) => chunks;
|
|
@@ -499,7 +499,7 @@
|
|
|
499
499
|
};
|
|
500
500
|
module.exports.auto = module.exports.none;
|
|
501
501
|
},
|
|
502
|
-
|
|
502
|
+
262: (module) => {
|
|
503
503
|
"use strict";
|
|
504
504
|
module.exports = function (err) {
|
|
505
505
|
return {
|
|
@@ -523,7 +523,7 @@
|
|
|
523
523
|
};
|
|
524
524
|
};
|
|
525
525
|
},
|
|
526
|
-
|
|
526
|
+
917: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
527
527
|
"use strict";
|
|
528
528
|
const { AsyncSeriesWaterfallHook } = __nccwpck_require__(159);
|
|
529
529
|
const htmlWebpackPluginHooksMap = new WeakMap();
|
|
@@ -549,7 +549,7 @@
|
|
|
549
549
|
}
|
|
550
550
|
module.exports = { getHtmlRspackPluginHooks };
|
|
551
551
|
},
|
|
552
|
-
|
|
552
|
+
492: (module) => {
|
|
553
553
|
const voidTags = [
|
|
554
554
|
"area",
|
|
555
555
|
"base",
|
|
@@ -617,19 +617,19 @@
|
|
|
617
617
|
htmlTagObjectToString,
|
|
618
618
|
};
|
|
619
619
|
},
|
|
620
|
-
|
|
620
|
+
345: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
621
621
|
"use strict";
|
|
622
622
|
const promisify = __nccwpck_require__(23).promisify;
|
|
623
623
|
const vm = __nccwpck_require__(154);
|
|
624
624
|
const fs = __nccwpck_require__(896);
|
|
625
625
|
const path = __nccwpck_require__(928);
|
|
626
|
-
const { CachedChildCompilation } = __nccwpck_require__(
|
|
626
|
+
const { CachedChildCompilation } = __nccwpck_require__(776);
|
|
627
627
|
const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } =
|
|
628
|
-
__nccwpck_require__(
|
|
629
|
-
const prettyError = __nccwpck_require__(
|
|
630
|
-
const chunkSorter = __nccwpck_require__(
|
|
628
|
+
__nccwpck_require__(492);
|
|
629
|
+
const prettyError = __nccwpck_require__(262);
|
|
630
|
+
const chunkSorter = __nccwpck_require__(67);
|
|
631
631
|
const getHtmlRspackPluginHooks =
|
|
632
|
-
__nccwpck_require__(
|
|
632
|
+
__nccwpck_require__(917).getHtmlRspackPluginHooks;
|
|
633
633
|
const WITH_PLACEHOLDER = "function __with_placeholder__";
|
|
634
634
|
class HtmlRspackPlugin {
|
|
635
635
|
constructor(userOptions = {}) {
|
|
@@ -2398,6 +2398,6 @@
|
|
|
2398
2398
|
}
|
|
2399
2399
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
2400
2400
|
__nccwpck_require__.ab = __dirname + "/";
|
|
2401
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
2401
|
+
var __webpack_exports__ = __nccwpck_require__(345);
|
|
2402
2402
|
module.exports = __webpack_exports__;
|
|
2403
2403
|
})();
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
"use strict";
|
|
3
3
|
var __webpack_modules__ = {
|
|
4
|
-
|
|
5
|
-
module.exports = __nccwpck_require__(
|
|
4
|
+
69: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
5
|
+
module.exports = __nccwpck_require__(487)["default"];
|
|
6
6
|
},
|
|
7
|
-
|
|
7
|
+
487: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
8
8
|
var __webpack_unused_export__;
|
|
9
9
|
__webpack_unused_export__ = { value: true };
|
|
10
10
|
exports["default"] = loader;
|
|
11
11
|
var _nodePath = _interopRequireDefault(__nccwpck_require__(760));
|
|
12
|
-
var _utils = __nccwpck_require__(
|
|
12
|
+
var _utils = __nccwpck_require__(474);
|
|
13
13
|
function _interopRequireDefault(e) {
|
|
14
14
|
return e && e.__esModule ? e : { default: e };
|
|
15
15
|
}
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
callback(null, result.css, map, { ast });
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
|
-
|
|
182
|
+
474: (module, exports, __nccwpck_require__) => {
|
|
183
183
|
module = __nccwpck_require__.nmd(module);
|
|
184
184
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
185
185
|
exports.exec = exec;
|
|
@@ -716,6 +716,6 @@
|
|
|
716
716
|
})();
|
|
717
717
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
718
718
|
__nccwpck_require__.ab = __dirname + "/";
|
|
719
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
719
|
+
var __webpack_exports__ = __nccwpck_require__(69);
|
|
720
720
|
module.exports = __webpack_exports__;
|
|
721
721
|
})();
|
package/dist/756.js
CHANGED
|
@@ -13,6 +13,7 @@ import { isPromise, isRegExp } from "node:util/types";
|
|
|
13
13
|
import { readFile } from "node:fs/promises";
|
|
14
14
|
import node_zlib from "node:zlib";
|
|
15
15
|
import { __webpack_require__ } from "./1~rslib-runtime.js";
|
|
16
|
+
var superClass, superClass1, __rspack_import_meta_filename__ = __rspack_fileURLToPath(import.meta.url);
|
|
16
17
|
let __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
17
18
|
__webpack_require__.add({
|
|
18
19
|
"../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js" (module) {
|
|
@@ -499,10 +500,8 @@ __webpack_require__.add({
|
|
|
499
500
|
};
|
|
500
501
|
},
|
|
501
502
|
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
502
|
-
let tsx, jiti;
|
|
503
|
-
|
|
504
|
-
let { createRequire } = __webpack_require__("node:module?1bcb"), { pathToFileURL } = __webpack_require__("node:url?b4ec"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
505
|
-
module.exports = async function req(name, rootFile = __filename) {
|
|
503
|
+
let tsx, jiti, { createRequire } = __webpack_require__("node:module?1bcb"), { pathToFileURL } = __webpack_require__("node:url?b4ec"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
504
|
+
module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
|
|
506
505
|
let url = createRequire(rootFile).resolve(name);
|
|
507
506
|
try {
|
|
508
507
|
return (await import(`${pathToFileURL(url)}?t=${Date.now()}`)).default;
|
|
@@ -935,7 +934,7 @@ function getFileName(input) {
|
|
|
935
934
|
function camelcaseOptionName(name) {
|
|
936
935
|
return name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
|
|
937
936
|
}
|
|
938
|
-
var
|
|
937
|
+
var CACError = class extends Error {
|
|
939
938
|
constructor(message){
|
|
940
939
|
super(message), this.name = "CACError", "function" != typeof Error.captureStackTrace && (this.stack = Error(message).stack);
|
|
941
940
|
}
|
|
@@ -2385,7 +2384,7 @@ function formatModuleTrace(stats, errorFile, level, logger) {
|
|
|
2385
2384
|
let trace = moduleNames.slice().reverse();
|
|
2386
2385
|
return trace.length > 4 && !isVerbose(logger) && (trace = [
|
|
2387
2386
|
...trace.slice(0, 2),
|
|
2388
|
-
|
|
2387
|
+
`... (${trace.length - 2 - 2} hidden)`,
|
|
2389
2388
|
...trace.slice(trace.length - 2)
|
|
2390
2389
|
]), color.dim(`Import traces (entry → ${level}):\n ${trace.join('\n ')} ${color.bold(color.red('×'))}`);
|
|
2391
2390
|
}
|
|
@@ -3501,7 +3500,7 @@ function createPublicContext(context) {
|
|
|
3501
3500
|
async function createContext(options, userConfig, logger) {
|
|
3502
3501
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
3503
3502
|
return {
|
|
3504
|
-
version: "2.1.
|
|
3503
|
+
version: "2.1.3",
|
|
3505
3504
|
rootPath,
|
|
3506
3505
|
distPath: '',
|
|
3507
3506
|
cachePath,
|
|
@@ -3779,12 +3778,15 @@ let configChain_CHAIN_ID = {
|
|
|
3779
3778
|
JS_MAIN: 'js',
|
|
3780
3779
|
JS_WORKER: 'js-worker',
|
|
3781
3780
|
JS_RAW: 'js-raw',
|
|
3781
|
+
JS_TEXT: 'js-text',
|
|
3782
3782
|
CSS_MAIN: 'css',
|
|
3783
3783
|
CSS_RAW: 'css-raw',
|
|
3784
|
+
CSS_TEXT: 'css-text',
|
|
3784
3785
|
CSS_URL: 'css-url',
|
|
3785
3786
|
CSS_INLINE: 'css-inline',
|
|
3786
3787
|
SVG: 'svg',
|
|
3787
3788
|
SVG_RAW: 'svg-asset-raw',
|
|
3789
|
+
SVG_TEXT: 'svg-asset-text',
|
|
3788
3790
|
SVG_URL: 'svg-asset-url',
|
|
3789
3791
|
SVG_ASSET: 'svg-asset',
|
|
3790
3792
|
SVG_REACT: 'svg-react',
|
|
@@ -4818,7 +4820,9 @@ let chainStaticAssetRule = ({ emit, rule, maxSize, filename, assetType })=>{
|
|
|
4818
4820
|
let generatorOptions = {
|
|
4819
4821
|
filename
|
|
4820
4822
|
};
|
|
4821
|
-
emit || (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(URL_QUERY_REGEX).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(INLINE_QUERY_REGEX), rule.oneOf(`${assetType}-asset-
|
|
4823
|
+
emit || (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(URL_QUERY_REGEX).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(INLINE_QUERY_REGEX), rule.oneOf(`${assetType}-asset-text`).type('asset/source').with({
|
|
4824
|
+
type: 'text'
|
|
4825
|
+
}), rule.oneOf(`${assetType}-asset-raw`).type('asset/source').resourceQuery(RAW_QUERY_REGEX), rule.oneOf(`${assetType}-asset`).type('asset').parser({
|
|
4822
4826
|
dataUrlCondition: {
|
|
4823
4827
|
maxSize
|
|
4824
4828
|
}
|
|
@@ -5151,7 +5155,7 @@ async function saveSnapshots(snapshotPath, snapshots, logger) {
|
|
|
5151
5155
|
logger.debug('Failed to save file size snapshots:', err);
|
|
5152
5156
|
}
|
|
5153
5157
|
}
|
|
5154
|
-
let EXCLUDE_ASSET_REGEX = /\.(?:map|LICENSE\.txt|d\.ts)$/, isSignificantDiff = (diff)=>Math.abs(diff) >= 10, formatDiff = (diff)=>{
|
|
5158
|
+
let EXCLUDE_ASSET_REGEX = /\.(?:map|LICENSE\.txt|d\.(?:ts|mts|cts))$/, isSignificantDiff = (diff)=>Math.abs(diff) >= 10, formatDiff = (diff)=>{
|
|
5155
5159
|
let label = `(${diff > 0 ? '+' : '-'}${calcFileSize(Math.abs(diff))})`;
|
|
5156
5160
|
return {
|
|
5157
5161
|
label: (diff > 0 ? color.red : color.green)(label),
|
|
@@ -5176,7 +5180,7 @@ function getHeader(maxFileLength, maxSizeLength, fileHeader, showGzipHeader) {
|
|
|
5176
5180
|
let calcFileSize = (len)=>{
|
|
5177
5181
|
let val = len / 1000;
|
|
5178
5182
|
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
5179
|
-
}, COMPRESSIBLE_REGEX = /\.(?:js|css|html|json|svg|txt|xml|xhtml|wasm|manifest|md)$/i, isCompressible = (assetName)=>COMPRESSIBLE_REGEX.test(assetName), getFilePath = (assetName)=>{
|
|
5183
|
+
}, COMPRESSIBLE_REGEX = /\.(?:js|mjs|cjs|jsx|ts|tsx|mts|cts|css|html|json|svg|txt|xml|xhtml|wasm|manifest|md)$/i, isCompressible = (assetName)=>COMPRESSIBLE_REGEX.test(assetName), getFilePath = (assetName)=>{
|
|
5180
5184
|
let queryIndex = assetName.indexOf('?');
|
|
5181
5185
|
return -1 === queryIndex ? assetName : assetName.slice(0, queryIndex);
|
|
5182
5186
|
};
|
|
@@ -5824,7 +5828,8 @@ let supportedChromiumBrowsers = [
|
|
|
5824
5828
|
'Microsoft Edge',
|
|
5825
5829
|
'Brave Browser',
|
|
5826
5830
|
'Vivaldi',
|
|
5827
|
-
'Chromium'
|
|
5831
|
+
'Chromium',
|
|
5832
|
+
'Helium'
|
|
5828
5833
|
], mapChromiumBrowserName = (browser)=>'chrome' === browser || 'google chrome' === browser ? 'Google Chrome' : browser;
|
|
5829
5834
|
async function openBrowser(url, logger) {
|
|
5830
5835
|
let browser = process.env.BROWSER, browserArgs = process.env.BROWSER_ARGS;
|
|
@@ -7115,7 +7120,7 @@ class SocketServer {
|
|
|
7115
7120
|
}
|
|
7116
7121
|
async prepare() {
|
|
7117
7122
|
this.clearHeartbeatTimer();
|
|
7118
|
-
let { WebSocketServer } = await import("./
|
|
7123
|
+
let { WebSocketServer } = await import("./ws.js");
|
|
7119
7124
|
this.wsServer = new WebSocketServer({
|
|
7120
7125
|
noServer: !0,
|
|
7121
7126
|
path: this.options.client?.path
|
|
@@ -7705,7 +7710,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
|
|
|
7705
7710
|
],
|
|
7706
7711
|
outputFileSystem: buildManager.outputFileSystem
|
|
7707
7712
|
})), server.publicDir.length) {
|
|
7708
|
-
let { default: sirv } = await import("./
|
|
7713
|
+
let { default: sirv } = await import("./sirv.js");
|
|
7709
7714
|
for (let { name } of server.publicDir){
|
|
7710
7715
|
let sirvMiddleware = sirv(name, {
|
|
7711
7716
|
etag: !0,
|
|
@@ -8580,7 +8585,11 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8580
8585
|
} : posix.join(jsPath, jsFilename)).chunkFilename(isJsFilenameFn ? (...args)=>{
|
|
8581
8586
|
let name = jsFilename(...args);
|
|
8582
8587
|
return posix.join(jsAsyncPath, name);
|
|
8583
|
-
} : posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath)
|
|
8588
|
+
} : posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath), ('web' === target || 'web-worker' === target) && chain.output.merge({
|
|
8589
|
+
environment: {
|
|
8590
|
+
const: !1
|
|
8591
|
+
}
|
|
8592
|
+
});
|
|
8584
8593
|
let isESM = config.output.module;
|
|
8585
8594
|
if (isServer && chain.output.library({
|
|
8586
8595
|
...chain.output.get('library') || {},
|
|
@@ -8733,7 +8742,11 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8733
8742
|
], emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.MEDIA, [
|
|
8734
8743
|
...VIDEO_EXTENSIONS,
|
|
8735
8744
|
...AUDIO_EXTENSIONS
|
|
8736
|
-
], emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.FONT, FONT_EXTENSIONS, emitAssets)
|
|
8745
|
+
], emitAssets), createAssetRule(configChain_CHAIN_ID.RULE.FONT, FONT_EXTENSIONS, emitAssets);
|
|
8746
|
+
let rule = chain.module.rule(configChain_CHAIN_ID.RULE.JSON).test(/\.json$/i);
|
|
8747
|
+
rule.oneOf('json-asset-text').type('asset/source').with({
|
|
8748
|
+
type: 'text'
|
|
8749
|
+
}), rule.oneOf('json-asset-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEX);
|
|
8737
8750
|
let assetsFilename = getMergedFilename('assets');
|
|
8738
8751
|
chain.output.assetModuleFilename(assetsFilename), emitAssets || chain.module.generator.merge({
|
|
8739
8752
|
'asset/resource': {
|
|
@@ -9031,7 +9044,9 @@ try {
|
|
|
9031
9044
|
let cssRule = chain.module.rule(CHAIN_ID.RULE.CSS), { config } = environment;
|
|
9032
9045
|
cssRule.test(CSS_REGEX).dependency({
|
|
9033
9046
|
not: 'url'
|
|
9034
|
-
})
|
|
9047
|
+
}), cssRule.oneOf(CHAIN_ID.ONE_OF.CSS_TEXT).with({
|
|
9048
|
+
type: 'text'
|
|
9049
|
+
}).type('asset/source');
|
|
9035
9050
|
let urlRule = cssRule.oneOf(CHAIN_ID.ONE_OF.CSS_URL).resourceQuery(URL_QUERY_REGEX);
|
|
9036
9051
|
urlRule.use(CHAIN_ID.USE.CSS_URL).loader(node_path.join(dirname, 'cssUrlLoader.mjs'));
|
|
9037
9052
|
let inlineRule = cssRule.oneOf(CHAIN_ID.ONE_OF.CSS_INLINE).resourceQuery(INLINE_QUERY_REGEX);
|
|
@@ -9191,7 +9206,9 @@ try {
|
|
|
9191
9206
|
let { config, browserslist } = environment, cacheRoot = node_path.join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).dependency({
|
|
9192
9207
|
not: 'url'
|
|
9193
9208
|
});
|
|
9194
|
-
rule.oneOf(CHAIN_ID.ONE_OF.
|
|
9209
|
+
rule.oneOf(CHAIN_ID.ONE_OF.JS_TEXT).with({
|
|
9210
|
+
type: 'text'
|
|
9211
|
+
}).type('asset/source'), rule.oneOf(CHAIN_ID.ONE_OF.JS_RAW).resourceQuery(RAW_QUERY_REGEX).type('asset/source');
|
|
9195
9212
|
let mainRule = rule.oneOf(CHAIN_ID.ONE_OF.JS_MAIN).type("javascript/auto"), dataUriRule = chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
9196
9213
|
or: [
|
|
9197
9214
|
"text/javascript",
|
|
@@ -9493,7 +9510,7 @@ try {
|
|
|
9493
9510
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev })=>{
|
|
9494
9511
|
let { output: { manifest }, dev: { writeToDisk } } = environment.config;
|
|
9495
9512
|
if (!1 === manifest) return;
|
|
9496
|
-
let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./
|
|
9513
|
+
let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
|
|
9497
9514
|
manifestFilenames.set(environment.name, manifestOptions.filename);
|
|
9498
9515
|
let pluginOptions = {
|
|
9499
9516
|
fileName: manifestOptions.filename,
|
|
@@ -9649,7 +9666,7 @@ try {
|
|
|
9649
9666
|
nonces.some((nonce)=>!!nonce) && applyToCompiler(compiler, (compiler, index)=>{
|
|
9650
9667
|
let nonce = nonces[index], environment = environmentList.find((item)=>item.index === index);
|
|
9651
9668
|
if (!Object.keys(environment?.htmlPaths ?? {}).length || !nonce) return;
|
|
9652
|
-
let injectCode = createVirtualModule(`
|
|
9669
|
+
let injectCode = createVirtualModule(`import.meta.rspackNonce = ${JSON.stringify(nonce)};`);
|
|
9653
9670
|
new core_rspack.EntryPlugin(compiler.context, injectCode, {
|
|
9654
9671
|
name: void 0
|
|
9655
9672
|
}).apply(compiler);
|
|
@@ -9850,36 +9867,53 @@ async function createRsbuild(options = {}) {
|
|
|
9850
9867
|
function defineConfig(config) {
|
|
9851
9868
|
return config;
|
|
9852
9869
|
}
|
|
9853
|
-
|
|
9854
|
-
|
|
9870
|
+
let DEFAULT_CONFIG_FILE_NAMES = [
|
|
9871
|
+
'rsbuild.config.ts',
|
|
9872
|
+
'rsbuild.config.js',
|
|
9873
|
+
'rsbuild.config.mts',
|
|
9874
|
+
'rsbuild.config.mjs',
|
|
9875
|
+
'rsbuild.config.cts',
|
|
9876
|
+
'rsbuild.config.cjs'
|
|
9877
|
+
], getConfigExport = (module)=>module && 'object' == typeof module && 'default' in module ? module.default : module, tryFreshImport = async (configFileURL)=>{
|
|
9878
|
+
try {
|
|
9879
|
+
let { freshImport } = await import("./fresh-import.js");
|
|
9880
|
+
return await freshImport(configFileURL);
|
|
9881
|
+
} catch (err) {
|
|
9882
|
+
src_logger.debug('failed to initialize fresh-import, fallback to dynamic import.'), src_logger.debug(err);
|
|
9883
|
+
}
|
|
9884
|
+
}, loadConfigWithNative = async (configFilePath)=>{
|
|
9885
|
+
let configFileURL = pathToFileURL(configFilePath).href, freshImportResult = await tryFreshImport(configFileURL);
|
|
9886
|
+
return freshImportResult ? {
|
|
9887
|
+
configExport: getConfigExport(freshImportResult.result),
|
|
9888
|
+
dependencies: freshImportResult.dependencies.sort()
|
|
9889
|
+
} : {
|
|
9890
|
+
configExport: getConfigExport(await import(`${configFileURL}?t=${Date.now()}`)),
|
|
9891
|
+
dependencies: []
|
|
9892
|
+
};
|
|
9893
|
+
};
|
|
9894
|
+
async function loadConfig_loadConfig({ cwd = process.cwd(), path, configFileNames, envMode, meta, loader = 'auto', command } = {}) {
|
|
9895
|
+
let configExport, configFilePath = ((root, customConfig, configFileNames = DEFAULT_CONFIG_FILE_NAMES)=>{
|
|
9855
9896
|
if (customConfig) {
|
|
9856
9897
|
let customConfigPath = external_node_path_isAbsolute(customConfig) ? customConfig : join(root, customConfig);
|
|
9857
9898
|
if (node_fs.existsSync(customConfigPath)) return customConfigPath;
|
|
9858
|
-
throw Error(
|
|
9859
|
-
}
|
|
9860
|
-
for (let file of
|
|
9861
|
-
'rsbuild.config.ts',
|
|
9862
|
-
'rsbuild.config.js',
|
|
9863
|
-
'rsbuild.config.mts',
|
|
9864
|
-
'rsbuild.config.mjs',
|
|
9865
|
-
'rsbuild.config.cts',
|
|
9866
|
-
'rsbuild.config.cjs'
|
|
9867
|
-
]){
|
|
9899
|
+
throw Error(`Cannot find config file: ${color.dim(customConfigPath)}`);
|
|
9900
|
+
}
|
|
9901
|
+
for (let file of configFileNames){
|
|
9868
9902
|
let configFile = join(root, file);
|
|
9869
9903
|
if (node_fs.existsSync(configFile)) return configFile;
|
|
9870
9904
|
}
|
|
9871
9905
|
return null;
|
|
9872
|
-
})(cwd, path);
|
|
9906
|
+
})(cwd, path, configFileNames);
|
|
9873
9907
|
if (!configFilePath) return src_logger.debug('no config file found.'), {
|
|
9874
9908
|
content: {},
|
|
9875
|
-
filePath: configFilePath
|
|
9909
|
+
filePath: configFilePath,
|
|
9910
|
+
dependencies: []
|
|
9876
9911
|
};
|
|
9877
|
-
let applyMetaInfo = (config)=>(config._privateMeta = {
|
|
9912
|
+
let dependencies = [], applyMetaInfo = (config)=>(config._privateMeta = {
|
|
9878
9913
|
configFilePath
|
|
9879
9914
|
}, config);
|
|
9880
9915
|
if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || /\.(?:js|mjs|cjs)$/.test(configFilePath)) try {
|
|
9881
|
-
|
|
9882
|
-
configExport = exportModule.default ? exportModule.default : exportModule;
|
|
9916
|
+
({ configExport, dependencies } = await loadConfigWithNative(configFilePath));
|
|
9883
9917
|
} catch (err) {
|
|
9884
9918
|
let errorMessage = `Failed to load file with native loader: ${color.dim(configFilePath)}`;
|
|
9885
9919
|
if ('native' === loader) throw src_logger.error(errorMessage), err;
|
|
@@ -9900,51 +9934,75 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta,
|
|
|
9900
9934
|
throw src_logger.error(`Failed to load file with jiti: ${color.dim(configFilePath)}`), err;
|
|
9901
9935
|
}
|
|
9902
9936
|
if ('function' == typeof configExport) {
|
|
9903
|
-
let
|
|
9937
|
+
let nodeEnv = process.env.NODE_ENV || '', configParams = {
|
|
9904
9938
|
env: nodeEnv,
|
|
9905
|
-
command,
|
|
9939
|
+
command: command ?? process.argv[2],
|
|
9906
9940
|
envMode: envMode || nodeEnv,
|
|
9907
9941
|
meta
|
|
9908
|
-
});
|
|
9942
|
+
}, result = await configExport(configParams);
|
|
9909
9943
|
if (void 0 === result) throw Error(`${color.dim('[rsbuild:loadConfig]')} The config function must return a config object.`);
|
|
9910
9944
|
return {
|
|
9911
9945
|
content: applyMetaInfo(result),
|
|
9912
|
-
filePath: configFilePath
|
|
9946
|
+
filePath: configFilePath,
|
|
9947
|
+
dependencies
|
|
9913
9948
|
};
|
|
9914
9949
|
}
|
|
9915
9950
|
if (!isObject(configExport)) throw Error(`${color.dim('[rsbuild:loadConfig]')} The config must be an object or a function that returns an object, get ${color.yellow(configExport)}`);
|
|
9916
9951
|
return src_logger.debug('configuration loaded from:', configFilePath), {
|
|
9917
9952
|
content: applyMetaInfo(configExport),
|
|
9918
|
-
filePath: configFilePath
|
|
9953
|
+
filePath: configFilePath,
|
|
9954
|
+
dependencies
|
|
9919
9955
|
};
|
|
9920
9956
|
}
|
|
9921
|
-
let
|
|
9922
|
-
|
|
9957
|
+
let cliState = {
|
|
9958
|
+
options: {}
|
|
9959
|
+
}, initCliAction = (command, options)=>{
|
|
9960
|
+
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;
|
|
9961
|
+
}, init_loadConfig = async (root)=>{
|
|
9962
|
+
let { options, command } = cliState, { content: config, filePath, dependencies } = await loadConfig_loadConfig({
|
|
9923
9963
|
cwd: root,
|
|
9924
|
-
path:
|
|
9925
|
-
envMode:
|
|
9926
|
-
loader:
|
|
9964
|
+
path: options.config,
|
|
9965
|
+
envMode: options.envMode,
|
|
9966
|
+
loader: options.configLoader,
|
|
9967
|
+
command
|
|
9927
9968
|
});
|
|
9928
|
-
|
|
9969
|
+
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), options.port && (config.server.port = options.port), void 0 !== options.strictPort && (config.server.strictPort = options.strictPort), void 0 !== options.distPath) {
|
|
9970
|
+
config.output ||= {};
|
|
9971
|
+
let { distPath } = config.output;
|
|
9972
|
+
config.output.distPath = distPath && 'object' == typeof distPath ? {
|
|
9973
|
+
...distPath,
|
|
9974
|
+
root: options.distPath
|
|
9975
|
+
} : {
|
|
9976
|
+
root: options.distPath
|
|
9977
|
+
};
|
|
9978
|
+
}
|
|
9979
|
+
if (void 0 !== options.sourceMap) {
|
|
9980
|
+
let sourceMap = options.sourceMap;
|
|
9981
|
+
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
9982
|
+
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
9983
|
+
}
|
|
9984
|
+
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
|
|
9929
9985
|
...config.dev.watchFiles ? helpers_castArray(config.dev.watchFiles) : [],
|
|
9930
9986
|
{
|
|
9931
|
-
paths:
|
|
9987
|
+
paths: [
|
|
9988
|
+
filePath,
|
|
9989
|
+
...dependencies
|
|
9990
|
+
],
|
|
9932
9991
|
type: 'reload-server'
|
|
9933
9992
|
}
|
|
9934
9993
|
]), config;
|
|
9935
9994
|
};
|
|
9936
|
-
async function init_init({
|
|
9937
|
-
|
|
9938
|
-
let logger = src_logger;
|
|
9995
|
+
async function init_init({ isRestart, isBuildWatch = !1 } = {}) {
|
|
9996
|
+
let logger = src_logger, { options } = cliState;
|
|
9939
9997
|
try {
|
|
9940
9998
|
var envDir;
|
|
9941
|
-
let cwd = process.cwd(), root =
|
|
9999
|
+
let cwd = process.cwd(), root = options.root ? ensureAbsolutePath(cwd, options.root) : cwd, rsbuild = await createRsbuild({
|
|
9942
10000
|
cwd: root,
|
|
9943
10001
|
config: ()=>init_loadConfig(root),
|
|
9944
|
-
environment:
|
|
9945
|
-
loadEnv: !1 !==
|
|
9946
|
-
cwd: (envDir =
|
|
9947
|
-
mode:
|
|
10002
|
+
environment: options.environment,
|
|
10003
|
+
loadEnv: !1 !== options.env && {
|
|
10004
|
+
cwd: (envDir = options.envDir) ? node_path.isAbsolute(envDir) ? envDir : node_path.join(root, envDir) : root,
|
|
10005
|
+
mode: options.envMode
|
|
9948
10006
|
}
|
|
9949
10007
|
});
|
|
9950
10008
|
return logger = rsbuild.logger, rsbuild.onBeforeCreateCompiler(()=>{
|
|
@@ -10024,13 +10082,13 @@ async function watchFilesForRestart({ files, rsbuild, isBuildWatch, watchOptions
|
|
|
10024
10082
|
watcher.on('add', onChange), watcher.on('change', onChange), watcher.on('unlink', onChange);
|
|
10025
10083
|
}
|
|
10026
10084
|
let applyServerOptions = (command)=>{
|
|
10027
|
-
command.option('-o, --open [url]', 'Open the page in browser on startup').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to');
|
|
10085
|
+
command.option('-o, --open [url]', 'Open the page in browser on startup').option('--port <port>', 'Set the port number for the server').option('--strict-port', 'Exit if the specified port is already in use').option('--host [host]', 'Set the host that the server listens to');
|
|
10028
10086
|
};
|
|
10029
|
-
function setupCommands() {
|
|
10087
|
+
function setupCommands(argv) {
|
|
10030
10088
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10031
|
-
cli.version("2.1.
|
|
10089
|
+
cli.version("2.1.3"), 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)', {
|
|
10032
10090
|
default: 'auto'
|
|
10033
|
-
}).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', {
|
|
10091
|
+
}).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', {
|
|
10034
10092
|
type: [
|
|
10035
10093
|
String
|
|
10036
10094
|
],
|
|
@@ -10040,20 +10098,19 @@ function setupCommands() {
|
|
|
10040
10098
|
applyServerOptions(devCommand), applyServerOptions(previewCommand);
|
|
10041
10099
|
let logger = src_logger;
|
|
10042
10100
|
devCommand.action(async (options)=>{
|
|
10101
|
+
initCliAction('dev', options);
|
|
10043
10102
|
try {
|
|
10044
|
-
let rsbuild = await init_init(
|
|
10045
|
-
cliOptions: options
|
|
10046
|
-
});
|
|
10103
|
+
let rsbuild = await init_init();
|
|
10047
10104
|
if (!rsbuild) return;
|
|
10048
10105
|
logger = rsbuild.logger, await rsbuild.startDevServer();
|
|
10049
10106
|
} catch (err) {
|
|
10050
10107
|
logger.error('Failed to start dev server.'), logger.error(err), process.exit(1);
|
|
10051
10108
|
}
|
|
10052
10109
|
}), buildCommand.option('-w, --watch', 'Enable watch mode to automatically rebuild on file changes').action(async (options)=>{
|
|
10110
|
+
initCliAction('build', options);
|
|
10053
10111
|
try {
|
|
10054
10112
|
options.watch || (process.env.RSPACK_UNSAFE_FAST_DROP = 'true');
|
|
10055
10113
|
let rsbuild = await init_init({
|
|
10056
|
-
cliOptions: options,
|
|
10057
10114
|
isBuildWatch: options.watch
|
|
10058
10115
|
});
|
|
10059
10116
|
if (!rsbuild) return;
|
|
@@ -10066,20 +10123,18 @@ function setupCommands() {
|
|
|
10066
10123
|
err instanceof Error && err.message === RSPACK_BUILD_ERROR || logger.error('Failed to build.'), logger.error(err), process.exit(1);
|
|
10067
10124
|
}
|
|
10068
10125
|
}), previewCommand.action(async (options)=>{
|
|
10126
|
+
initCliAction('preview', options);
|
|
10069
10127
|
try {
|
|
10070
|
-
let rsbuild = await init_init(
|
|
10071
|
-
cliOptions: options
|
|
10072
|
-
});
|
|
10128
|
+
let rsbuild = await init_init();
|
|
10073
10129
|
if (!rsbuild) return;
|
|
10074
10130
|
logger = rsbuild.logger, await rsbuild.preview();
|
|
10075
10131
|
} catch (err) {
|
|
10076
10132
|
logger.error('Failed to start preview server.'), logger.error(err), process.exit(1);
|
|
10077
10133
|
}
|
|
10078
10134
|
}), inspectCommand.option('--output <output>', 'Set the output path for inspection results').option('--verbose', 'Show complete function definitions in output').action(async (options)=>{
|
|
10135
|
+
initCliAction('inspect', options);
|
|
10079
10136
|
try {
|
|
10080
|
-
let rsbuild = await init_init(
|
|
10081
|
-
cliOptions: options
|
|
10082
|
-
});
|
|
10137
|
+
let rsbuild = await init_init();
|
|
10083
10138
|
if (!rsbuild) return;
|
|
10084
10139
|
logger = rsbuild.logger, await rsbuild.inspectConfig({
|
|
10085
10140
|
verbose: options.verbose,
|
|
@@ -10091,21 +10146,17 @@ function setupCommands() {
|
|
|
10091
10146
|
}
|
|
10092
10147
|
}), cli.help((sections)=>{
|
|
10093
10148
|
for (let section of (sections.shift(), sections))'Usage' === section.title && (section.body = section.body.replace('$ rsbuild', color.yellow("$ rsbuild [command] [options]"))), 'Commands' === section.title && (section.body = section.body.replace(` ${devDescription}`, `dev ${devDescription}`)), section.title?.startsWith('For more info') ? (section.title = color.dim(' For details on a sub-command, run'), section.body = color.dim(' $ rsbuild <command> -h')) : section.title && (section.title = color.cyan(section.title));
|
|
10094
|
-
}), cli.parse();
|
|
10095
|
-
}
|
|
10096
|
-
let { argv: cli_argv } = process;
|
|
10097
|
-
function initNodeEnv(command) {
|
|
10098
|
-
process.env.NODE_ENV || (process.env.NODE_ENV = 'build' === command || 'preview' === command ? 'production' : 'development');
|
|
10149
|
+
}), cli.parse(argv);
|
|
10099
10150
|
}
|
|
10100
10151
|
function showGreeting() {
|
|
10101
10152
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10102
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.
|
|
10153
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.3\n`);
|
|
10103
10154
|
}
|
|
10104
|
-
function setupLogLevel() {
|
|
10105
|
-
if (
|
|
10106
|
-
let logLevelIndex =
|
|
10155
|
+
function setupLogLevel(argv) {
|
|
10156
|
+
if (argv.length <= 3) return;
|
|
10157
|
+
let logLevelIndex = argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
10107
10158
|
if (-1 !== logLevelIndex) {
|
|
10108
|
-
let level =
|
|
10159
|
+
let level = argv[logLevelIndex + 1];
|
|
10109
10160
|
level && [
|
|
10110
10161
|
'warn',
|
|
10111
10162
|
'error',
|
|
@@ -10113,13 +10164,13 @@ function setupLogLevel() {
|
|
|
10113
10164
|
].includes(level) && !isDebug() && (src_logger.level = level);
|
|
10114
10165
|
}
|
|
10115
10166
|
}
|
|
10116
|
-
function runCLI() {
|
|
10117
|
-
|
|
10167
|
+
function runCLI({ argv = process.argv } = {}) {
|
|
10168
|
+
setupLogLevel(argv), showGreeting();
|
|
10118
10169
|
try {
|
|
10119
|
-
setupCommands();
|
|
10170
|
+
setupCommands(argv);
|
|
10120
10171
|
} catch (err) {
|
|
10121
10172
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10122
10173
|
}
|
|
10123
10174
|
}
|
|
10124
|
-
let src_version = "2.1.
|
|
10175
|
+
let src_version = "2.1.3";
|
|
10125
10176
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, 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 };
|
package/dist/client/hmr.js
CHANGED
|
@@ -100,7 +100,7 @@ function init(token, config, serverHost, serverPort, serverBase, liveReload, bro
|
|
|
100
100
|
for (const item of clientErrors)if (item.id === id) item.message = message;
|
|
101
101
|
createOverlay('Runtime errors', clientErrors.map((item)=>item.message).filter(Boolean).join('\n\n'));
|
|
102
102
|
}
|
|
103
|
-
const shouldUpdate = ()=>lastHash !==
|
|
103
|
+
const shouldUpdate = ()=>lastHash !== import.meta.rspackHash;
|
|
104
104
|
const handleApplyUpdates = (err, updatedModules)=>{
|
|
105
105
|
const forcedReload = err || !updatedModules;
|
|
106
106
|
if (forcedReload) {
|
package/dist/cssUrlLoader.mjs
CHANGED
|
@@ -26,7 +26,7 @@ let HASH_PLACEHOLDER_REGEX = /\[(?:[^:\]]+:)?(?:chunkhash|contenthash|hash|fullh
|
|
|
26
26
|
...info,
|
|
27
27
|
...assetInfo,
|
|
28
28
|
immutable: info.immutable || HASH_PLACEHOLDER_REGEX.test(filenameTemplate)
|
|
29
|
-
}), `export default
|
|
29
|
+
}), `export default import.meta.rspackPublicPath + ${JSON.stringify(filename)};`;
|
|
30
30
|
};
|
|
31
31
|
export default function(source) {
|
|
32
32
|
return source;
|