@rsbuild/core 1.1.2 → 1.1.4
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/bin/rsbuild.js +2 -10
- package/compiled/css-loader/index.js +46 -46
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/postcss/index.js +135 -117
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-load-config/index.js +10 -10
- package/compiled/postcss-loader/index.js +11 -11
- package/compiled/rspack-chain/index.d.ts +3 -0
- package/compiled/rspack-chain/index.js +69 -66
- package/compiled/rspack-chain/package.json +1 -1
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/client/hmr.js +10 -1
- package/dist/index.cjs +459 -507
- package/dist/index.js +362 -412
- package/dist-types/cli/commands.d.ts +1 -1
- package/dist-types/cli/index.d.ts +1 -0
- package/dist-types/config.d.ts +29 -3
- package/dist-types/helpers/stats.d.ts +2 -3
- package/dist-types/index.d.ts +2 -1
- package/dist-types/internal.d.ts +0 -2
- package/package.json +6 -8
- package/dist/index.cjs.LICENSE.txt +0 -13
- package/dist/index.js.LICENSE.txt +0 -13
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/*! For license information please see index.cjs.LICENSE.txt */
|
|
2
1
|
var __webpack_modules__ = {
|
|
3
2
|
"../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js": function(module1) {
|
|
4
3
|
"use strict";
|
|
@@ -57,14 +56,14 @@ var __webpack_modules__ = {
|
|
|
57
56
|
};
|
|
58
57
|
module1.exports = deepmerge;
|
|
59
58
|
},
|
|
60
|
-
"../../node_modules/.pnpm/dotenv-expand@11.0.
|
|
59
|
+
"../../node_modules/.pnpm/dotenv-expand@11.0.7/node_modules/dotenv-expand/lib/main.js": function(module1) {
|
|
61
60
|
"use strict";
|
|
62
61
|
let DOTENV_SUBSTITUTION_REGEX = /(\\)?(\$)(?!\()(\{?)([\w.]+)(?::?-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))?(\}?)/gi;
|
|
63
62
|
function interpolate(value, processEnv, parsed) {
|
|
64
63
|
return value.replace(DOTENV_SUBSTITUTION_REGEX, (match, escaped, dollarSign, openBrace, key, defaultValue, closeBrace)=>{
|
|
65
64
|
if ('\\' === escaped) return match.slice(1);
|
|
66
65
|
if (processEnv[key]) return processEnv[key] === parsed[key] ? processEnv[key] : interpolate(processEnv[key], processEnv, parsed);
|
|
67
|
-
if (parsed[key]
|
|
66
|
+
if (parsed[key] && parsed[key] !== value) return interpolate(parsed[key], processEnv, parsed);
|
|
68
67
|
if (defaultValue) return defaultValue.startsWith('$') ? interpolate(defaultValue, processEnv, parsed) : defaultValue;
|
|
69
68
|
return '';
|
|
70
69
|
});
|
|
@@ -232,62 +231,6 @@ var __webpack_modules__ = {
|
|
|
232
231
|
};
|
|
233
232
|
module1.exports.configDotenv = DotenvModule.configDotenv, module1.exports._configVault = DotenvModule._configVault, module1.exports._parseVault = DotenvModule._parseVault, module1.exports.config = DotenvModule.config, module1.exports.decrypt = DotenvModule.decrypt, module1.exports.parse = DotenvModule.parse, module1.exports.populate = DotenvModule.populate, module1.exports = DotenvModule;
|
|
234
233
|
},
|
|
235
|
-
"../../node_modules/.pnpm/is-extglob@2.1.1/node_modules/is-extglob/index.js": function(module1) {
|
|
236
|
-
module1.exports = function(str) {
|
|
237
|
-
var match;
|
|
238
|
-
if ('string' != typeof str || '' === str) return !1;
|
|
239
|
-
for(; match = /(\\).|([@?!+*]\(.*\))/g.exec(str);){
|
|
240
|
-
if (match[2]) return !0;
|
|
241
|
-
str = str.slice(match.index + match[0].length);
|
|
242
|
-
}
|
|
243
|
-
return !1;
|
|
244
|
-
};
|
|
245
|
-
},
|
|
246
|
-
"../../node_modules/.pnpm/is-glob@4.0.3/node_modules/is-glob/index.js": function(module1, __unused_webpack_exports, __webpack_require__) {
|
|
247
|
-
var isExtglob = __webpack_require__("../../node_modules/.pnpm/is-extglob@2.1.1/node_modules/is-extglob/index.js"), chars = {
|
|
248
|
-
'{': '}',
|
|
249
|
-
'(': ')',
|
|
250
|
-
'[': ']'
|
|
251
|
-
}, strictCheck = function(str) {
|
|
252
|
-
if ('!' === str[0]) return !0;
|
|
253
|
-
for(var index = 0, pipeIndex = -2, closeSquareIndex = -2, closeCurlyIndex = -2, closeParenIndex = -2, backSlashIndex = -2; index < str.length;){
|
|
254
|
-
if ('*' === str[index] || '?' === str[index + 1] && /[\].+)]/.test(str[index]) || -1 !== closeSquareIndex && '[' === str[index] && ']' !== str[index + 1] && (closeSquareIndex < index && (closeSquareIndex = str.indexOf(']', index)), closeSquareIndex > index && (-1 === backSlashIndex || backSlashIndex > closeSquareIndex || -1 === (backSlashIndex = str.indexOf('\\', index)) || backSlashIndex > closeSquareIndex)) || -1 !== closeCurlyIndex && '{' === str[index] && '}' !== str[index + 1] && (closeCurlyIndex = str.indexOf('}', index)) > index && (-1 === (backSlashIndex = str.indexOf('\\', index)) || backSlashIndex > closeCurlyIndex) || -1 !== closeParenIndex && '(' === str[index] && '?' === str[index + 1] && /[:!=]/.test(str[index + 2]) && ')' !== str[index + 3] && (closeParenIndex = str.indexOf(')', index)) > index && (-1 === (backSlashIndex = str.indexOf('\\', index)) || backSlashIndex > closeParenIndex) || -1 !== pipeIndex && '(' === str[index] && '|' !== str[index + 1] && (pipeIndex < index && (pipeIndex = str.indexOf('|', index)), -1 !== pipeIndex && ')' !== str[pipeIndex + 1] && (closeParenIndex = str.indexOf(')', pipeIndex)) > pipeIndex && (-1 === (backSlashIndex = str.indexOf('\\', pipeIndex)) || backSlashIndex > closeParenIndex))) return !0;
|
|
255
|
-
if ('\\' === str[index]) {
|
|
256
|
-
var open = str[index + 1];
|
|
257
|
-
index += 2;
|
|
258
|
-
var close = chars[open];
|
|
259
|
-
if (close) {
|
|
260
|
-
var n = str.indexOf(close, index);
|
|
261
|
-
-1 !== n && (index = n + 1);
|
|
262
|
-
}
|
|
263
|
-
if ('!' === str[index]) return !0;
|
|
264
|
-
} else index++;
|
|
265
|
-
}
|
|
266
|
-
return !1;
|
|
267
|
-
}, relaxedCheck = function(str) {
|
|
268
|
-
if ('!' === str[0]) return !0;
|
|
269
|
-
for(var index = 0; index < str.length;){
|
|
270
|
-
if (/[*?{}()[\]]/.test(str[index])) return !0;
|
|
271
|
-
if ('\\' === str[index]) {
|
|
272
|
-
var open = str[index + 1];
|
|
273
|
-
index += 2;
|
|
274
|
-
var close = chars[open];
|
|
275
|
-
if (close) {
|
|
276
|
-
var n = str.indexOf(close, index);
|
|
277
|
-
-1 !== n && (index = n + 1);
|
|
278
|
-
}
|
|
279
|
-
if ('!' === str[index]) return !0;
|
|
280
|
-
} else index++;
|
|
281
|
-
}
|
|
282
|
-
return !1;
|
|
283
|
-
};
|
|
284
|
-
module1.exports = function(str, options) {
|
|
285
|
-
if ('string' != typeof str || '' === str) return !1;
|
|
286
|
-
if (isExtglob(str)) return !0;
|
|
287
|
-
var check = strictCheck;
|
|
288
|
-
return options && !1 === options.strict && (check = relaxedCheck), check(str);
|
|
289
|
-
};
|
|
290
|
-
},
|
|
291
234
|
"../../compiled/chokidar/index.js": function(module1) {
|
|
292
235
|
"use strict";
|
|
293
236
|
module1.exports = require("../compiled/chokidar/index.js");
|
|
@@ -1514,7 +1457,7 @@ __webpack_require__.n = function(module1) {
|
|
|
1514
1457
|
var __webpack_exports__ = {};
|
|
1515
1458
|
(()=>{
|
|
1516
1459
|
"use strict";
|
|
1517
|
-
let
|
|
1460
|
+
let pluginHelper_htmlPlugin, cssExtractPlugin, swcHelpersPath;
|
|
1518
1461
|
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
1519
1462
|
ensureAssetPrefix: ()=>ensureAssetPrefix,
|
|
1520
1463
|
createRsbuild: ()=>createRsbuild,
|
|
@@ -1522,13 +1465,18 @@ var __webpack_exports__ = {};
|
|
|
1522
1465
|
loadConfig: ()=>config_loadConfig,
|
|
1523
1466
|
version: ()=>src_version,
|
|
1524
1467
|
PLUGIN_CSS_NAME: ()=>PLUGIN_CSS_NAME,
|
|
1525
|
-
logger: ()=>
|
|
1468
|
+
logger: ()=>rslog_index_js_namespaceObject.logger,
|
|
1526
1469
|
loadEnv: ()=>loadEnv,
|
|
1527
1470
|
mergeRsbuildConfig: ()=>mergeRsbuildConfig,
|
|
1528
1471
|
rspack: ()=>core_namespaceObject.rspack,
|
|
1529
1472
|
__internalHelper: ()=>internal_namespaceObject,
|
|
1473
|
+
runCLI: ()=>runCLI,
|
|
1530
1474
|
defineConfig: ()=>defineConfig
|
|
1531
1475
|
});
|
|
1476
|
+
var internal_namespaceObject = {};
|
|
1477
|
+
__webpack_require__.r(internal_namespaceObject), __webpack_require__.d(internal_namespaceObject, {
|
|
1478
|
+
setHTMLPlugin: ()=>setHTMLPlugin
|
|
1479
|
+
});
|
|
1532
1480
|
var provider_helpers_namespaceObject = {};
|
|
1533
1481
|
__webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(provider_helpers_namespaceObject, {
|
|
1534
1482
|
chainToConfig: ()=>chainToConfig,
|
|
@@ -1548,18 +1496,16 @@ var __webpack_exports__ = {};
|
|
|
1548
1496
|
setCssExtractPlugin: ()=>setCssExtractPlugin,
|
|
1549
1497
|
stringifyConfig: ()=>stringifyConfig
|
|
1550
1498
|
});
|
|
1551
|
-
var internal_namespaceObject = {};
|
|
1552
|
-
__webpack_require__.r(internal_namespaceObject), __webpack_require__.d(internal_namespaceObject, {
|
|
1553
|
-
prepareCli: ()=>prepareCli,
|
|
1554
|
-
runCli: ()=>runCli,
|
|
1555
|
-
setHTMLPlugin: ()=>setHTMLPlugin
|
|
1556
|
-
});
|
|
1557
1499
|
let core_namespaceObject = require("@rspack/core");
|
|
1558
1500
|
var core_default = __webpack_require__.n(core_namespaceObject);
|
|
1559
|
-
let
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1501
|
+
let external_node_module_namespaceObject = require("node:module"), pluginHelper_require = (0, external_node_module_namespaceObject.createRequire)('undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href), setHTMLPlugin = (plugin)=>{
|
|
1502
|
+
plugin && (pluginHelper_htmlPlugin = plugin);
|
|
1503
|
+
}, getHTMLPlugin = ()=>(!pluginHelper_htmlPlugin && (pluginHelper_htmlPlugin = pluginHelper_require('../compiled/html-rspack-plugin/index.js')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
|
|
1504
|
+
cssExtractPlugin = plugin;
|
|
1505
|
+
}, getCssExtractPlugin = ()=>cssExtractPlugin ? cssExtractPlugin : core_default().CssExtractRspackPlugin;
|
|
1506
|
+
var external_node_fs_ = __webpack_require__("node:fs"), external_node_fs_default = __webpack_require__.n(external_node_fs_), external_node_path_ = __webpack_require__("node:path"), external_node_path_default = __webpack_require__.n(external_node_path_), main = __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js"), lib_main = __webpack_require__("../../node_modules/.pnpm/dotenv-expand@11.0.7/node_modules/dotenv-expand/lib/main.js"), cjs = __webpack_require__("../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"), cjs_default = __webpack_require__.n(cjs);
|
|
1507
|
+
let index_js_namespaceObject = require("../compiled/picocolors/index.js");
|
|
1508
|
+
var index_js_default = __webpack_require__.n(index_js_namespaceObject);
|
|
1563
1509
|
let ROOT_DIST_DIR = 'dist', LOADER_PATH = (0, external_node_path_.join)(__dirname), STATIC_PATH = (0, external_node_path_.join)(__dirname, '../static'), COMPILED_PATH = (0, external_node_path_.join)(__dirname, '../compiled'), RSBUILD_OUTPUTS_PATH = '.rsbuild', DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_ASSET_PREFIX = '/', DEFAULT_WEB_BROWSERSLIST = [
|
|
1564
1510
|
'chrome >= 87',
|
|
1565
1511
|
'edge >= 88',
|
|
@@ -1605,8 +1551,26 @@ var __webpack_exports__ = {};
|
|
|
1605
1551
|
'aac',
|
|
1606
1552
|
'm4a',
|
|
1607
1553
|
'opus'
|
|
1608
|
-
]
|
|
1609
|
-
|
|
1554
|
+
], rslog_index_js_namespaceObject = require("../compiled/rslog/index.js"), isDebug = ()=>{
|
|
1555
|
+
if (!process.env.DEBUG) return !1;
|
|
1556
|
+
let values = process.env.DEBUG.toLocaleLowerCase().split(',');
|
|
1557
|
+
return [
|
|
1558
|
+
'rsbuild',
|
|
1559
|
+
'builder',
|
|
1560
|
+
'*'
|
|
1561
|
+
].some((key)=>values.includes(key));
|
|
1562
|
+
};
|
|
1563
|
+
isDebug() && (rslog_index_js_namespaceObject.logger.level = 'verbose');
|
|
1564
|
+
rslog_index_js_namespaceObject.logger.override({
|
|
1565
|
+
debug: (message, ...args)=>{
|
|
1566
|
+
if ('verbose' !== rslog_index_js_namespaceObject.logger.level) return;
|
|
1567
|
+
let time = index_js_default().gray(`${function() {
|
|
1568
|
+
let now = new Date(), hours = String(now.getHours()).padStart(2, '0'), minutes = String(now.getMinutes()).padStart(2, '0'), seconds = String(now.getSeconds()).padStart(2, '0');
|
|
1569
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
1570
|
+
}()}`);
|
|
1571
|
+
console.log(` ${index_js_default().magenta('rsbuild')} ${time} ${message}`, ...args);
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1610
1574
|
let isFileSync = (filePath)=>{
|
|
1611
1575
|
try {
|
|
1612
1576
|
var _fs_statSync;
|
|
@@ -1644,7 +1608,7 @@ var __webpack_exports__ = {};
|
|
|
1644
1608
|
force: !0
|
|
1645
1609
|
});
|
|
1646
1610
|
} catch (err) {
|
|
1647
|
-
|
|
1611
|
+
rslog_index_js_namespaceObject.logger.debug(`Failed to empty dir: ${dir}`), rslog_index_js_namespaceObject.logger.debug(err);
|
|
1648
1612
|
}
|
|
1649
1613
|
}
|
|
1650
1614
|
function getAbsolutePath(base, filepath) {
|
|
@@ -1670,8 +1634,12 @@ var __webpack_exports__ = {};
|
|
|
1670
1634
|
}
|
|
1671
1635
|
let file = stats.file || stats.moduleName;
|
|
1672
1636
|
return file ? `File: ${file}\n` : '';
|
|
1673
|
-
}(stats), mainMessage = stats.message, details = verbose && stats.details ? `\nDetails: ${stats.details}\n` : '', stack = verbose && stats.stack ? `\n${stats.stack}` : ''
|
|
1674
|
-
|
|
1637
|
+
}(stats), mainMessage = stats.message, details = verbose && stats.details ? `\nDetails: ${stats.details}\n` : '', stack = verbose && stats.stack ? `\n${stats.stack}` : '', moduleTrace = function(stats) {
|
|
1638
|
+
let traceStr = '';
|
|
1639
|
+
if (stats.moduleTrace) for (let trace of stats.moduleTrace)trace.originName && (traceStr += `\n @ ${trace.originName}`);
|
|
1640
|
+
return traceStr;
|
|
1641
|
+
}(stats);
|
|
1642
|
+
message = `${fileName}${mainMessage}${details}${stack}${moduleTrace}`;
|
|
1675
1643
|
} else message = stats;
|
|
1676
1644
|
message = (lines = (lines = (message = function(message) {
|
|
1677
1645
|
let hint = 'You may need an appropriate loader to handle this file type.';
|
|
@@ -1692,9 +1660,9 @@ var __webpack_exports__ = {};
|
|
|
1692
1660
|
let getTips = (moduleName)=>{
|
|
1693
1661
|
let tips = [
|
|
1694
1662
|
`Tip: "${moduleName}" is a built-in Node.js module. It cannot be imported in client-side code.`,
|
|
1695
|
-
`Check if you need to import Node.js module. If needed, you can use ${
|
|
1663
|
+
`Check if you need to import Node.js module. If needed, you can use ${index_js_default().cyan('@rsbuild/plugin-node-polyfill')}.`
|
|
1696
1664
|
];
|
|
1697
|
-
return `${message}\n\n${
|
|
1665
|
+
return `${message}\n\n${index_js_default().yellow(tips.join('\n'))}`;
|
|
1698
1666
|
};
|
|
1699
1667
|
if (message.includes('need an additional plugin to handle "node:" URIs')) return getTips('node:*');
|
|
1700
1668
|
if (!message.includes("Can't resolve")) return message;
|
|
@@ -1749,12 +1717,16 @@ var __webpack_exports__ = {};
|
|
|
1749
1717
|
return statsData.warningsCount && (null === (_statsData_warnings = statsData.warnings) || void 0 === _statsData_warnings ? void 0 : _statsData_warnings.length) === 0 ? null === (_statsData_children = statsData.children) || void 0 === _statsData_children ? void 0 : _statsData_children.reduce((warnings, curr)=>warnings.concat(curr.warnings || []), []) : statsData.warnings;
|
|
1750
1718
|
};
|
|
1751
1719
|
function getStatsOptions(compiler) {
|
|
1752
|
-
|
|
1720
|
+
if (isMultiCompiler(compiler)) return {
|
|
1753
1721
|
children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
|
|
1754
|
-
}
|
|
1722
|
+
};
|
|
1723
|
+
let { stats } = compiler.options;
|
|
1724
|
+
return 'string' == typeof stats ? {
|
|
1725
|
+
preset: stats
|
|
1726
|
+
} : 'object' == typeof stats ? stats : {};
|
|
1755
1727
|
}
|
|
1756
1728
|
function formatStats(statsData, hasErrors) {
|
|
1757
|
-
let verbose = 'verbose' ===
|
|
1729
|
+
let verbose = 'verbose' === rslog_index_js_namespaceObject.logger.level;
|
|
1758
1730
|
if (hasErrors) {
|
|
1759
1731
|
let { errors } = formatStatsMessages({
|
|
1760
1732
|
errors: getAllStatsErrors(statsData),
|
|
@@ -1762,9 +1734,9 @@ var __webpack_exports__ = {};
|
|
|
1762
1734
|
}, verbose);
|
|
1763
1735
|
return {
|
|
1764
1736
|
message: function(errors) {
|
|
1765
|
-
let messages = errors.map((error)=>hintNodePolyfill(error)), text = `${messages.join('\n\n')}\n`, title =
|
|
1766
|
-
if (!errors.length) return `${title}\n${
|
|
1767
|
-
let tip =
|
|
1737
|
+
let messages = errors.map((error)=>hintNodePolyfill(error)), text = `${messages.join('\n\n')}\n`, title = index_js_default().bold(index_js_default().red('Compile error: '));
|
|
1738
|
+
if (!errors.length) return `${title}\n${index_js_default().yellow("For more details, please setting 'stats.errors: true' ")}`;
|
|
1739
|
+
let tip = index_js_default().yellow('Failed to compile, check the errors for troubleshooting.');
|
|
1768
1740
|
return `${title}\n${tip}\n${text}`;
|
|
1769
1741
|
}(errors),
|
|
1770
1742
|
level: 'error'
|
|
@@ -1775,7 +1747,7 @@ var __webpack_exports__ = {};
|
|
|
1775
1747
|
warnings: getAllStatsWarnings(statsData)
|
|
1776
1748
|
}, verbose);
|
|
1777
1749
|
if (warnings.length) {
|
|
1778
|
-
let title =
|
|
1750
|
+
let title = index_js_default().bold(index_js_default().yellow('Compile Warning: \n'));
|
|
1779
1751
|
return {
|
|
1780
1752
|
message: `${title}${warnings.join('\n\n')}\n`,
|
|
1781
1753
|
level: 'warning'
|
|
@@ -1845,7 +1817,7 @@ var __webpack_exports__ = {};
|
|
|
1845
1817
|
return keys.reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {});
|
|
1846
1818
|
}
|
|
1847
1819
|
let camelCase = (input)=>input.replace(/[-_](\w)/g, (_, c)=>c.toUpperCase()), prettyTime = (seconds)=>{
|
|
1848
|
-
let format = (time)=>
|
|
1820
|
+
let format = (time)=>index_js_default().bold(time);
|
|
1849
1821
|
if (seconds < 10) {
|
|
1850
1822
|
let digits = seconds >= 0.01 ? 2 : 3;
|
|
1851
1823
|
return `${format(seconds.toFixed(digits))} s`;
|
|
@@ -1853,27 +1825,110 @@ var __webpack_exports__ = {};
|
|
|
1853
1825
|
if (seconds < 60) return `${format(seconds.toFixed(1))} s`;
|
|
1854
1826
|
let minutes = seconds / 60;
|
|
1855
1827
|
return `${format(minutes.toFixed(2))} m`;
|
|
1856
|
-
}, isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
'
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1828
|
+
}, isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
|
|
1829
|
+
function loadEnv({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
|
|
1830
|
+
'PUBLIC_'
|
|
1831
|
+
] } = {}) {
|
|
1832
|
+
if ('local' === mode) throw Error("'local' cannot be used as a value for env mode, because \".env.local\" represents a temporary local file. Please use another value.");
|
|
1833
|
+
let filePaths = [
|
|
1834
|
+
'.env',
|
|
1835
|
+
'.env.local',
|
|
1836
|
+
`.env.${mode}`,
|
|
1837
|
+
`.env.${mode}.local`
|
|
1838
|
+
].map((filename)=>(0, external_node_path_.join)(cwd, filename)).filter(isFileSync), parsed = {};
|
|
1839
|
+
for (let envPath of filePaths)Object.assign(parsed, (0, main.parse)(external_node_fs_default().readFileSync(envPath)));
|
|
1840
|
+
parsed.NODE_ENV && (process.env.NODE_ENV = parsed.NODE_ENV), (0, lib_main.expand)({
|
|
1841
|
+
parsed
|
|
1842
|
+
});
|
|
1843
|
+
let publicVars = {}, rawPublicVars = {};
|
|
1844
|
+
for (let key of Object.keys(process.env))if (prefixes.some((prefix)=>key.startsWith(prefix))) {
|
|
1845
|
+
let val = process.env[key];
|
|
1846
|
+
publicVars[`import.meta.env.${key}`] = JSON.stringify(val), publicVars[`process.env.${key}`] = JSON.stringify(val), rawPublicVars[key] = val;
|
|
1874
1847
|
}
|
|
1875
|
-
|
|
1876
|
-
|
|
1848
|
+
let cleaned = !1;
|
|
1849
|
+
return {
|
|
1850
|
+
parsed,
|
|
1851
|
+
cleanup: ()=>{
|
|
1852
|
+
if (!cleaned) {
|
|
1853
|
+
for (let key of Object.keys(parsed)){
|
|
1854
|
+
if ('NODE_ENV' !== key) process.env[key] === parsed[key] && delete process.env[key];
|
|
1855
|
+
}
|
|
1856
|
+
cleaned = !0;
|
|
1857
|
+
}
|
|
1858
|
+
},
|
|
1859
|
+
filePaths,
|
|
1860
|
+
publicVars,
|
|
1861
|
+
rawPublicVars
|
|
1862
|
+
};
|
|
1863
|
+
}
|
|
1864
|
+
let types_namespaceObject = require("node:util/types");
|
|
1865
|
+
class BrowserslistError extends Error {
|
|
1866
|
+
constructor(message){
|
|
1867
|
+
super(message), function(obj, key, value) {
|
|
1868
|
+
key in obj ? Object.defineProperty(obj, key, {
|
|
1869
|
+
value: value,
|
|
1870
|
+
enumerable: !0,
|
|
1871
|
+
configurable: !0,
|
|
1872
|
+
writable: !0
|
|
1873
|
+
}) : obj[key] = value;
|
|
1874
|
+
}(this, "browserslist", void 0), this.name = 'BrowserslistError', this.browserslist = !0, Error.captureStackTrace && Error.captureStackTrace(this, BrowserslistError);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
let isFileCache = {};
|
|
1878
|
+
function isFile(file) {
|
|
1879
|
+
if (file in isFileCache) return isFileCache[file];
|
|
1880
|
+
let result = external_node_fs_.existsSync(file) && external_node_fs_.statSync(file).isFile();
|
|
1881
|
+
return isFileCache[file] = result, result;
|
|
1882
|
+
}
|
|
1883
|
+
function parsePackage(file) {
|
|
1884
|
+
let config = JSON.parse(external_node_fs_.readFileSync(file).toString().replace(/^\uFEFF/m, ''));
|
|
1885
|
+
if (config.browserlist && !config.browserslist) throw new BrowserslistError(`\`browserlist\` key instead of \`browserslist\` in ${file}`);
|
|
1886
|
+
let list = config.browserslist;
|
|
1887
|
+
for(let i in Array.isArray(list) && (list = {
|
|
1888
|
+
defaults: list
|
|
1889
|
+
}), 'string' == typeof list && (list = parseConfig(list)), list)!function(section) {
|
|
1890
|
+
let FORMAT = 'Browserslist config should be a string or an array of strings with browser queries';
|
|
1891
|
+
if (Array.isArray(section)) {
|
|
1892
|
+
for(let i = 0; i < section.length; i++)if ('string' != typeof section[i]) throw new BrowserslistError(FORMAT);
|
|
1893
|
+
} else if ('string' != typeof section) throw new BrowserslistError(FORMAT);
|
|
1894
|
+
}(list[i]);
|
|
1895
|
+
return list;
|
|
1896
|
+
}
|
|
1897
|
+
let IS_SECTION = /^\s*\[(.+)]\s*$/;
|
|
1898
|
+
function parseConfig(string) {
|
|
1899
|
+
let result = {
|
|
1900
|
+
defaults: []
|
|
1901
|
+
}, sections = [
|
|
1902
|
+
'defaults'
|
|
1903
|
+
];
|
|
1904
|
+
return string.toString().replace(/#[^\n]*/g, '').split(/\n|,/).map((line)=>line.trim()).filter((line)=>'' !== line).forEach((line)=>{
|
|
1905
|
+
let matched = line.match(IS_SECTION);
|
|
1906
|
+
matched ? (sections = matched[1].trim().split(' ')).forEach((section)=>{
|
|
1907
|
+
if (result[section]) throw new BrowserslistError(`Duplicate section ${section} in Browserslist config`);
|
|
1908
|
+
result[section] = [];
|
|
1909
|
+
}) : sections.forEach((section)=>{
|
|
1910
|
+
result[section].push(line);
|
|
1911
|
+
});
|
|
1912
|
+
}), result;
|
|
1913
|
+
}
|
|
1914
|
+
function parsePackageOrReadConfig(file) {
|
|
1915
|
+
return 'package.json' === external_node_path_.basename(file) ? parsePackage(file) : function(file) {
|
|
1916
|
+
if (!isFile(file)) throw new BrowserslistError(`Can't read ${file} config`);
|
|
1917
|
+
return parseConfig(external_node_fs_.readFileSync(file, 'utf-8'));
|
|
1918
|
+
}(file);
|
|
1919
|
+
}
|
|
1920
|
+
function pickEnv(config, opts) {
|
|
1921
|
+
let name;
|
|
1922
|
+
return 'object' != typeof config ? config : ('string' == typeof opts.env ? name = opts.env : process.env.BROWSERSLIST_ENV ? name = process.env.BROWSERSLIST_ENV : process.env.NODE_ENV ? name = process.env.NODE_ENV : name = 'production', config[name] || config.defaults);
|
|
1923
|
+
}
|
|
1924
|
+
function eachParent(file, callback) {
|
|
1925
|
+
let dir = isFile(file) ? external_node_path_.dirname(file) : file, loc = external_node_path_.resolve(dir);
|
|
1926
|
+
do {
|
|
1927
|
+
let result = callback(loc);
|
|
1928
|
+
if (void 0 !== result) return result;
|
|
1929
|
+
}while (loc !== (loc = external_node_path_.dirname(loc)));
|
|
1930
|
+
}
|
|
1931
|
+
let configCache = {}, rspack_chain_index_js_namespaceObject = require("../compiled/rspack-chain/index.js");
|
|
1877
1932
|
var rspack_chain_index_js_default = __webpack_require__.n(rspack_chain_index_js_namespaceObject);
|
|
1878
1933
|
let OVERRIDE_PATHS = [
|
|
1879
1934
|
'performance.removeConsole',
|
|
@@ -1914,8 +1969,78 @@ var __webpack_exports__ = {};
|
|
|
1914
1969
|
merged[key] = mergeConfig_merge(x[key], y[key], childPath);
|
|
1915
1970
|
}
|
|
1916
1971
|
return merged;
|
|
1917
|
-
}, mergeRsbuildConfig = (...configs)=>2 === configs.length ? mergeConfig_merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>mergeConfig_merge(result, config), {});
|
|
1918
|
-
|
|
1972
|
+
}, mergeRsbuildConfig = (...configs)=>2 === configs.length ? mergeConfig_merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>mergeConfig_merge(result, config), {}), commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? external_node_path_default().isAbsolute(envDir) ? envDir : external_node_path_default().resolve(cwd, envDir) : cwd;
|
|
1973
|
+
async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
|
|
1974
|
+
cliOptions && (commonOpts = cliOptions);
|
|
1975
|
+
try {
|
|
1976
|
+
var _config_server, _config_dev, _config_dev1;
|
|
1977
|
+
let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, envs = loadEnv({
|
|
1978
|
+
cwd: getEnvDir(root, commonOpts.envDir),
|
|
1979
|
+
mode: commonOpts.envMode
|
|
1980
|
+
});
|
|
1981
|
+
onBeforeRestartServer(envs.cleanup);
|
|
1982
|
+
let { content: config, filePath: configFilePath } = await config_loadConfig({
|
|
1983
|
+
cwd: root,
|
|
1984
|
+
path: commonOpts.config,
|
|
1985
|
+
envMode: commonOpts.envMode
|
|
1986
|
+
}), command = process.argv[2];
|
|
1987
|
+
if ('dev' === command || isBuildWatch) {
|
|
1988
|
+
let files = [
|
|
1989
|
+
...envs.filePaths
|
|
1990
|
+
];
|
|
1991
|
+
if (configFilePath && files.push(configFilePath), null === (_config_dev1 = config.dev) || void 0 === _config_dev1 ? void 0 : _config_dev1.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
|
|
1992
|
+
if ('reload-server' !== watchFilesConfig.type) continue;
|
|
1993
|
+
let paths = castArray(watchFilesConfig.paths);
|
|
1994
|
+
watchFilesConfig.options ? watchFilesForRestart(paths, root, isBuildWatch, watchFilesConfig.options) : files.push(...paths);
|
|
1995
|
+
}
|
|
1996
|
+
watchFilesForRestart(files, root, isBuildWatch);
|
|
1997
|
+
}
|
|
1998
|
+
return config.source ||= {}, config.source.define = {
|
|
1999
|
+
...envs.publicVars,
|
|
2000
|
+
...config.source.define
|
|
2001
|
+
}, commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), commonOpts.open && !(null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) && (config.server ||= {}, config.server.open = commonOpts.open), commonOpts.host && (config.server ||= {}, config.server.host = commonOpts.host), commonOpts.port && (config.server ||= {}, config.server.port = commonOpts.port), (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.cliShortcuts) === void 0 && (config.dev ||= {}, config.dev.cliShortcuts = !0), createRsbuild({
|
|
2002
|
+
cwd: root,
|
|
2003
|
+
rsbuildConfig: config,
|
|
2004
|
+
environment: commonOpts.environment
|
|
2005
|
+
});
|
|
2006
|
+
} catch (err) {
|
|
2007
|
+
if (isRestart) rslog_index_js_namespaceObject.logger.error(err);
|
|
2008
|
+
else throw err;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
2012
|
+
cleaners.push(cleaner);
|
|
2013
|
+
}, clearConsole = ()=>{
|
|
2014
|
+
isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J');
|
|
2015
|
+
}, beforeRestart = async ({ filePath, clear = !0 } = {})=>{
|
|
2016
|
+
if (clear && clearConsole(), filePath) {
|
|
2017
|
+
let filename = external_node_path_default().basename(filePath);
|
|
2018
|
+
rslog_index_js_namespaceObject.logger.info(`Restart server because ${index_js_default().yellow(filename)} is changed.\n`);
|
|
2019
|
+
} else rslog_index_js_namespaceObject.logger.info('Restarting server...\n');
|
|
2020
|
+
for (let cleaner of cleaners)await cleaner();
|
|
2021
|
+
cleaners = [];
|
|
2022
|
+
}, restartDevServer = async ({ filePath, clear = !0 } = {})=>{
|
|
2023
|
+
await beforeRestart({
|
|
2024
|
+
filePath,
|
|
2025
|
+
clear
|
|
2026
|
+
});
|
|
2027
|
+
let rsbuild = await init({
|
|
2028
|
+
isRestart: !0
|
|
2029
|
+
});
|
|
2030
|
+
if (!!rsbuild) await rsbuild.startDevServer();
|
|
2031
|
+
}, restartBuild = async ({ filePath, clear = !0 } = {})=>{
|
|
2032
|
+
await beforeRestart({
|
|
2033
|
+
filePath,
|
|
2034
|
+
clear
|
|
2035
|
+
});
|
|
2036
|
+
let rsbuild = await init({
|
|
2037
|
+
isRestart: !0,
|
|
2038
|
+
isBuildWatch: !0
|
|
2039
|
+
});
|
|
2040
|
+
if (!!rsbuild) onBeforeRestartServer((await rsbuild.build({
|
|
2041
|
+
watch: !0
|
|
2042
|
+
})).close);
|
|
2043
|
+
};
|
|
1919
2044
|
async function setupWatchFiles(options) {
|
|
1920
2045
|
let { dev, server, root, compileMiddlewareAPI } = options, { hmr, liveReload } = dev;
|
|
1921
2046
|
if (!hmr && !liveReload || !compileMiddlewareAPI) return;
|
|
@@ -1955,8 +2080,9 @@ var __webpack_exports__ = {};
|
|
|
1955
2080
|
type
|
|
1956
2081
|
};
|
|
1957
2082
|
}
|
|
2083
|
+
let GLOB_REGEX = /[*?{}[\]()!@+|]/, isGlob = (str)=>GLOB_REGEX.test(str);
|
|
1958
2084
|
async function createChokidar(pathOrGlobs, root, options) {
|
|
1959
|
-
let chokidar = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/chokidar/index.js", 23)), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!
|
|
2085
|
+
let chokidar = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/chokidar/index.js", 23)), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!isGlob(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
|
|
1960
2086
|
if (globPatterns.length) {
|
|
1961
2087
|
let tinyglobby = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/tinyglobby/index.js", 23)), { glob } = tinyglobby.default || tinyglobby;
|
|
1962
2088
|
for (let file of (await glob(globPatterns, {
|
|
@@ -2115,7 +2241,7 @@ var __webpack_exports__ = {};
|
|
|
2115
2241
|
if (customConfig) {
|
|
2116
2242
|
let customConfigPath = (0, external_node_path_.isAbsolute)(customConfig) ? customConfig : (0, external_node_path_.join)(root, customConfig);
|
|
2117
2243
|
if (external_node_fs_default().existsSync(customConfigPath)) return customConfigPath;
|
|
2118
|
-
|
|
2244
|
+
rslog_index_js_namespaceObject.logger.warn(`Cannot find config file: ${index_js_default().dim(customConfigPath)}\n`);
|
|
2119
2245
|
}
|
|
2120
2246
|
for (let file of [
|
|
2121
2247
|
'rsbuild.config.mjs',
|
|
@@ -2152,7 +2278,7 @@ var __webpack_exports__ = {};
|
|
|
2152
2278
|
});
|
|
2153
2279
|
watcher.on('add', callback), watcher.on('change', callback), watcher.on('unlink', callback);
|
|
2154
2280
|
}
|
|
2155
|
-
async function config_loadConfig({ cwd = process.cwd(), path, envMode } = {}) {
|
|
2281
|
+
async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta } = {}) {
|
|
2156
2282
|
let configExport;
|
|
2157
2283
|
let configFilePath = resolveConfigPath(cwd, path);
|
|
2158
2284
|
if (!configFilePath) return {
|
|
@@ -2166,7 +2292,7 @@ var __webpack_exports__ = {};
|
|
|
2166
2292
|
let exportModule = await import(`${configFilePath}?t=${Date.now()}`);
|
|
2167
2293
|
configExport = exportModule.default ? exportModule.default : exportModule;
|
|
2168
2294
|
} catch (err) {
|
|
2169
|
-
|
|
2295
|
+
rslog_index_js_namespaceObject.logger.debug(`Failed to load file with dynamic import: ${index_js_default().dim(configFilePath)}`);
|
|
2170
2296
|
}
|
|
2171
2297
|
try {
|
|
2172
2298
|
if (void 0 === configExport) {
|
|
@@ -2178,13 +2304,14 @@ var __webpack_exports__ = {};
|
|
|
2178
2304
|
})(configFilePath);
|
|
2179
2305
|
}
|
|
2180
2306
|
} catch (err) {
|
|
2181
|
-
throw
|
|
2307
|
+
throw rslog_index_js_namespaceObject.logger.error(`Failed to load file with jiti: ${index_js_default().dim(configFilePath)}`), err;
|
|
2182
2308
|
}
|
|
2183
2309
|
if ('function' == typeof configExport) {
|
|
2184
2310
|
let command = process.argv[2], nodeEnv = getNodeEnv(), result = await configExport({
|
|
2185
2311
|
env: nodeEnv,
|
|
2186
2312
|
command,
|
|
2187
|
-
envMode: envMode || nodeEnv
|
|
2313
|
+
envMode: envMode || nodeEnv,
|
|
2314
|
+
meta
|
|
2188
2315
|
});
|
|
2189
2316
|
if (void 0 === result) throw Error('The config function must return a config object.');
|
|
2190
2317
|
return {
|
|
@@ -2192,7 +2319,7 @@ var __webpack_exports__ = {};
|
|
|
2192
2319
|
filePath: configFilePath
|
|
2193
2320
|
};
|
|
2194
2321
|
}
|
|
2195
|
-
if (!isObject(configExport)) throw Error(`The config must be an object or a function that returns an object, get ${
|
|
2322
|
+
if (!isObject(configExport)) throw Error(`The config must be an object or a function that returns an object, get ${index_js_default().yellow(configExport)}`);
|
|
2196
2323
|
return {
|
|
2197
2324
|
content: applyMetaInfo(configExport),
|
|
2198
2325
|
filePath: configFilePath
|
|
@@ -2255,8 +2382,8 @@ var __webpack_exports__ = {};
|
|
|
2255
2382
|
await external_node_fs_default().promises.mkdir(outputPath, {
|
|
2256
2383
|
recursive: !0
|
|
2257
2384
|
}), await Promise.all(files.map(async (item)=>external_node_fs_default().promises.writeFile(item.path, `export default ${item.content}`)));
|
|
2258
|
-
let fileInfos = files.map((item)=>` - ${
|
|
2259
|
-
|
|
2385
|
+
let fileInfos = files.map((item)=>` - ${index_js_default().bold(index_js_default().yellow(item.label))}: ${index_js_default().underline(item.path)}`).join('\n');
|
|
2386
|
+
rslog_index_js_namespaceObject.logger.success(`Inspect config succeed, open following files to view the content: \n\n${fileInfos}\n`);
|
|
2260
2387
|
}
|
|
2261
2388
|
function stringifyConfig(config, verbose) {
|
|
2262
2389
|
return (0, rspack_chain_index_js_default().toString)(config, {
|
|
@@ -2281,74 +2408,7 @@ var __webpack_exports__ = {};
|
|
|
2281
2408
|
...publicDir
|
|
2282
2409
|
}
|
|
2283
2410
|
];
|
|
2284
|
-
},
|
|
2285
|
-
class BrowserslistError extends Error {
|
|
2286
|
-
constructor(message){
|
|
2287
|
-
super(message), function(obj, key, value) {
|
|
2288
|
-
key in obj ? Object.defineProperty(obj, key, {
|
|
2289
|
-
value: value,
|
|
2290
|
-
enumerable: !0,
|
|
2291
|
-
configurable: !0,
|
|
2292
|
-
writable: !0
|
|
2293
|
-
}) : obj[key] = value;
|
|
2294
|
-
}(this, "browserslist", void 0), this.name = 'BrowserslistError', this.browserslist = !0, Error.captureStackTrace && Error.captureStackTrace(this, BrowserslistError);
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
let isFileCache = {};
|
|
2298
|
-
function isFile(file) {
|
|
2299
|
-
if (file in isFileCache) return isFileCache[file];
|
|
2300
|
-
let result = external_node_fs_.existsSync(file) && external_node_fs_.statSync(file).isFile();
|
|
2301
|
-
return isFileCache[file] = result, result;
|
|
2302
|
-
}
|
|
2303
|
-
function parsePackage(file) {
|
|
2304
|
-
let config = JSON.parse(external_node_fs_.readFileSync(file).toString().replace(/^\uFEFF/m, ''));
|
|
2305
|
-
if (config.browserlist && !config.browserslist) throw new BrowserslistError(`\`browserlist\` key instead of \`browserslist\` in ${file}`);
|
|
2306
|
-
let list = config.browserslist;
|
|
2307
|
-
for(let i in Array.isArray(list) && (list = {
|
|
2308
|
-
defaults: list
|
|
2309
|
-
}), 'string' == typeof list && (list = parseConfig(list)), list)!function(section) {
|
|
2310
|
-
let FORMAT = 'Browserslist config should be a string or an array of strings with browser queries';
|
|
2311
|
-
if (Array.isArray(section)) {
|
|
2312
|
-
for(let i = 0; i < section.length; i++)if ('string' != typeof section[i]) throw new BrowserslistError(FORMAT);
|
|
2313
|
-
} else if ('string' != typeof section) throw new BrowserslistError(FORMAT);
|
|
2314
|
-
}(list[i]);
|
|
2315
|
-
return list;
|
|
2316
|
-
}
|
|
2317
|
-
let IS_SECTION = /^\s*\[(.+)]\s*$/;
|
|
2318
|
-
function parseConfig(string) {
|
|
2319
|
-
let result = {
|
|
2320
|
-
defaults: []
|
|
2321
|
-
}, sections = [
|
|
2322
|
-
'defaults'
|
|
2323
|
-
];
|
|
2324
|
-
return string.toString().replace(/#[^\n]*/g, '').split(/\n|,/).map((line)=>line.trim()).filter((line)=>'' !== line).forEach((line)=>{
|
|
2325
|
-
let matched = line.match(IS_SECTION);
|
|
2326
|
-
matched ? (sections = matched[1].trim().split(' ')).forEach((section)=>{
|
|
2327
|
-
if (result[section]) throw new BrowserslistError(`Duplicate section ${section} in Browserslist config`);
|
|
2328
|
-
result[section] = [];
|
|
2329
|
-
}) : sections.forEach((section)=>{
|
|
2330
|
-
result[section].push(line);
|
|
2331
|
-
});
|
|
2332
|
-
}), result;
|
|
2333
|
-
}
|
|
2334
|
-
function parsePackageOrReadConfig(file) {
|
|
2335
|
-
return 'package.json' === external_node_path_.basename(file) ? parsePackage(file) : function(file) {
|
|
2336
|
-
if (!isFile(file)) throw new BrowserslistError(`Can't read ${file} config`);
|
|
2337
|
-
return parseConfig(external_node_fs_.readFileSync(file, 'utf-8'));
|
|
2338
|
-
}(file);
|
|
2339
|
-
}
|
|
2340
|
-
function pickEnv(config, opts) {
|
|
2341
|
-
let name;
|
|
2342
|
-
return 'object' != typeof config ? config : ('string' == typeof opts.env ? name = opts.env : process.env.BROWSERSLIST_ENV ? name = process.env.BROWSERSLIST_ENV : process.env.NODE_ENV ? name = process.env.NODE_ENV : name = 'production', config[name] || config.defaults);
|
|
2343
|
-
}
|
|
2344
|
-
function eachParent(file, callback) {
|
|
2345
|
-
let dir = isFile(file) ? external_node_path_.dirname(file) : file, loc = external_node_path_.resolve(dir);
|
|
2346
|
-
do {
|
|
2347
|
-
let result = callback(loc);
|
|
2348
|
-
if (void 0 !== result) return result;
|
|
2349
|
-
}while (loc !== (loc = external_node_path_.dirname(loc)));
|
|
2350
|
-
}
|
|
2351
|
-
let configCache = {}, RSBUILD_ALL_ENVIRONMENT_SYMBOL = 'RSBUILD_ALL_ENVIRONMENT_SYMBOL', isPluginMatchEnvironment = (pluginEnvironment, currentEnvironment)=>pluginEnvironment === currentEnvironment || pluginEnvironment === RSBUILD_ALL_ENVIRONMENT_SYMBOL, pluginDagSort = (plugins)=>{
|
|
2411
|
+
}, RSBUILD_ALL_ENVIRONMENT_SYMBOL = 'RSBUILD_ALL_ENVIRONMENT_SYMBOL', isPluginMatchEnvironment = (pluginEnvironment, currentEnvironment)=>pluginEnvironment === currentEnvironment || pluginEnvironment === RSBUILD_ALL_ENVIRONMENT_SYMBOL, pluginDagSort = (plugins)=>{
|
|
2352
2412
|
let allLines = [];
|
|
2353
2413
|
function getPlugin(name) {
|
|
2354
2414
|
let targets = plugins.filter((item)=>item.instance.name === name);
|
|
@@ -2378,7 +2438,7 @@ var __webpack_exports__ = {};
|
|
|
2378
2438
|
return sortedPoint;
|
|
2379
2439
|
};
|
|
2380
2440
|
async function initPlugins({ getPluginAPI, pluginManager }) {
|
|
2381
|
-
|
|
2441
|
+
rslog_index_js_namespaceObject.logger.debug('init plugins');
|
|
2382
2442
|
let plugins = pluginDagSort(pluginManager.getAllPluginsWithMeta()), removedPlugins = plugins.reduce((ret, plugin)=>(plugin.instance.remove && (ret[plugin.environment] ??= [], ret[plugin.environment].push(...plugin.instance.remove)), ret), {});
|
|
2383
2443
|
for (let plugin of plugins){
|
|
2384
2444
|
var _removedPlugins_plugin_environment, _removedPlugins_RSBUILD_ALL_ENVIRONMENT_SYMBOL;
|
|
@@ -2387,7 +2447,7 @@ var __webpack_exports__ = {};
|
|
|
2387
2447
|
let { instance, environment } = plugin;
|
|
2388
2448
|
await instance.setup(getPluginAPI(environment));
|
|
2389
2449
|
}
|
|
2390
|
-
|
|
2450
|
+
rslog_index_js_namespaceObject.logger.debug('init plugins done');
|
|
2391
2451
|
}
|
|
2392
2452
|
function createEnvironmentAsyncHook() {
|
|
2393
2453
|
let preGroup = [], postGroup = [], defaultGroup = [], tapEnvironment = ({ environment, handler: cb })=>{
|
|
@@ -2657,7 +2717,7 @@ var __webpack_exports__ = {};
|
|
|
2657
2717
|
let filename;
|
|
2658
2718
|
filename = config.output.filename.html ? config.output.filename.html.replace('[name]', entryName) : 'flat' === config.html.outputStructure ? `${entryName}.html` : `${entryName}/index.html`;
|
|
2659
2719
|
let prefix = config.output.distPath.html;
|
|
2660
|
-
return prefix.startsWith('/') &&
|
|
2720
|
+
return prefix.startsWith('/') && rslog_index_js_namespaceObject.logger.warn(`Absolute path is not recommended at \`output.distPath.html\`: "${prefix}", please use relative path instead.`), removeLeadingSlash(external_node_path_.posix.join(prefix, filename));
|
|
2661
2721
|
}(key, config)), prev;
|
|
2662
2722
|
}, {});
|
|
2663
2723
|
async function updateEnvironmentContext(context, configs) {
|
|
@@ -2677,14 +2737,14 @@ var __webpack_exports__ = {};
|
|
|
2677
2737
|
};
|
|
2678
2738
|
context.environments[name] = new Proxy(environmentContext, {
|
|
2679
2739
|
get: (target, prop)=>target[prop],
|
|
2680
|
-
set: (_, prop)=>(
|
|
2740
|
+
set: (_, prop)=>(rslog_index_js_namespaceObject.logger.error(`EnvironmentContext is readonly, you can not assign to the "environment.${prop}" prop.`), !0)
|
|
2681
2741
|
});
|
|
2682
2742
|
}
|
|
2683
2743
|
}
|
|
2684
2744
|
async function createContext(options, userConfig, bundlerType) {
|
|
2685
2745
|
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');
|
|
2686
2746
|
return {
|
|
2687
|
-
version: "1.1.
|
|
2747
|
+
version: "1.1.4",
|
|
2688
2748
|
rootPath,
|
|
2689
2749
|
distPath: '',
|
|
2690
2750
|
cachePath,
|
|
@@ -2961,7 +3021,7 @@ var __webpack_exports__ = {};
|
|
|
2961
3021
|
if (!0 === cleanDistPath || 'auto' === cleanDistPath && isStrictSubdir(rootPath, cleanPath)) return cleanPath;
|
|
2962
3022
|
}, getCleanPath = (environment)=>{
|
|
2963
3023
|
let { rootPath } = api.context, { config, distPath } = environment, { cleanDistPath } = config.output;
|
|
2964
|
-
if ('auto' === cleanDistPath && !(cleanDistPath = isStrictSubdir(rootPath, distPath)) && (
|
|
3024
|
+
if ('auto' === cleanDistPath && !(cleanDistPath = isStrictSubdir(rootPath, distPath)) && (rslog_index_js_namespaceObject.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), rslog_index_js_namespaceObject.logger.warn(`Please set ${index_js_default().yellow('`output.cleanDistPath`')} config manually.`), rslog_index_js_namespaceObject.logger.warn(`Current root path: ${index_js_default().dim(rootPath)}`), rslog_index_js_namespaceObject.logger.warn(`Current dist path: ${index_js_default().dim(distPath)}`)), cleanDistPath) return distPath;
|
|
2965
3025
|
}, cleanAll = async (params)=>{
|
|
2966
3026
|
let cleanPaths = Object.values(params.environments).reduce((total, curr)=>(!total.find((t)=>t.distPath === curr.distPath) && total.push(curr), total), []).map((e)=>getCleanPath(e)).concat(getRsbuildCleanPath()).filter((p)=>!!p);
|
|
2967
3027
|
await Promise.all(dedupeCleanPaths(cleanPaths).map((p)=>emptyDir(p)));
|
|
@@ -3008,11 +3068,7 @@ var __webpack_exports__ = {};
|
|
|
3008
3068
|
mergeFn
|
|
3009
3069
|
}), initial) : config ?? initial;
|
|
3010
3070
|
}
|
|
3011
|
-
let
|
|
3012
|
-
plugin && (pluginHelper_htmlPlugin = plugin);
|
|
3013
|
-
}, getHTMLPlugin = ()=>(!pluginHelper_htmlPlugin && (pluginHelper_htmlPlugin = pluginHelper_require('../compiled/html-rspack-plugin/index.js')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
|
|
3014
|
-
cssExtractPlugin = plugin;
|
|
3015
|
-
}, getCssExtractPlugin = ()=>cssExtractPlugin ? cssExtractPlugin : core_default().CssExtractRspackPlugin, getCSSModulesLocalIdentName = (config, isProd)=>config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), normalizeCssLoaderOptions = (options, exportOnlyLocals)=>{
|
|
3071
|
+
let getCSSModulesLocalIdentName = (config, isProd)=>config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), normalizeCssLoaderOptions = (options, exportOnlyLocals)=>{
|
|
3016
3072
|
if (options.modules && exportOnlyLocals) {
|
|
3017
3073
|
let { modules } = options;
|
|
3018
3074
|
return modules = !0 === modules ? {
|
|
@@ -3096,62 +3152,56 @@ var __webpack_exports__ = {};
|
|
|
3096
3152
|
config: config.tools.cssLoader,
|
|
3097
3153
|
mergeFn: cjs_default()
|
|
3098
3154
|
}), !emitCss);
|
|
3099
|
-
}
|
|
3100
|
-
async function applyCSSRule({ rule, config, context, utils: { target, isProd, CHAIN_ID, environment } }) {
|
|
3101
|
-
let emitCss = config.output.emitCss ?? 'web' === target;
|
|
3102
|
-
if (emitCss) {
|
|
3103
|
-
if (config.output.injectStyles) {
|
|
3104
|
-
let styleLoaderOptions = reduceConfigs({
|
|
3105
|
-
initial: {},
|
|
3106
|
-
config: config.tools.styleLoader
|
|
3107
|
-
});
|
|
3108
|
-
rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
|
|
3109
|
-
} else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions);
|
|
3110
|
-
} else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_default().join(LOADER_PATH, 'ignoreCssLoader.cjs'));
|
|
3111
|
-
let importLoaders = 0;
|
|
3112
|
-
if (rule.use(CHAIN_ID.USE.CSS).loader(getCompiledPath('css-loader')), emitCss) {
|
|
3113
|
-
var _postcssLoaderOptions_postcssOptions_plugins, _postcssLoaderOptions_postcssOptions;
|
|
3114
|
-
if ('rspack' === context.bundlerType && !1 !== config.tools.lightningcssLoader) {
|
|
3115
|
-
importLoaders++;
|
|
3116
|
-
let userOptions = !0 === config.tools.lightningcssLoader ? {} : config.tools.lightningcssLoader, initialOptions = {
|
|
3117
|
-
targets: environment.browserslist
|
|
3118
|
-
};
|
|
3119
|
-
'production' === config.mode && config.output.injectStyles && (initialOptions.minify = !0);
|
|
3120
|
-
let loaderOptions = reduceConfigs({
|
|
3121
|
-
initial: initialOptions,
|
|
3122
|
-
config: userOptions
|
|
3123
|
-
});
|
|
3124
|
-
rule.use(CHAIN_ID.USE.LIGHTNINGCSS).loader('builtin:lightningcss-loader').options(loaderOptions);
|
|
3125
|
-
}
|
|
3126
|
-
let postcssLoaderOptions = await getPostcssLoaderOptions({
|
|
3127
|
-
config,
|
|
3128
|
-
root: context.rootPath
|
|
3129
|
-
});
|
|
3130
|
-
('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) && (importLoaders++, rule.use(CHAIN_ID.USE.POSTCSS).loader(getCompiledPath('postcss-loader')).options(postcssLoaderOptions));
|
|
3131
|
-
}
|
|
3132
|
-
let localIdentName = getCSSModulesLocalIdentName(config, isProd), cssLoaderOptions = getCSSLoaderOptions({
|
|
3133
|
-
config,
|
|
3134
|
-
importLoaders,
|
|
3135
|
-
localIdentName,
|
|
3136
|
-
emitCss
|
|
3137
|
-
});
|
|
3138
|
-
rule.use(CHAIN_ID.USE.CSS).options(cssLoaderOptions), rule.merge({
|
|
3139
|
-
sideEffects: !0
|
|
3140
|
-
}), rule.resolve.preferRelative(!0);
|
|
3141
|
-
}
|
|
3142
|
-
let pluginCss = ()=>({
|
|
3155
|
+
}, pluginCss = ()=>({
|
|
3143
3156
|
name: 'rsbuild:css',
|
|
3144
3157
|
setup (api) {
|
|
3145
3158
|
api.modifyBundlerChain({
|
|
3146
3159
|
order: 'pre',
|
|
3147
|
-
handler: async (chain,
|
|
3148
|
-
let rule = chain.module.rule(
|
|
3149
|
-
rule.test(CSS_REGEX).type('javascript/auto')
|
|
3150
|
-
|
|
3151
|
-
|
|
3160
|
+
handler: async (chain, { target, isProd, CHAIN_ID, environment })=>{
|
|
3161
|
+
let rule = chain.module.rule(CHAIN_ID.RULE.CSS), { config } = environment;
|
|
3162
|
+
rule.test(CSS_REGEX).type('javascript/auto').dependency({
|
|
3163
|
+
not: 'url'
|
|
3164
|
+
});
|
|
3165
|
+
let emitCss = config.output.emitCss ?? 'web' === target;
|
|
3166
|
+
if (emitCss) {
|
|
3167
|
+
if (config.output.injectStyles) {
|
|
3168
|
+
let styleLoaderOptions = reduceConfigs({
|
|
3169
|
+
initial: {},
|
|
3170
|
+
config: config.tools.styleLoader
|
|
3171
|
+
});
|
|
3172
|
+
rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
|
|
3173
|
+
} else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions);
|
|
3174
|
+
} else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_default().join(LOADER_PATH, 'ignoreCssLoader.cjs'));
|
|
3175
|
+
let importLoaders = 0;
|
|
3176
|
+
if (rule.use(CHAIN_ID.USE.CSS).loader(getCompiledPath('css-loader')), emitCss) {
|
|
3177
|
+
var _postcssLoaderOptions_postcssOptions_plugins, _postcssLoaderOptions_postcssOptions;
|
|
3178
|
+
if ('rspack' === api.context.bundlerType && !1 !== config.tools.lightningcssLoader) {
|
|
3179
|
+
importLoaders++;
|
|
3180
|
+
let userOptions = !0 === config.tools.lightningcssLoader ? {} : config.tools.lightningcssLoader, initialOptions = {
|
|
3181
|
+
targets: environment.browserslist
|
|
3182
|
+
};
|
|
3183
|
+
'production' === config.mode && config.output.injectStyles && (initialOptions.minify = !0);
|
|
3184
|
+
let loaderOptions = reduceConfigs({
|
|
3185
|
+
initial: initialOptions,
|
|
3186
|
+
config: userOptions
|
|
3187
|
+
});
|
|
3188
|
+
rule.use(CHAIN_ID.USE.LIGHTNINGCSS).loader('builtin:lightningcss-loader').options(loaderOptions);
|
|
3189
|
+
}
|
|
3190
|
+
let postcssLoaderOptions = await getPostcssLoaderOptions({
|
|
3191
|
+
config,
|
|
3192
|
+
root: api.context.rootPath
|
|
3193
|
+
});
|
|
3194
|
+
('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) && (importLoaders++, rule.use(CHAIN_ID.USE.POSTCSS).loader(getCompiledPath('postcss-loader')).options(postcssLoaderOptions));
|
|
3195
|
+
}
|
|
3196
|
+
let localIdentName = getCSSModulesLocalIdentName(config, isProd), cssLoaderOptions = getCSSLoaderOptions({
|
|
3152
3197
|
config,
|
|
3153
|
-
|
|
3198
|
+
importLoaders,
|
|
3199
|
+
localIdentName,
|
|
3200
|
+
emitCss
|
|
3154
3201
|
});
|
|
3202
|
+
rule.use(CHAIN_ID.USE.CSS).options(cssLoaderOptions), rule.merge({
|
|
3203
|
+
sideEffects: !0
|
|
3204
|
+
}), rule.resolve.preferRelative(!0);
|
|
3155
3205
|
}
|
|
3156
3206
|
});
|
|
3157
3207
|
}
|
|
@@ -3191,7 +3241,7 @@ var __webpack_exports__ = {};
|
|
|
3191
3241
|
preEntry.forEach(addEntry), injectCoreJsEntry && addEntry(createVirtualModule('import "core-js";')), castArray(entry[entryName]).forEach(addEntry);
|
|
3192
3242
|
}
|
|
3193
3243
|
}), api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
|
|
3194
|
-
if (bundlerConfigs.every((config)=>!config.entry)) throw Error(`Could not find any entry module, please make sure that ${
|
|
3244
|
+
if (bundlerConfigs.every((config)=>!config.entry)) throw Error(`Could not find any entry module, please make sure that ${index_js_default().cyan('src/index.(ts|js|tsx|jsx|mjs|cjs)')} exists, or customize entry through the ${index_js_default().cyan('source.entry')} configuration.`);
|
|
3195
3245
|
});
|
|
3196
3246
|
}
|
|
3197
3247
|
}), external_node_zlib_namespaceObject = require("node:zlib");
|
|
@@ -3200,10 +3250,10 @@ var __webpack_exports__ = {};
|
|
|
3200
3250
|
async function gzipSize(input) {
|
|
3201
3251
|
return (await fileSize_gzip(input)).length;
|
|
3202
3252
|
}
|
|
3203
|
-
let filterAsset = (asset)=>!/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset), getAssetColor = (size)=>size > 300000 ?
|
|
3253
|
+
let filterAsset = (asset)=>!/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset), getAssetColor = (size)=>size > 300000 ? index_js_default().red : size > 100000 ? index_js_default().yellow : index_js_default().green, calcFileSize = (len)=>{
|
|
3204
3254
|
let val = len / 1000;
|
|
3205
3255
|
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
3206
|
-
}, coloringAssetName = (assetName)=>JS_REGEX.test(assetName) ?
|
|
3256
|
+
}, coloringAssetName = (assetName)=>JS_REGEX.test(assetName) ? index_js_default().cyan(assetName) : CSS_REGEX.test(assetName) ? index_js_default().yellow(assetName) : HTML_REGEX.test(assetName) ? index_js_default().green(assetName) : index_js_default().magenta(assetName);
|
|
3207
3257
|
async function printFileSizes(options, stats, rootPath, environmentName) {
|
|
3208
3258
|
let logs = [];
|
|
3209
3259
|
if (!1 === options.detail && !1 === options.total) return logs;
|
|
@@ -3248,22 +3298,22 @@ var __webpack_exports__ = {};
|
|
|
3248
3298
|
let length = longestLengths[index], curLabel = cur;
|
|
3249
3299
|
return length && (curLabel = cur.length < length ? cur + ' '.repeat(length - cur.length) : cur), `${prev + curLabel} `;
|
|
3250
3300
|
}, ' ');
|
|
3251
|
-
return
|
|
3301
|
+
return index_js_default().blue(headerRow);
|
|
3252
3302
|
}(longestFileLength, longestLabelLength, options, environmentName));
|
|
3253
3303
|
let totalSize = 0, totalGzipSize = 0;
|
|
3254
3304
|
for (let asset of assets){
|
|
3255
3305
|
let { sizeLabel } = asset, { name, folder, gzipSizeLabel } = asset, fileNameLength = (folder + external_node_path_default().sep + name).length, sizeLength = sizeLabel.length;
|
|
3256
3306
|
if (totalSize += asset.size, asset.gzippedSize && (totalGzipSize += asset.gzippedSize), !1 !== options.detail) {
|
|
3257
3307
|
sizeLength < longestLabelLength && (sizeLabel += ' '.repeat(longestLabelLength - sizeLength));
|
|
3258
|
-
let fileNameLabel =
|
|
3308
|
+
let fileNameLabel = index_js_default().dim(asset.folder + external_node_path_default().sep) + coloringAssetName(asset.name);
|
|
3259
3309
|
fileNameLength < longestFileLength && (fileNameLabel += ' '.repeat(longestFileLength - fileNameLength));
|
|
3260
3310
|
let log = ` ${fileNameLabel} ${sizeLabel}`;
|
|
3261
3311
|
gzipSizeLabel && (log += ` ${gzipSizeLabel}`), logs.push(log);
|
|
3262
3312
|
}
|
|
3263
3313
|
}
|
|
3264
3314
|
if (!1 !== options.total) {
|
|
3265
|
-
let totalSizeLabel = `${
|
|
3266
|
-
options.compressed && (log +=
|
|
3315
|
+
let totalSizeLabel = `${index_js_default().blue('Total:')} ${calcFileSize(totalSize)}`, log = `\n ${totalSizeLabel}`;
|
|
3316
|
+
options.compressed && (log += index_js_default().dim(` (gzip: ${calcFileSize(totalGzipSize)})`)), log += '\n', logs.push(log);
|
|
3267
3317
|
}
|
|
3268
3318
|
return logs;
|
|
3269
3319
|
}
|
|
@@ -3286,10 +3336,10 @@ var __webpack_exports__ = {};
|
|
|
3286
3336
|
...defaultConfig,
|
|
3287
3337
|
...printFileSize
|
|
3288
3338
|
}, statsLogs = await printFileSizes(mergedConfig, multiStats[index], api.context.rootPath, environment.name);
|
|
3289
|
-
logs.length && logs.push(
|
|
3339
|
+
logs.length && logs.push(index_js_default().dim(' -----')), logs.push(...statsLogs);
|
|
3290
3340
|
})).catch((err)=>{
|
|
3291
|
-
|
|
3292
|
-
}),
|
|
3341
|
+
rslog_index_js_namespaceObject.logger.warn('Failed to print file size.'), rslog_index_js_namespaceObject.logger.warn(err);
|
|
3342
|
+
}), rslog_index_js_namespaceObject.logger.log(logs.join('\n'));
|
|
3293
3343
|
});
|
|
3294
3344
|
}
|
|
3295
3345
|
});
|
|
@@ -3463,7 +3513,7 @@ var __webpack_exports__ = {};
|
|
|
3463
3513
|
};
|
|
3464
3514
|
let absolutePath = (0, external_node_path_.isAbsolute)(templatePath) ? templatePath : external_node_path_default().resolve(rootPath, templatePath);
|
|
3465
3515
|
if (!existTemplatePath.has(absolutePath)) {
|
|
3466
|
-
if (!await isFileExists(absolutePath)) throw Error(`Failed to resolve HTML template, please check if the file exists: ${
|
|
3516
|
+
if (!await isFileExists(absolutePath)) throw Error(`Failed to resolve HTML template, please check if the file exists: ${index_js_default().cyan(absolutePath)}`);
|
|
3467
3517
|
existTemplatePath.add(absolutePath);
|
|
3468
3518
|
}
|
|
3469
3519
|
let templateContent = await external_node_fs_default().promises.readFile(absolutePath, 'utf-8');
|
|
@@ -3966,7 +4016,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
3966
4016
|
let trailingSlashBase = addTrailingSlash(base);
|
|
3967
4017
|
return path.startsWith(trailingSlashBase) ? path.slice(trailingSlashBase.length - 1) : path;
|
|
3968
4018
|
}, getRoutes = (context)=>Object.values(context.environments).reduce((prev, environmentContext)=>{
|
|
3969
|
-
let { distPath, config } = environmentContext, distPrefix = external_node_path_.
|
|
4019
|
+
let { distPath, config } = environmentContext, distPrefix = (0, external_node_path_.relative)(context.distPath, distPath).split(external_node_path_.sep).join('/'), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, external_node_path_.posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
|
|
3970
4020
|
return prev.concat(...routes);
|
|
3971
4021
|
}, []), formatRoutes = (entry, base, distPathPrefix, outputStructure)=>{
|
|
3972
4022
|
let prefix = joinUrlSegments(base, formatPrefix(distPathPrefix));
|
|
@@ -3997,16 +4047,16 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
3997
4047
|
if (routes.length <= 1) {
|
|
3998
4048
|
let pathname = routes.length ? routes[0].pathname : '';
|
|
3999
4049
|
return urls.map(({ label, url })=>{
|
|
4000
|
-
let normalizedPathname = normalizeUrl(`${url}${pathname}`), prefix = `➜ ${
|
|
4001
|
-
return ` ${prefix}${
|
|
4050
|
+
let normalizedPathname = normalizeUrl(`${url}${pathname}`), prefix = `➜ ${index_js_default().dim(label.padEnd(10))}`;
|
|
4051
|
+
return ` ${prefix}${index_js_default().cyan(normalizedPathname)}\n`;
|
|
4002
4052
|
}).join('');
|
|
4003
4053
|
}
|
|
4004
4054
|
let message = '', maxNameLength = Math.max(...routes.map((r)=>r.entryName.length));
|
|
4005
4055
|
return urls.forEach(({ label, url }, index)=>{
|
|
4006
|
-
for (let r of (index > 0 && (message += '\n'), message += ` ➜ ${label}\n`, routes))message += ` ${
|
|
4056
|
+
for (let r of (index > 0 && (message += '\n'), message += ` ➜ ${label}\n`, routes))message += ` ${index_js_default().dim('-')} ${index_js_default().dim(r.entryName.padEnd(maxNameLength + 4))}${index_js_default().cyan(normalizeUrl(`${url}${r.pathname}`))}\n`;
|
|
4007
4057
|
}), message;
|
|
4008
4058
|
}(urls, routes);
|
|
4009
|
-
return !1 === trailingLineBreak && message.endsWith('\n') && (message = message.slice(0, -1)),
|
|
4059
|
+
return !1 === trailingLineBreak && message.endsWith('\n') && (message = message.slice(0, -1)), rslog_index_js_namespaceObject.logger.log(message), message;
|
|
4010
4060
|
}
|
|
4011
4061
|
let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
4012
4062
|
'string' == typeof port && (port = Number.parseInt(port, 10)), strictPort && (tryLimits = 1);
|
|
@@ -4032,7 +4082,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4032
4082
|
host,
|
|
4033
4083
|
port: originalPort,
|
|
4034
4084
|
strictPort: config.server.strictPort || !1
|
|
4035
|
-
}), https = !!config.server.https, portTip = port !== originalPort ? `Port ${originalPort} is in use, ${
|
|
4085
|
+
}), https = !!config.server.https, portTip = port !== originalPort ? `Port ${originalPort} is in use, ${index_js_default().yellow(`using port ${port}.`)}` : void 0;
|
|
4036
4086
|
return {
|
|
4037
4087
|
port,
|
|
4038
4088
|
host,
|
|
@@ -4129,15 +4179,15 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4129
4179
|
if (targetBrowser) return await execAsync(`osascript openChrome.applescript "${encodeURI(url)}" "${targetBrowser}"`, {
|
|
4130
4180
|
cwd: STATIC_PATH
|
|
4131
4181
|
}), !0;
|
|
4132
|
-
|
|
4182
|
+
rslog_index_js_namespaceObject.logger.debug('Failed to find the target browser.');
|
|
4133
4183
|
} catch (err) {
|
|
4134
|
-
|
|
4184
|
+
rslog_index_js_namespaceObject.logger.debug('Failed to open start URL with apple script.'), rslog_index_js_namespaceObject.logger.debug(err);
|
|
4135
4185
|
}
|
|
4136
4186
|
try {
|
|
4137
4187
|
let { default: open } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/open/index.js", 23));
|
|
4138
4188
|
return await open(url), !0;
|
|
4139
4189
|
} catch (err) {
|
|
4140
|
-
return
|
|
4190
|
+
return rslog_index_js_namespaceObject.logger.error('Failed to open start URL.'), rslog_index_js_namespaceObject.logger.error(err), !1;
|
|
4141
4191
|
}
|
|
4142
4192
|
}
|
|
4143
4193
|
let openedURLs = [], clearOpenedURLs = ()=>{
|
|
@@ -4489,18 +4539,18 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4489
4539
|
]
|
|
4490
4540
|
});
|
|
4491
4541
|
} catch (err) {
|
|
4492
|
-
|
|
4542
|
+
rslog_index_js_namespaceObject.logger.warn(`\`process.env.RSDOCTOR\` enabled, please install ${index_js_default().bold(index_js_default().yellow(packageName))} package.`);
|
|
4493
4543
|
return;
|
|
4494
4544
|
}
|
|
4495
4545
|
try {
|
|
4496
4546
|
module1 = await import(packagePath);
|
|
4497
4547
|
} catch (err) {
|
|
4498
|
-
|
|
4548
|
+
rslog_index_js_namespaceObject.logger.error(`\`process.env.RSDOCTOR\` enabled, but failed to load ${index_js_default().bold(index_js_default().yellow(packageName))} module.`);
|
|
4499
4549
|
return;
|
|
4500
4550
|
}
|
|
4501
4551
|
if (!!module1 && !!module1[pluginName]) {
|
|
4502
4552
|
for (let config of bundlerConfigs)config.plugins ||= [], config.plugins.push(new module1[pluginName]());
|
|
4503
|
-
|
|
4553
|
+
rslog_index_js_namespaceObject.logger.info(`${index_js_default().bold(index_js_default().yellow(packageName))} enabled.`);
|
|
4504
4554
|
}
|
|
4505
4555
|
});
|
|
4506
4556
|
}
|
|
@@ -4509,7 +4559,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4509
4559
|
let stopProfiler = (output, profileSession)=>{
|
|
4510
4560
|
if (!!profileSession) profileSession.post('Profiler.stop', (error, param)=>{
|
|
4511
4561
|
if (error) {
|
|
4512
|
-
|
|
4562
|
+
rslog_index_js_namespaceObject.logger.error('Failed to generate JS CPU profile:', error);
|
|
4513
4563
|
return;
|
|
4514
4564
|
}
|
|
4515
4565
|
external_node_fs_default().writeFileSync(output, JSON.stringify(param.profile));
|
|
@@ -4543,7 +4593,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4543
4593
|
}), api.onExit(()=>{
|
|
4544
4594
|
enableProfileTrace && core_default().experiments.globalTrace.cleanup();
|
|
4545
4595
|
let profileDir = external_node_path_default().join(api.context.distPath, profileDirName);
|
|
4546
|
-
stopProfiler(external_node_path_default().join(profileDir, 'jscpuprofile.json'), profileSession),
|
|
4596
|
+
stopProfiler(external_node_path_default().join(profileDir, 'jscpuprofile.json'), profileSession), rslog_index_js_namespaceObject.logger.info(`Saved Rspack profile file to ${profileDir}`);
|
|
4547
4597
|
});
|
|
4548
4598
|
}
|
|
4549
4599
|
}), pluginServer = ()=>({
|
|
@@ -4764,7 +4814,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4764
4814
|
if (!!assetName) if (assets[assetName]) {
|
|
4765
4815
|
let integrity = calcIntegrity(algorithm, assetName, assets[assetName].buffer());
|
|
4766
4816
|
replacedHtml = replacedHtml.replaceAll(`integrity="${placeholder}${assetName}"`, `integrity="${integrity}"`);
|
|
4767
|
-
} else
|
|
4817
|
+
} else rslog_index_js_namespaceObject.logger.debug(`[rsbuild:sri] failed to generate integrity for ${assetName}.`), replacedHtml = replacedHtml.replace(`integrity="${placeholder}${assetName}"`, '');
|
|
4768
4818
|
}
|
|
4769
4819
|
return replacedHtml;
|
|
4770
4820
|
};
|
|
@@ -4790,7 +4840,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4790
4840
|
order: 'pre',
|
|
4791
4841
|
handler: async (chain, { CHAIN_ID, isDev, target, environment })=>{
|
|
4792
4842
|
var browserslist, target1;
|
|
4793
|
-
let { config, browserslist: browserslist1 } = 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')
|
|
4843
|
+
let { config, browserslist: browserslist1 } = 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({
|
|
4844
|
+
not: 'url'
|
|
4845
|
+
}), dataUriRule = chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
4794
4846
|
or: [
|
|
4795
4847
|
'text/javascript',
|
|
4796
4848
|
'application/javascript'
|
|
@@ -4972,7 +5024,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4972
5024
|
}
|
|
4973
5025
|
async function modifyBundlerChain(context, utils) {
|
|
4974
5026
|
var _utils_environment_config_tools;
|
|
4975
|
-
|
|
5027
|
+
rslog_index_js_namespaceObject.logger.debug('modify bundler chain');
|
|
4976
5028
|
let bundlerChain = new (rspack_chain_index_js_default())(), [modifiedBundlerChain] = await context.hooks.modifyBundlerChain.callInEnvironment({
|
|
4977
5029
|
environment: utils.environment.name,
|
|
4978
5030
|
args: [
|
|
@@ -4981,7 +5033,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4981
5033
|
]
|
|
4982
5034
|
});
|
|
4983
5035
|
if (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.bundlerChain) for (let item of castArray(utils.environment.config.tools.bundlerChain))await item(modifiedBundlerChain, utils);
|
|
4984
|
-
return
|
|
5036
|
+
return rslog_index_js_namespaceObject.logger.debug('modify bundler chain done'), modifiedBundlerChain;
|
|
4985
5037
|
}
|
|
4986
5038
|
function chainToConfig(chain) {
|
|
4987
5039
|
let config = chain.toConfig(), { entry } = config;
|
|
@@ -5078,7 +5130,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5078
5130
|
};
|
|
5079
5131
|
async function modifyRspackConfig(context, rspackConfig, utils) {
|
|
5080
5132
|
var _utils_environment_config_tools;
|
|
5081
|
-
|
|
5133
|
+
rslog_index_js_namespaceObject.logger.debug('modify Rspack config');
|
|
5082
5134
|
let [modifiedConfig] = await context.hooks.modifyRspackConfig.callInEnvironment({
|
|
5083
5135
|
environment: utils.environment.name,
|
|
5084
5136
|
args: [
|
|
@@ -5091,7 +5143,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5091
5143
|
config: utils.environment.config.tools.rspack,
|
|
5092
5144
|
ctx: utils,
|
|
5093
5145
|
mergeFn: utils.mergeConfig
|
|
5094
|
-
})),
|
|
5146
|
+
})), rslog_index_js_namespaceObject.logger.debug('modify Rspack config done'), modifiedConfig;
|
|
5095
5147
|
}
|
|
5096
5148
|
async function getConfigUtils(config, chainUtils) {
|
|
5097
5149
|
let { merge } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/webpack-merge/index.js", 23));
|
|
@@ -5146,21 +5198,21 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5146
5198
|
}));
|
|
5147
5199
|
if ((rspackConfig = await modifyRspackConfig(context, rspackConfig, await getConfigUtils(rspackConfig, chainUtils))).plugins) {
|
|
5148
5200
|
for (let plugin of rspackConfig.plugins)if (plugin && void 0 === plugin.apply && 'name' in plugin && 'setup' in plugin) {
|
|
5149
|
-
let name =
|
|
5201
|
+
let name = index_js_default().bold(index_js_default().yellow(plugin.name));
|
|
5150
5202
|
throw Error(`${name} appears to be an Rsbuild plugin. It cannot be used as an Rspack plugin.`);
|
|
5151
5203
|
}
|
|
5152
5204
|
}
|
|
5153
5205
|
return rspackConfig;
|
|
5154
5206
|
}
|
|
5155
5207
|
async function modifyRsbuildConfig(context) {
|
|
5156
|
-
|
|
5208
|
+
rslog_index_js_namespaceObject.logger.debug('modify Rsbuild config');
|
|
5157
5209
|
let [modified] = await context.hooks.modifyRsbuildConfig.call(context.config, {
|
|
5158
5210
|
mergeRsbuildConfig: mergeRsbuildConfig
|
|
5159
5211
|
});
|
|
5160
|
-
context.config = modified,
|
|
5212
|
+
context.config = modified, rslog_index_js_namespaceObject.logger.debug('modify Rsbuild config done');
|
|
5161
5213
|
}
|
|
5162
5214
|
async function modifyEnvironmentConfig(context, config, name) {
|
|
5163
|
-
|
|
5215
|
+
rslog_index_js_namespaceObject.logger.debug(`modify Rsbuild environment(${name}) config`);
|
|
5164
5216
|
let [modified] = await context.hooks.modifyEnvironmentConfig.callInEnvironment({
|
|
5165
5217
|
environment: name,
|
|
5166
5218
|
args: [
|
|
@@ -5171,7 +5223,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5171
5223
|
}
|
|
5172
5224
|
]
|
|
5173
5225
|
});
|
|
5174
|
-
return
|
|
5226
|
+
return rslog_index_js_namespaceObject.logger.debug(`modify Rsbuild environment(${name}) config done`), modified;
|
|
5175
5227
|
}
|
|
5176
5228
|
let initEnvironmentConfigs = (normalizedConfig, rootPath, specifiedEnvironments)=>{
|
|
5177
5229
|
let defaultEntry;
|
|
@@ -5208,11 +5260,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5208
5260
|
}, config)
|
|
5209
5261
|
})
|
|
5210
5262
|
]));
|
|
5211
|
-
if (!Object.keys(resolvedEnvironments).length) throw Error(`The current build is specified to run only in the ${
|
|
5263
|
+
if (!Object.keys(resolvedEnvironments).length) throw Error(`The current build is specified to run only in the ${index_js_default().yellow(null == specifiedEnvironments ? void 0 : specifiedEnvironments.join(','))} environment, but the configuration of the specified environment was not found.`);
|
|
5212
5264
|
return resolvedEnvironments;
|
|
5213
5265
|
}
|
|
5214
5266
|
let defaultEnvironmentName = camelCase(rsbuildSharedConfig.output.target);
|
|
5215
|
-
if (!isEnvironmentEnabled(defaultEnvironmentName)) throw Error(`The current build is specified to run only in the ${
|
|
5267
|
+
if (!isEnvironmentEnabled(defaultEnvironmentName)) throw Error(`The current build is specified to run only in the ${index_js_default().yellow(null == specifiedEnvironments ? void 0 : specifiedEnvironments.join(','))} environment, but the configuration of the specified environment was not found.`);
|
|
5216
5268
|
return {
|
|
5217
5269
|
[defaultEnvironmentName]: applyEnvironmentDefaultConfig({
|
|
5218
5270
|
...rsbuildSharedConfig,
|
|
@@ -5301,19 +5353,19 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5301
5353
|
let shortcuts = [
|
|
5302
5354
|
{
|
|
5303
5355
|
key: 'c',
|
|
5304
|
-
description: `${
|
|
5356
|
+
description: `${index_js_default().bold('c + enter')} ${index_js_default().dim('clear console')}`,
|
|
5305
5357
|
action: ()=>{
|
|
5306
5358
|
console.clear();
|
|
5307
5359
|
}
|
|
5308
5360
|
},
|
|
5309
5361
|
{
|
|
5310
5362
|
key: 'o',
|
|
5311
|
-
description: `${
|
|
5363
|
+
description: `${index_js_default().bold('o + enter')} ${index_js_default().dim('open in browser')}`,
|
|
5312
5364
|
action: openPage
|
|
5313
5365
|
},
|
|
5314
5366
|
{
|
|
5315
5367
|
key: 'q',
|
|
5316
|
-
description: `${
|
|
5368
|
+
description: `${index_js_default().bold('q + enter')} ${index_js_default().dim('quit process')}`,
|
|
5317
5369
|
action: async ()=>{
|
|
5318
5370
|
try {
|
|
5319
5371
|
await closeServer();
|
|
@@ -5324,25 +5376,25 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5324
5376
|
},
|
|
5325
5377
|
restartServer ? {
|
|
5326
5378
|
key: 'r',
|
|
5327
|
-
description: `${
|
|
5379
|
+
description: `${index_js_default().bold('r + enter')} ${index_js_default().dim('restart server')}`,
|
|
5328
5380
|
action: restartServer
|
|
5329
5381
|
} : null,
|
|
5330
5382
|
{
|
|
5331
5383
|
key: 'u',
|
|
5332
|
-
description: `${
|
|
5384
|
+
description: `${index_js_default().bold('u + enter')} ${index_js_default().dim('show urls')}`,
|
|
5333
5385
|
action: printUrls
|
|
5334
5386
|
}
|
|
5335
5387
|
].filter(Boolean);
|
|
5336
5388
|
if (customShortcuts && !Array.isArray(shortcuts = customShortcuts(shortcuts))) throw Error('`dev.cliShortcuts` must return an array of shortcuts.');
|
|
5337
|
-
help &&
|
|
5389
|
+
help && rslog_index_js_namespaceObject.logger.log(` ➜ ${index_js_default().dim('press')} ${index_js_default().bold('h + enter')} ${index_js_default().dim('to show shortcuts')}\n`);
|
|
5338
5390
|
let rl = external_node_readline_default().createInterface({
|
|
5339
5391
|
input: process.stdin
|
|
5340
5392
|
});
|
|
5341
5393
|
rl.on('line', (input)=>{
|
|
5342
5394
|
if ('h' === input) {
|
|
5343
|
-
let message = `\n ${
|
|
5395
|
+
let message = `\n ${index_js_default().bold(index_js_default().blue('Shortcuts:'))}\n`;
|
|
5344
5396
|
for (let shortcut of shortcuts)message += ` ${shortcut.description}\n`;
|
|
5345
|
-
|
|
5397
|
+
rslog_index_js_namespaceObject.logger.log(message);
|
|
5346
5398
|
}
|
|
5347
5399
|
for (let shortcut of shortcuts)if (input === shortcut.key) {
|
|
5348
5400
|
shortcut.action();
|
|
@@ -5405,7 +5457,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5405
5457
|
noServer: !0,
|
|
5406
5458
|
path: null === (_this_options_client = this.options.client) || void 0 === _this_options_client ? void 0 : _this_options_client.path
|
|
5407
5459
|
}), this.wsServer.on('error', (err)=>{
|
|
5408
|
-
|
|
5460
|
+
rslog_index_js_namespaceObject.logger.error(err);
|
|
5409
5461
|
}), this.timer = setInterval(()=>{
|
|
5410
5462
|
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
5411
5463
|
}, 30000), this.wsServer.on('connection', (socket, req)=>{
|
|
@@ -5453,7 +5505,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5453
5505
|
}
|
|
5454
5506
|
getStats(name) {
|
|
5455
5507
|
let curStats = this.stats[name];
|
|
5456
|
-
|
|
5508
|
+
if (!curStats) return null;
|
|
5509
|
+
let statsOptions = getStatsOptions(curStats.compilation.compiler);
|
|
5510
|
+
return curStats.toJson({
|
|
5457
5511
|
all: !1,
|
|
5458
5512
|
hash: !0,
|
|
5459
5513
|
assets: !0,
|
|
@@ -5463,8 +5517,10 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5463
5517
|
errorsCount: !0,
|
|
5464
5518
|
errorDetails: !1,
|
|
5465
5519
|
entrypoints: !0,
|
|
5466
|
-
children: !0
|
|
5467
|
-
|
|
5520
|
+
children: !0,
|
|
5521
|
+
moduleTrace: !0,
|
|
5522
|
+
...statsOptions
|
|
5523
|
+
});
|
|
5468
5524
|
}
|
|
5469
5525
|
sendStats({ force = !1, compilationId }) {
|
|
5470
5526
|
let stats = this.getStats(compilationId);
|
|
@@ -5847,13 +5903,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5847
5903
|
]), res), next();
|
|
5848
5904
|
}, faviconFallbackMiddleware = (req, res, next)=>{
|
|
5849
5905
|
'/favicon.ico' === req.url ? (res.statusCode = 204, res.end()) : next();
|
|
5850
|
-
}, getStatusCodeColor = (status)=>status >= 500 ?
|
|
5906
|
+
}, getStatusCodeColor = (status)=>status >= 500 ? index_js_default().red : status >= 400 ? index_js_default().yellow : status >= 300 ? index_js_default().cyan : status >= 200 ? index_js_default().green : (res)=>res, getRequestLoggerMiddleware = async ()=>{
|
|
5851
5907
|
let { default: onFinished } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/on-finished/index.js", 23));
|
|
5852
5908
|
return (req, res, next)=>{
|
|
5853
5909
|
let _startAt = process.hrtime();
|
|
5854
5910
|
onFinished(res, ()=>{
|
|
5855
5911
|
let method = req.method, url = req.originalUrl || req.url, status = Number(res.statusCode), statusColor = getStatusCodeColor(status), endAt = process.hrtime(), totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
5856
|
-
|
|
5912
|
+
rslog_index_js_namespaceObject.logger.debug(`${statusColor(status)} ${method} ${index_js_default().gray(url)} ${index_js_default().gray(`${totalTime.toFixed(3)} ms`)}`);
|
|
5857
5913
|
}), next();
|
|
5858
5914
|
};
|
|
5859
5915
|
}, notFoundMiddleware = (_req, res, _next)=>{
|
|
@@ -5904,7 +5960,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5904
5960
|
let filePath = external_node_path_default().join(distPath, 'index.html');
|
|
5905
5961
|
if (await middlewares_isFileExists(filePath, outputFileSystem)) {
|
|
5906
5962
|
let newUrl = '/index.html';
|
|
5907
|
-
return 'verbose' ===
|
|
5963
|
+
return 'verbose' === rslog_index_js_namespaceObject.logger.level && rslog_index_js_namespaceObject.logger.debug(`${req.method} ${index_js_default().gray(`${req.url} ${index_js_default().yellow('fallback')} to ${newUrl}`)}`), req.url = newUrl, callback(req, res, (...args)=>next(...args));
|
|
5908
5964
|
}
|
|
5909
5965
|
next();
|
|
5910
5966
|
}, viewingServedFilesMiddleware = ({ environments })=>async (req, res, next)=>{
|
|
@@ -5964,7 +6020,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5964
6020
|
}
|
|
5965
6021
|
res.end('</body></html>');
|
|
5966
6022
|
} catch (err) {
|
|
5967
|
-
|
|
6023
|
+
rslog_index_js_namespaceObject.logger.error(err), res.writeHead(500), res.end('Failed to list the files');
|
|
5968
6024
|
}
|
|
5969
6025
|
} else next();
|
|
5970
6026
|
}, createProxyMiddleware = async (proxyOptions)=>{
|
|
@@ -5980,7 +6036,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5980
6036
|
};
|
|
5981
6037
|
'string' == typeof options ? opts.target = options : Object.assign(opts, options), ret.push(opts);
|
|
5982
6038
|
}
|
|
5983
|
-
let handleError = (err)=>
|
|
6039
|
+
let handleError = (err)=>rslog_index_js_namespaceObject.logger.error(err);
|
|
5984
6040
|
for (let opts of ret)opts.onError ??= handleError;
|
|
5985
6041
|
return ret;
|
|
5986
6042
|
}(proxyOptions), proxyMiddlewares = [], middlewares = [], { createProxyMiddleware: baseMiddleware } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "../../compiled/http-proxy-middleware/index.js", 23));
|
|
@@ -6070,7 +6126,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6070
6126
|
};
|
|
6071
6127
|
}, getMiddlewares = async (options)=>{
|
|
6072
6128
|
let middlewares = [], { environments, compileMiddlewareAPI } = options;
|
|
6073
|
-
'verbose' ===
|
|
6129
|
+
'verbose' === rslog_index_js_namespaceObject.logger.level && middlewares.push(await getRequestLoggerMiddleware());
|
|
6074
6130
|
let { before, after } = applySetupMiddlewares(options.dev, environments, compileMiddlewareAPI);
|
|
6075
6131
|
middlewares.push(...before);
|
|
6076
6132
|
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
@@ -6102,7 +6158,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6102
6158
|
}, devServer_formatDevConfig = (config, port)=>('<port>' === config.client.port && (config.client.port = String(port)), config);
|
|
6103
6159
|
async function devServer_createDevServer(options, createCompiler, config, { compiler: customCompiler, getPortSilently, runCompile = !0 } = {}) {
|
|
6104
6160
|
let lastStats;
|
|
6105
|
-
|
|
6161
|
+
rslog_index_js_namespaceObject.logger.debug('create dev server');
|
|
6106
6162
|
let { port, host, https, portTip } = await getServerConfig({
|
|
6107
6163
|
config
|
|
6108
6164
|
}), devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(options.context);
|
|
@@ -6175,7 +6231,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6175
6231
|
customShortcuts: shortcutsOptions.custom
|
|
6176
6232
|
});
|
|
6177
6233
|
}
|
|
6178
|
-
!getPortSilently && portTip &&
|
|
6234
|
+
!getPortSilently && portTip && rslog_index_js_namespaceObject.logger.info(portTip);
|
|
6179
6235
|
};
|
|
6180
6236
|
runCompile ? options.context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
|
|
6181
6237
|
let compileMiddlewareAPI = runCompile ? await startCompile() : void 0, root = options.context.rootPath, fileWatcher = await setupWatchFiles({
|
|
@@ -6220,13 +6276,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6220
6276
|
serverConfig: config.server,
|
|
6221
6277
|
middlewares
|
|
6222
6278
|
}), serverTerminator = getServerTerminator(httpServer);
|
|
6223
|
-
return
|
|
6279
|
+
return rslog_index_js_namespaceObject.logger.debug('listen dev server'), options.context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
|
|
6224
6280
|
httpServer.listen({
|
|
6225
6281
|
host,
|
|
6226
6282
|
port
|
|
6227
6283
|
}, async (err)=>{
|
|
6228
6284
|
if (err) throw err;
|
|
6229
|
-
middlewares.use(notFoundMiddleware), httpServer.on('upgrade', devMiddlewares.onUpgrade),
|
|
6285
|
+
middlewares.use(notFoundMiddleware), httpServer.on('upgrade', devMiddlewares.onUpgrade), rslog_index_js_namespaceObject.logger.debug('listen dev server done'), await devServerAPI.afterListen(), onBeforeRestartServer(devServerAPI.close), resolve({
|
|
6230
6286
|
port,
|
|
6231
6287
|
urls: urls.map((item)=>item.url),
|
|
6232
6288
|
server: {
|
|
@@ -6250,36 +6306,33 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6250
6306
|
printUrls,
|
|
6251
6307
|
open: openPage
|
|
6252
6308
|
};
|
|
6253
|
-
return
|
|
6309
|
+
return rslog_index_js_namespaceObject.logger.debug('create dev server done'), devServerAPI;
|
|
6254
6310
|
}
|
|
6255
6311
|
async function createCompiler_createCompiler(options) {
|
|
6256
6312
|
var _context_normalizedConfig, _context_normalizedConfig1;
|
|
6257
|
-
|
|
6313
|
+
rslog_index_js_namespaceObject.logger.debug('create compiler');
|
|
6258
6314
|
let { context } = options, { rspackConfigs } = await initConfigs(options);
|
|
6259
6315
|
if (await context.hooks.onBeforeCreateCompiler.call({
|
|
6260
6316
|
bundlerConfigs: rspackConfigs,
|
|
6261
6317
|
environments: context.environments
|
|
6262
|
-
}), !await isSatisfyRspackVersion(core_namespaceObject.rspack.rspackVersion)) throw Error(`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${
|
|
6318
|
+
}), !await isSatisfyRspackVersion(core_namespaceObject.rspack.rspackVersion)) throw Error(`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${index_js_default().green(rspackMinVersion)}`);
|
|
6263
6319
|
let compiler = 1 === rspackConfigs.length ? (0, core_namespaceObject.rspack)(rspackConfigs[0]) : (0, core_namespaceObject.rspack)(rspackConfigs), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
|
|
6264
|
-
!isVersionLogged && (
|
|
6320
|
+
!isVersionLogged && (rslog_index_js_namespaceObject.logger.debug(`Use Rspack v${core_namespaceObject.rspack.rspackVersion}`), isVersionLogged = !0);
|
|
6265
6321
|
};
|
|
6266
6322
|
compiler.hooks.watchRun.tap('rsbuild:compiling', ()=>{
|
|
6267
|
-
logRspackVersion(), !isCompiling &&
|
|
6323
|
+
logRspackVersion(), !isCompiling && rslog_index_js_namespaceObject.logger.start('Building...'), isCompiling = !0;
|
|
6268
6324
|
}), (null === (_context_normalizedConfig = context.normalizedConfig) || void 0 === _context_normalizedConfig ? void 0 : _context_normalizedConfig.mode) === 'production' && compiler.hooks.run.tap('rsbuild:run', logRspackVersion);
|
|
6269
6325
|
let done = (stats)=>{
|
|
6270
6326
|
let statsOptions = getStatsOptions(compiler), statsJson = stats.toJson({
|
|
6271
6327
|
children: !0,
|
|
6328
|
+
moduleTrace: !0,
|
|
6272
6329
|
timings: !0,
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
} : {
|
|
6276
|
-
preset: 'errors-warnings'
|
|
6277
|
-
},
|
|
6278
|
-
...'object' == typeof statsOptions ? statsOptions : {}
|
|
6330
|
+
preset: 'errors-warnings',
|
|
6331
|
+
...statsOptions
|
|
6279
6332
|
}), printTime = (c, index)=>{
|
|
6280
6333
|
if (c.time) {
|
|
6281
|
-
let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name ?
|
|
6282
|
-
|
|
6334
|
+
let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name ? index_js_default().gray(` (${name})`) : '';
|
|
6335
|
+
rslog_index_js_namespaceObject.logger.ready(`Built in ${time}${suffix}`);
|
|
6283
6336
|
}
|
|
6284
6337
|
}, hasErrors = stats.hasErrors();
|
|
6285
6338
|
if (!hasErrors) {
|
|
@@ -6289,7 +6342,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6289
6342
|
}) : printTime(statsJson, 0);
|
|
6290
6343
|
}
|
|
6291
6344
|
let { message, level } = formatStats(statsJson, hasErrors);
|
|
6292
|
-
'error' === level &&
|
|
6345
|
+
'error' === level && rslog_index_js_namespaceObject.logger.error(message), 'warning' === level && rslog_index_js_namespaceObject.logger.warn(message), isCompiling = !1;
|
|
6293
6346
|
};
|
|
6294
6347
|
return compiler.hooks.done.tap('rsbuild:done', (stats)=>{
|
|
6295
6348
|
done(stats);
|
|
@@ -6301,7 +6354,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6301
6354
|
}), await context.hooks.onAfterCreateCompiler.call({
|
|
6302
6355
|
compiler,
|
|
6303
6356
|
environments: context.environments
|
|
6304
|
-
}),
|
|
6357
|
+
}), rslog_index_js_namespaceObject.logger.debug('create compiler done'), {
|
|
6305
6358
|
compiler,
|
|
6306
6359
|
rspackConfigs
|
|
6307
6360
|
};
|
|
@@ -6321,7 +6374,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6321
6374
|
isWatch: !!watch,
|
|
6322
6375
|
MultiStatsCtor: core_namespaceObject.rspack.MultiStats
|
|
6323
6376
|
}), watch) return compiler.watch({}, (err)=>{
|
|
6324
|
-
err &&
|
|
6377
|
+
err && rslog_index_js_namespaceObject.logger.error(err);
|
|
6325
6378
|
}), {
|
|
6326
6379
|
close: ()=>new Promise((resolve)=>{
|
|
6327
6380
|
compiler.close(()=>{
|
|
@@ -6332,7 +6385,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6332
6385
|
let { stats } = await new Promise((resolve, reject)=>{
|
|
6333
6386
|
compiler.run((err, stats)=>{
|
|
6334
6387
|
err ? reject(err) : (null == stats ? void 0 : stats.hasErrors()) ? reject(Error('Rspack build failed!')) : compiler.close((closeErr)=>{
|
|
6335
|
-
closeErr &&
|
|
6388
|
+
closeErr && rslog_index_js_namespaceObject.logger.error(closeErr), resolve({
|
|
6336
6389
|
stats
|
|
6337
6390
|
});
|
|
6338
6391
|
});
|
|
@@ -6412,7 +6465,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6412
6465
|
}
|
|
6413
6466
|
async applyDefaultMiddlewares() {
|
|
6414
6467
|
let { headers, proxy, historyApiFallback, compress, base } = this.options.serverConfig;
|
|
6415
|
-
if ('verbose' ===
|
|
6468
|
+
if ('verbose' === rslog_index_js_namespaceObject.logger.level && this.middlewares.use(await getRequestLoggerMiddleware()), compress && this.middlewares.use(gzipMiddleware({
|
|
6416
6469
|
level: 6
|
|
6417
6470
|
})), headers && this.middlewares.use((_req, res, next)=>{
|
|
6418
6471
|
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
@@ -6511,7 +6564,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6511
6564
|
customShortcuts: shortcutsOptions.custom
|
|
6512
6565
|
});
|
|
6513
6566
|
}
|
|
6514
|
-
!getPortSilently && portTip &&
|
|
6567
|
+
!getPortSilently && portTip && rslog_index_js_namespaceObject.logger.info(portTip), resolve({
|
|
6515
6568
|
port,
|
|
6516
6569
|
urls: urls.map((item)=>item.url),
|
|
6517
6570
|
server: {
|
|
@@ -6647,8 +6700,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6647
6700
|
if (isFunction(plugin.apply)) {
|
|
6648
6701
|
let { name = 'SomeWebpackPlugin' } = plugin.constructor || {};
|
|
6649
6702
|
throw Error([
|
|
6650
|
-
`${
|
|
6651
|
-
|
|
6703
|
+
`${index_js_default().yellow(name)} looks like a Webpack or Rspack plugin, please use ${index_js_default().yellow('`tools.rspack`')} to register it:`,
|
|
6704
|
+
index_js_default().green(`
|
|
6652
6705
|
// rsbuild.config.ts
|
|
6653
6706
|
export default {
|
|
6654
6707
|
tools: {
|
|
@@ -6664,7 +6717,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6664
6717
|
}
|
|
6665
6718
|
}(newPlugin), before) {
|
|
6666
6719
|
let index = plugins.findIndex((item)=>item.instance.name === before);
|
|
6667
|
-
-1 === index ? (
|
|
6720
|
+
-1 === index ? (rslog_index_js_namespaceObject.logger.warn(`Plugin "${before}" does not exist.`), plugins.push({
|
|
6668
6721
|
environment,
|
|
6669
6722
|
instance: newPlugin
|
|
6670
6723
|
})) : plugins.splice(index, 0, {
|
|
@@ -6697,7 +6750,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6697
6750
|
get (target, prop) {
|
|
6698
6751
|
if (exposedKeys.includes(prop)) return target[prop];
|
|
6699
6752
|
},
|
|
6700
|
-
set: (_, prop)=>(
|
|
6753
|
+
set: (_, prop)=>(rslog_index_js_namespaceObject.logger.error(`Context is readonly, you can not assign to the "context.${prop}" prop.`), !0)
|
|
6701
6754
|
});
|
|
6702
6755
|
}(context);
|
|
6703
6756
|
function getNormalizedConfig(options) {
|
|
@@ -6859,7 +6912,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6859
6912
|
});
|
|
6860
6913
|
context.getPluginAPI = getPluginAPI;
|
|
6861
6914
|
let globalPluginAPI = getPluginAPI();
|
|
6862
|
-
|
|
6915
|
+
rslog_index_js_namespaceObject.logger.debug('add default plugins'), await applyDefaultPlugins(pluginManager, context), rslog_index_js_namespaceObject.logger.debug('add default plugins done');
|
|
6863
6916
|
let provider = rsbuildConfig.provider || rspackProvider, providerInstance = await provider({
|
|
6864
6917
|
context,
|
|
6865
6918
|
pluginManager,
|
|
@@ -6872,11 +6925,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6872
6925
|
pluginManager
|
|
6873
6926
|
}), { distPath } = context, { checkDistDir = !0 } = options;
|
|
6874
6927
|
if (checkDistDir) {
|
|
6875
|
-
if (!(0, external_node_fs_.existsSync)(distPath)) throw Error(`The output directory ${
|
|
6928
|
+
if (!(0, external_node_fs_.existsSync)(distPath)) throw Error(`The output directory ${index_js_default().yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
6876
6929
|
if (function(path) {
|
|
6877
6930
|
let files = external_node_fs_default().readdirSync(path);
|
|
6878
6931
|
return 0 === files.length || 1 === files.length && '.git' === files[0];
|
|
6879
|
-
}(distPath)) throw Error(`The output directory ${
|
|
6932
|
+
}(distPath)) throw Error(`The output directory ${index_js_default().yellow(distPath)} is empty, please build the project before previewing.`);
|
|
6880
6933
|
}
|
|
6881
6934
|
return startProdServer(context, config, options);
|
|
6882
6935
|
}, rsbuild = {
|
|
@@ -6931,188 +6984,87 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6931
6984
|
}
|
|
6932
6985
|
})), rsbuild;
|
|
6933
6986
|
}
|
|
6934
|
-
|
|
6935
|
-
function loadEnv({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
|
|
6936
|
-
'PUBLIC_'
|
|
6937
|
-
] } = {}) {
|
|
6938
|
-
if ('local' === mode) throw Error("'local' cannot be used as a value for env mode, because \".env.local\" represents a temporary local file. Please use another value.");
|
|
6939
|
-
let filePaths = [
|
|
6940
|
-
'.env',
|
|
6941
|
-
'.env.local',
|
|
6942
|
-
`.env.${mode}`,
|
|
6943
|
-
`.env.${mode}.local`
|
|
6944
|
-
].map((filename)=>(0, external_node_path_.join)(cwd, filename)).filter(isFileSync), parsed = {};
|
|
6945
|
-
for (let envPath of filePaths)Object.assign(parsed, (0, main.parse)(external_node_fs_default().readFileSync(envPath)));
|
|
6946
|
-
parsed.NODE_ENV && (process.env.NODE_ENV = parsed.NODE_ENV), (0, lib_main.expand)({
|
|
6947
|
-
parsed
|
|
6948
|
-
});
|
|
6949
|
-
let publicVars = {}, rawPublicVars = {};
|
|
6950
|
-
for (let key of Object.keys(process.env))if (prefixes.some((prefix)=>key.startsWith(prefix))) {
|
|
6951
|
-
let val = process.env[key];
|
|
6952
|
-
publicVars[`import.meta.env.${key}`] = JSON.stringify(val), publicVars[`process.env.${key}`] = JSON.stringify(val), rawPublicVars[key] = val;
|
|
6953
|
-
}
|
|
6954
|
-
let cleaned = !1;
|
|
6955
|
-
return {
|
|
6956
|
-
parsed,
|
|
6957
|
-
cleanup: ()=>{
|
|
6958
|
-
if (!cleaned) {
|
|
6959
|
-
for (let key of Object.keys(parsed)){
|
|
6960
|
-
if ('NODE_ENV' !== key) process.env[key] === parsed[key] && delete process.env[key];
|
|
6961
|
-
}
|
|
6962
|
-
cleaned = !0;
|
|
6963
|
-
}
|
|
6964
|
-
},
|
|
6965
|
-
filePaths,
|
|
6966
|
-
publicVars,
|
|
6967
|
-
rawPublicVars
|
|
6968
|
-
};
|
|
6969
|
-
}
|
|
6970
|
-
let commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? external_node_path_default().isAbsolute(envDir) ? envDir : external_node_path_default().resolve(cwd, envDir) : cwd;
|
|
6971
|
-
async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
|
|
6972
|
-
cliOptions && (commonOpts = cliOptions);
|
|
6973
|
-
try {
|
|
6974
|
-
var _config_server, _config_dev, _config_dev1;
|
|
6975
|
-
let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, envs = loadEnv({
|
|
6976
|
-
cwd: getEnvDir(root, commonOpts.envDir),
|
|
6977
|
-
mode: commonOpts.envMode
|
|
6978
|
-
});
|
|
6979
|
-
onBeforeRestartServer(envs.cleanup);
|
|
6980
|
-
let { content: config, filePath: configFilePath } = await config_loadConfig({
|
|
6981
|
-
cwd: root,
|
|
6982
|
-
path: commonOpts.config,
|
|
6983
|
-
envMode: commonOpts.envMode
|
|
6984
|
-
}), command = process.argv[2];
|
|
6985
|
-
if ('dev' === command || isBuildWatch) {
|
|
6986
|
-
let files = [
|
|
6987
|
-
...envs.filePaths
|
|
6988
|
-
];
|
|
6989
|
-
if (configFilePath && files.push(configFilePath), null === (_config_dev1 = config.dev) || void 0 === _config_dev1 ? void 0 : _config_dev1.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
|
|
6990
|
-
if ('reload-server' !== watchFilesConfig.type) continue;
|
|
6991
|
-
let paths = castArray(watchFilesConfig.paths);
|
|
6992
|
-
watchFilesConfig.options ? watchFilesForRestart(paths, root, isBuildWatch, watchFilesConfig.options) : files.push(...paths);
|
|
6993
|
-
}
|
|
6994
|
-
watchFilesForRestart(files, root, isBuildWatch);
|
|
6995
|
-
}
|
|
6996
|
-
return config.source ||= {}, config.source.define = {
|
|
6997
|
-
...envs.publicVars,
|
|
6998
|
-
...config.source.define
|
|
6999
|
-
}, commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), commonOpts.open && !(null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) && (config.server ||= {}, config.server.open = commonOpts.open), commonOpts.host && (config.server ||= {}, config.server.host = commonOpts.host), commonOpts.port && (config.server ||= {}, config.server.port = commonOpts.port), (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.cliShortcuts) === void 0 && (config.dev ||= {}, config.dev.cliShortcuts = !0), createRsbuild({
|
|
7000
|
-
cwd: root,
|
|
7001
|
-
rsbuildConfig: config,
|
|
7002
|
-
environment: commonOpts.environment
|
|
7003
|
-
});
|
|
7004
|
-
} catch (err) {
|
|
7005
|
-
if (isRestart) index_js_namespaceObject.logger.error(err);
|
|
7006
|
-
else throw err;
|
|
7007
|
-
}
|
|
7008
|
-
}
|
|
7009
|
-
let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
7010
|
-
cleaners.push(cleaner);
|
|
7011
|
-
}, clearConsole = ()=>{
|
|
7012
|
-
isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J');
|
|
7013
|
-
}, beforeRestart = async ({ filePath, clear = !0 } = {})=>{
|
|
7014
|
-
if (clear && clearConsole(), filePath) {
|
|
7015
|
-
let filename = external_node_path_default().basename(filePath);
|
|
7016
|
-
index_js_namespaceObject.logger.info(`Restart server because ${picocolors_index_js_default().yellow(filename)} is changed.\n`);
|
|
7017
|
-
} else index_js_namespaceObject.logger.info('Restarting server...\n');
|
|
7018
|
-
for (let cleaner of cleaners)await cleaner();
|
|
7019
|
-
cleaners = [];
|
|
7020
|
-
}, restartDevServer = async ({ filePath, clear = !0 } = {})=>{
|
|
7021
|
-
await beforeRestart({
|
|
7022
|
-
filePath,
|
|
7023
|
-
clear
|
|
7024
|
-
});
|
|
7025
|
-
let rsbuild = await init({
|
|
7026
|
-
isRestart: !0
|
|
7027
|
-
});
|
|
7028
|
-
if (!!rsbuild) await rsbuild.startDevServer();
|
|
7029
|
-
}, restartBuild = async ({ filePath, clear = !0 } = {})=>{
|
|
7030
|
-
await beforeRestart({
|
|
7031
|
-
filePath,
|
|
7032
|
-
clear
|
|
7033
|
-
});
|
|
7034
|
-
let rsbuild = await init({
|
|
7035
|
-
isRestart: !0,
|
|
7036
|
-
isBuildWatch: !0
|
|
7037
|
-
});
|
|
7038
|
-
if (!!rsbuild) onBeforeRestartServer((await rsbuild.build({
|
|
7039
|
-
watch: !0
|
|
7040
|
-
})).close);
|
|
7041
|
-
}, applyCommonOptions = (command)=>{
|
|
6987
|
+
let { program, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help } = __webpack_require__("../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/index.js"), applyCommonOptions = (command)=>{
|
|
7042
6988
|
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').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('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--environment <name>', 'specify the name of environment to build', (str, prev)=>prev ? prev.concat(str.split(',')) : str.split(',')).option('--env-dir <dir>', 'specify the directory to load `.env` files');
|
|
7043
6989
|
}, applyServerOptions = (command)=>{
|
|
7044
6990
|
command.option('-o --open [url]', 'open the page in browser on startup').option('--port <port>', 'specify a port number for server to listen').option('--host <host>', 'specify the host that the server listens to');
|
|
7045
6991
|
};
|
|
7046
|
-
function
|
|
7047
|
-
program.name('rsbuild').usage('<command> [options]').version("1.1.2");
|
|
7048
|
-
let devCommand = program.command('dev'), buildCommand = program.command('build'), previewCommand = program.command('preview'), inspectCommand = program.command('inspect');
|
|
7049
|
-
[
|
|
7050
|
-
devCommand,
|
|
7051
|
-
buildCommand,
|
|
7052
|
-
previewCommand,
|
|
7053
|
-
inspectCommand
|
|
7054
|
-
].forEach(applyCommonOptions), [
|
|
7055
|
-
devCommand,
|
|
7056
|
-
previewCommand
|
|
7057
|
-
].forEach(applyServerOptions), devCommand.description('starting the dev server').action(async (options)=>{
|
|
7058
|
-
try {
|
|
7059
|
-
let rsbuild = await init({
|
|
7060
|
-
cliOptions: options
|
|
7061
|
-
});
|
|
7062
|
-
await (null == rsbuild ? void 0 : rsbuild.startDevServer());
|
|
7063
|
-
} catch (err) {
|
|
7064
|
-
index_js_namespaceObject.logger.error('Failed to start dev server.'), index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7065
|
-
}
|
|
7066
|
-
}), buildCommand.option('-w --watch', 'turn on watch mode, watch for changes and rebuild').description('build the app for production').action(async (options)=>{
|
|
7067
|
-
try {
|
|
7068
|
-
let rsbuild = await init({
|
|
7069
|
-
cliOptions: options,
|
|
7070
|
-
isBuildWatch: options.watch
|
|
7071
|
-
}), buildInstance = await (null == rsbuild ? void 0 : rsbuild.build({
|
|
7072
|
-
watch: options.watch
|
|
7073
|
-
}));
|
|
7074
|
-
options.watch && buildInstance && onBeforeRestartServer(buildInstance.close);
|
|
7075
|
-
} catch (err) {
|
|
7076
|
-
index_js_namespaceObject.logger.error('Failed to build.'), index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7077
|
-
}
|
|
7078
|
-
}), previewCommand.description('preview the production build locally').action(async (options)=>{
|
|
7079
|
-
try {
|
|
7080
|
-
let rsbuild = await init({
|
|
7081
|
-
cliOptions: options
|
|
7082
|
-
});
|
|
7083
|
-
await (null == rsbuild ? void 0 : rsbuild.preview());
|
|
7084
|
-
} catch (err) {
|
|
7085
|
-
index_js_namespaceObject.logger.error('Failed to start preview server.'), index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7086
|
-
}
|
|
7087
|
-
}), inspectCommand.description('inspect the Rspack and Rsbuild configs').option('--output <output>', 'specify inspect content output path').option('--verbose', 'show full function definitions in output').action(async (options)=>{
|
|
7088
|
-
try {
|
|
7089
|
-
let rsbuild = await init({
|
|
7090
|
-
cliOptions: options
|
|
7091
|
-
});
|
|
7092
|
-
await (null == rsbuild ? void 0 : rsbuild.inspectConfig({
|
|
7093
|
-
verbose: options.verbose,
|
|
7094
|
-
outputPath: options.output,
|
|
7095
|
-
writeToDisk: !0
|
|
7096
|
-
}));
|
|
7097
|
-
} catch (err) {
|
|
7098
|
-
index_js_namespaceObject.logger.error('Failed to inspect config.'), index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7099
|
-
}
|
|
7100
|
-
}), program.parse();
|
|
7101
|
-
}
|
|
7102
|
-
function prepareCli() {
|
|
6992
|
+
async function runCLI() {
|
|
7103
6993
|
!function() {
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
6994
|
+
!function() {
|
|
6995
|
+
if (!process.env.NODE_ENV) {
|
|
6996
|
+
let command = process.argv[2];
|
|
6997
|
+
process.env.NODE_ENV = [
|
|
6998
|
+
'build',
|
|
6999
|
+
'preview'
|
|
7000
|
+
].includes(command) ? 'production' : 'development';
|
|
7001
|
+
}
|
|
7002
|
+
}();
|
|
7003
|
+
let { npm_execpath } = process.env;
|
|
7004
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.1.4\n`);
|
|
7111
7005
|
}();
|
|
7112
|
-
|
|
7113
|
-
|
|
7006
|
+
try {
|
|
7007
|
+
!function() {
|
|
7008
|
+
program.name('rsbuild').usage('<command> [options]').version("1.1.4");
|
|
7009
|
+
let devCommand = program.command('dev'), buildCommand = program.command('build'), previewCommand = program.command('preview'), inspectCommand = program.command('inspect');
|
|
7010
|
+
[
|
|
7011
|
+
devCommand,
|
|
7012
|
+
buildCommand,
|
|
7013
|
+
previewCommand,
|
|
7014
|
+
inspectCommand
|
|
7015
|
+
].forEach(applyCommonOptions), [
|
|
7016
|
+
devCommand,
|
|
7017
|
+
previewCommand
|
|
7018
|
+
].forEach(applyServerOptions), devCommand.description('starting the dev server').action(async (options)=>{
|
|
7019
|
+
try {
|
|
7020
|
+
let rsbuild = await init({
|
|
7021
|
+
cliOptions: options
|
|
7022
|
+
});
|
|
7023
|
+
await (null == rsbuild ? void 0 : rsbuild.startDevServer());
|
|
7024
|
+
} catch (err) {
|
|
7025
|
+
rslog_index_js_namespaceObject.logger.error('Failed to start dev server.'), rslog_index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7026
|
+
}
|
|
7027
|
+
}), buildCommand.option('-w --watch', 'turn on watch mode, watch for changes and rebuild').description('build the app for production').action(async (options)=>{
|
|
7028
|
+
try {
|
|
7029
|
+
let rsbuild = await init({
|
|
7030
|
+
cliOptions: options,
|
|
7031
|
+
isBuildWatch: options.watch
|
|
7032
|
+
}), buildInstance = await (null == rsbuild ? void 0 : rsbuild.build({
|
|
7033
|
+
watch: options.watch
|
|
7034
|
+
}));
|
|
7035
|
+
options.watch && buildInstance && onBeforeRestartServer(buildInstance.close);
|
|
7036
|
+
} catch (err) {
|
|
7037
|
+
rslog_index_js_namespaceObject.logger.error('Failed to build.'), rslog_index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7038
|
+
}
|
|
7039
|
+
}), previewCommand.description('preview the production build locally').action(async (options)=>{
|
|
7040
|
+
try {
|
|
7041
|
+
let rsbuild = await init({
|
|
7042
|
+
cliOptions: options
|
|
7043
|
+
});
|
|
7044
|
+
await (null == rsbuild ? void 0 : rsbuild.preview());
|
|
7045
|
+
} catch (err) {
|
|
7046
|
+
rslog_index_js_namespaceObject.logger.error('Failed to start preview server.'), rslog_index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7047
|
+
}
|
|
7048
|
+
}), inspectCommand.description('inspect the Rspack and Rsbuild configs').option('--output <output>', 'specify inspect content output path').option('--verbose', 'show full function definitions in output').action(async (options)=>{
|
|
7049
|
+
try {
|
|
7050
|
+
let rsbuild = await init({
|
|
7051
|
+
cliOptions: options
|
|
7052
|
+
});
|
|
7053
|
+
await (null == rsbuild ? void 0 : rsbuild.inspectConfig({
|
|
7054
|
+
verbose: options.verbose,
|
|
7055
|
+
outputPath: options.output,
|
|
7056
|
+
writeToDisk: !0
|
|
7057
|
+
}));
|
|
7058
|
+
} catch (err) {
|
|
7059
|
+
rslog_index_js_namespaceObject.logger.error('Failed to inspect config.'), rslog_index_js_namespaceObject.logger.error(err), process.exit(1);
|
|
7060
|
+
}
|
|
7061
|
+
}), program.parse();
|
|
7062
|
+
}();
|
|
7063
|
+
} catch (err) {
|
|
7064
|
+
rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
|
|
7065
|
+
}
|
|
7114
7066
|
}
|
|
7115
|
-
let src_version = "1.1.
|
|
7067
|
+
let src_version = "1.1.4";
|
|
7116
7068
|
})();
|
|
7117
7069
|
var __webpack_export_target__ = exports;
|
|
7118
7070
|
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|