@rsbuild/core 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/css-loader/index.js +18 -18
- package/compiled/postcss-load-config/index.js +9 -3
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rsbuild-dev-middleware/index.js +177 -145
- package/compiled/rspack-chain/index.d.ts +2 -2
- package/compiled/rspack-chain/index.js +98 -71
- package/compiled/rspack-chain/license +22 -373
- package/compiled/rspack-chain/package.json +1 -1
- package/compiled/style-loader/index.js +10 -10
- package/dist/client/hmr.js +22 -13
- package/dist/index.cjs +143 -91
- package/dist/index.js +143 -91
- package/dist-types/cli/commands.d.ts +3 -0
- package/dist-types/config.d.ts +9 -1
- package/dist-types/configChain.d.ts +1 -2
- package/dist-types/index.d.ts +1 -1
- package/dist-types/plugins/basic.d.ts +1 -1
- package/dist-types/provider/createCompiler.d.ts +2 -1
- package/dist-types/provider/helpers.d.ts +1 -1
- package/dist-types/server/devMiddleware.d.ts +1 -1
- package/dist-types/server/helper.d.ts +1 -0
- package/dist-types/server/hmrFallback.d.ts +10 -0
- package/dist-types/types/config.d.ts +3 -12
- package/dist-types/types/hooks.d.ts +1 -0
- package/dist-types/types/plugin.d.ts +2 -2
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -384,7 +384,6 @@ var __webpack_exports__ = {};
|
|
|
384
384
|
});
|
|
385
385
|
var provider_helpers_namespaceObject = {};
|
|
386
386
|
__webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(provider_helpers_namespaceObject, {
|
|
387
|
-
chainToConfig: ()=>chainToConfig,
|
|
388
387
|
createDevServer: ()=>devServer_createDevServer,
|
|
389
388
|
formatStats: ()=>formatStats,
|
|
390
389
|
getChainUtils: ()=>getChainUtils,
|
|
@@ -919,36 +918,42 @@ var __webpack_exports__ = {};
|
|
|
919
918
|
async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
|
|
920
919
|
cliOptions && (commonOpts = cliOptions);
|
|
921
920
|
try {
|
|
922
|
-
var _config_server, _config_dev
|
|
921
|
+
var _config_server, _config_dev;
|
|
923
922
|
let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, envs = loadEnv({
|
|
924
923
|
cwd: getEnvDir(root, commonOpts.envDir),
|
|
925
924
|
mode: commonOpts.envMode
|
|
926
925
|
}), { content: config, filePath: configFilePath } = await config_loadConfig({
|
|
927
926
|
cwd: root,
|
|
928
927
|
path: commonOpts.config,
|
|
929
|
-
envMode: commonOpts.envMode
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
let files = [
|
|
933
|
-
...envs.filePaths
|
|
934
|
-
];
|
|
935
|
-
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)){
|
|
936
|
-
if ('reload-server' !== watchFilesConfig.type) continue;
|
|
937
|
-
let paths = castArray(watchFilesConfig.paths);
|
|
938
|
-
watchFilesConfig.options ? watchFilesForRestart(paths, root, isBuildWatch, watchFilesConfig.options) : files.push(...paths);
|
|
939
|
-
}
|
|
940
|
-
watchFilesForRestart(files, root, isBuildWatch);
|
|
941
|
-
}
|
|
928
|
+
envMode: commonOpts.envMode,
|
|
929
|
+
loader: commonOpts.configLoader
|
|
930
|
+
});
|
|
942
931
|
config.source ||= {}, config.source.define = {
|
|
943
932
|
...envs.publicVars,
|
|
944
933
|
...config.source.define
|
|
945
|
-
}, 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);
|
|
934
|
+
}, commonOpts.base && (config.server ||= {}, config.server.base = commonOpts.base), 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);
|
|
946
935
|
let rsbuild = await createRsbuild({
|
|
947
936
|
cwd: root,
|
|
948
937
|
rsbuildConfig: config,
|
|
949
938
|
environment: commonOpts.environment
|
|
950
939
|
});
|
|
951
|
-
return rsbuild.
|
|
940
|
+
return rsbuild.onBeforeCreateCompiler(()=>{
|
|
941
|
+
let command = process.argv[2];
|
|
942
|
+
if ('dev' === command || isBuildWatch) {
|
|
943
|
+
var _config_dev;
|
|
944
|
+
let files = [
|
|
945
|
+
...envs.filePaths
|
|
946
|
+
];
|
|
947
|
+
configFilePath && files.push(configFilePath);
|
|
948
|
+
let config = rsbuild.getNormalizedConfig();
|
|
949
|
+
if (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
|
|
950
|
+
if ('reload-server' !== watchFilesConfig.type) continue;
|
|
951
|
+
let paths = castArray(watchFilesConfig.paths);
|
|
952
|
+
watchFilesConfig.options ? watchFilesForRestart(paths, root, isBuildWatch, watchFilesConfig.options) : files.push(...paths);
|
|
953
|
+
}
|
|
954
|
+
watchFilesForRestart(files, root, isBuildWatch);
|
|
955
|
+
}
|
|
956
|
+
}), rsbuild.onCloseBuild(envs.cleanup), rsbuild.onCloseDevServer(envs.cleanup), rsbuild;
|
|
952
957
|
} catch (err) {
|
|
953
958
|
if (isRestart) rslog_index_js_namespaceObject.logger.error(err);
|
|
954
959
|
else throw err;
|
|
@@ -1104,7 +1109,6 @@ var __webpack_exports__ = {};
|
|
|
1104
1109
|
}
|
|
1105
1110
|
}), getDefaultPerformanceConfig = ()=>({
|
|
1106
1111
|
profile: !1,
|
|
1107
|
-
buildCache: !0,
|
|
1108
1112
|
printFileSize: !0,
|
|
1109
1113
|
removeConsole: !1,
|
|
1110
1114
|
removeMomentLocale: !1,
|
|
@@ -1237,7 +1241,7 @@ var __webpack_exports__ = {};
|
|
|
1237
1241
|
});
|
|
1238
1242
|
watcher.on('add', callback), watcher.on('change', callback), watcher.on('unlink', callback);
|
|
1239
1243
|
}
|
|
1240
|
-
async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta } = {}) {
|
|
1244
|
+
async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader = 'jiti' } = {}) {
|
|
1241
1245
|
let configExport;
|
|
1242
1246
|
let configFilePath = resolveConfigPath(cwd, path);
|
|
1243
1247
|
if (!configFilePath) return {
|
|
@@ -1247,10 +1251,11 @@ var __webpack_exports__ = {};
|
|
|
1247
1251
|
let applyMetaInfo = (config)=>(config._privateMeta = {
|
|
1248
1252
|
configFilePath
|
|
1249
1253
|
}, config);
|
|
1250
|
-
if (/\.(?:js|mjs|cjs)$/.test(configFilePath)) try {
|
|
1251
|
-
let exportModule = await import(`${
|
|
1254
|
+
if ('native' === loader || /\.(?:js|mjs|cjs)$/.test(configFilePath)) try {
|
|
1255
|
+
let configFileURL = (0, external_node_url_namespaceObject.pathToFileURL)(configFilePath).href, exportModule = await import(`${configFileURL}?t=${Date.now()}`);
|
|
1252
1256
|
configExport = exportModule.default ? exportModule.default : exportModule;
|
|
1253
1257
|
} catch (err) {
|
|
1258
|
+
if ('native' === loader) throw rslog_index_js_namespaceObject.logger.error(`Failed to load file with native loader: ${index_js_default().dim(configFilePath)}`), err;
|
|
1254
1259
|
rslog_index_js_namespaceObject.logger.debug(`Failed to load file with dynamic import: ${index_js_default().dim(configFilePath)}`);
|
|
1255
1260
|
}
|
|
1256
1261
|
try {
|
|
@@ -1703,7 +1708,7 @@ var __webpack_exports__ = {};
|
|
|
1703
1708
|
async function createContext(options, userConfig, bundlerType) {
|
|
1704
1709
|
let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
1705
1710
|
return {
|
|
1706
|
-
version: "1.2.
|
|
1711
|
+
version: "1.2.5",
|
|
1707
1712
|
rootPath,
|
|
1708
1713
|
distPath: '',
|
|
1709
1714
|
cachePath,
|
|
@@ -1846,26 +1851,6 @@ var __webpack_exports__ = {};
|
|
|
1846
1851
|
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);
|
|
1847
1852
|
return rslog_index_js_namespaceObject.logger.debug('modify bundler chain done'), modifiedBundlerChain;
|
|
1848
1853
|
}
|
|
1849
|
-
function chainToConfig(chain) {
|
|
1850
|
-
let config = chain.toConfig(), { entry } = config;
|
|
1851
|
-
if (!isPlainObject(entry)) return config;
|
|
1852
|
-
let formattedEntry = {};
|
|
1853
|
-
for (let [entryName, entryValue] of Object.entries(entry)){
|
|
1854
|
-
let entryImport = [], entryDescription = null;
|
|
1855
|
-
for (let item of castArray(entryValue)){
|
|
1856
|
-
if ('string' == typeof item) {
|
|
1857
|
-
entryImport.push(item);
|
|
1858
|
-
continue;
|
|
1859
|
-
}
|
|
1860
|
-
item.import && entryImport.push(...castArray(item.import)), entryDescription ? Object.assign(entryDescription, item) : entryDescription = item;
|
|
1861
|
-
}
|
|
1862
|
-
formattedEntry[entryName] = entryDescription ? {
|
|
1863
|
-
...entryDescription,
|
|
1864
|
-
import: entryImport
|
|
1865
|
-
} : entryImport;
|
|
1866
|
-
}
|
|
1867
|
-
return config.entry = formattedEntry, config;
|
|
1868
|
-
}
|
|
1869
1854
|
let configChain_CHAIN_ID = {
|
|
1870
1855
|
RULE: {
|
|
1871
1856
|
MJS: 'mjs',
|
|
@@ -1993,7 +1978,7 @@ var __webpack_exports__ = {};
|
|
|
1993
1978
|
}
|
|
1994
1979
|
});
|
|
1995
1980
|
}
|
|
1996
|
-
}),
|
|
1981
|
+
}), getDevtool = (config)=>{
|
|
1997
1982
|
let { sourceMap } = config.output, isProd = 'production' === config.mode;
|
|
1998
1983
|
return !1 !== sourceMap && (!0 === sourceMap ? isProd ? 'source-map' : 'cheap-module-source-map' : void 0 === sourceMap.js ? !isProd && 'cheap-module-source-map' : sourceMap.js);
|
|
1999
1984
|
}, pluginBasic = ()=>({
|
|
@@ -2001,7 +1986,16 @@ var __webpack_exports__ = {};
|
|
|
2001
1986
|
setup (api) {
|
|
2002
1987
|
api.modifyBundlerChain((chain, { env, isDev, target, bundler, environment, CHAIN_ID })=>{
|
|
2003
1988
|
let { config } = environment;
|
|
2004
|
-
chain.name(environment.name)
|
|
1989
|
+
chain.name(environment.name);
|
|
1990
|
+
let devtool = getDevtool(config);
|
|
1991
|
+
chain.devtool(devtool);
|
|
1992
|
+
let { sourceMap } = config.output;
|
|
1993
|
+
!devtool && 'object' == typeof sourceMap && sourceMap.css && chain.plugin('source-map-css').use(bundler.SourceMapDevToolPlugin, [
|
|
1994
|
+
{
|
|
1995
|
+
test: /\.css$/,
|
|
1996
|
+
filename: '[file].map[query]'
|
|
1997
|
+
}
|
|
1998
|
+
]), chain.context(api.context.rootPath), chain.mode(environment.config.mode), chain.merge({
|
|
2005
1999
|
infrastructureLogging: {
|
|
2006
2000
|
level: 'error'
|
|
2007
2001
|
}
|
|
@@ -2023,10 +2017,16 @@ var __webpack_exports__ = {};
|
|
|
2023
2017
|
return process.env.BUNDLE_ANALYZE || (null === (_config_performance = config.performance) || void 0 === _config_performance ? void 0 : _config_performance.bundleAnalyze);
|
|
2024
2018
|
}, external_node_crypto_namespaceObject = require("node:crypto");
|
|
2025
2019
|
var external_node_crypto_default = __webpack_require__.n(external_node_crypto_namespaceObject);
|
|
2026
|
-
async function
|
|
2020
|
+
async function validateWebpackCache(cacheDirectory, buildDependencies) {
|
|
2027
2021
|
let configFile = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'buildDependencies.json');
|
|
2028
2022
|
if (await isFileExists(configFile)) {
|
|
2029
|
-
|
|
2023
|
+
let rawConfigFile = await external_node_fs_default().promises.readFile(configFile, 'utf-8'), prevBuildDependencies = null;
|
|
2024
|
+
try {
|
|
2025
|
+
prevBuildDependencies = JSON.parse(rawConfigFile);
|
|
2026
|
+
} catch (e) {
|
|
2027
|
+
rslog_index_js_namespaceObject.logger.debug('Failed to parse the previous buildDependencies.json', e);
|
|
2028
|
+
}
|
|
2029
|
+
if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) return;
|
|
2030
2030
|
await external_node_fs_default().promises.rm(cacheDirectory, {
|
|
2031
2031
|
force: !0,
|
|
2032
2032
|
recursive: !0
|
|
@@ -2063,24 +2063,33 @@ var __webpack_exports__ = {};
|
|
|
2063
2063
|
let pluginCache = ()=>({
|
|
2064
2064
|
name: 'rsbuild:cache',
|
|
2065
2065
|
setup (api) {
|
|
2066
|
-
|
|
2066
|
+
let cacheEnabled = !1;
|
|
2067
|
+
api.modifyBundlerChain(async (chain, { environment, env })=>{
|
|
2067
2068
|
var digest;
|
|
2068
|
-
let { config } = environment, {
|
|
2069
|
-
if (!1 === buildCache)
|
|
2070
|
-
|
|
2071
|
-
return;
|
|
2072
|
-
}
|
|
2069
|
+
let { config } = environment, { bundlerType } = api.context, buildCache = config.performance.buildCache ?? 'webpack' === bundlerType;
|
|
2070
|
+
if (!1 === buildCache) return;
|
|
2071
|
+
cacheEnabled = !0;
|
|
2073
2072
|
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = function({ cacheDirectory }, context) {
|
|
2074
2073
|
return cacheDirectory ? (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory) : (0, external_node_path_namespaceObject.join)(context.cachePath, context.bundlerType);
|
|
2075
2074
|
}(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment);
|
|
2076
|
-
await
|
|
2077
|
-
let
|
|
2078
|
-
chain.cache({
|
|
2079
|
-
|
|
2075
|
+
'webpack' === bundlerType && await validateWebpackCache(cacheDirectory, buildDependencies);
|
|
2076
|
+
let cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${digest = cacheConfig.cacheDigest, external_node_crypto_default().createHash('md5').update(JSON.stringify(digest)).digest('hex').slice(0, 8)}` : `${environment.name}-${env}`;
|
|
2077
|
+
'rspack' === bundlerType ? (chain.cache(!0), chain.experiments({
|
|
2078
|
+
...chain.get('experiments'),
|
|
2079
|
+
cache: {
|
|
2080
|
+
type: 'persistent',
|
|
2081
|
+
version: cacheVersion,
|
|
2082
|
+
directory: cacheDirectory,
|
|
2083
|
+
buildDependencies: Object.values(buildDependencies).flat()
|
|
2084
|
+
}
|
|
2085
|
+
})) : chain.cache({
|
|
2086
|
+
name: cacheVersion,
|
|
2080
2087
|
type: 'filesystem',
|
|
2081
2088
|
cacheDirectory,
|
|
2082
2089
|
buildDependencies
|
|
2083
2090
|
});
|
|
2091
|
+
}), api.onAfterCreateCompiler(()=>{
|
|
2092
|
+
cacheEnabled && 'rspack' === api.context.bundlerType && rslog_index_js_namespaceObject.logger.info(`Rspack persistent cache enabled ${index_js_default().dim('(experimental)')}`);
|
|
2084
2093
|
});
|
|
2085
2094
|
}
|
|
2086
2095
|
}), addTrailingSep = (dir)=>dir.endsWith(external_node_path_namespaceObject.sep) ? dir : dir + external_node_path_namespaceObject.sep, isStrictSubdir = (parent, child)=>{
|
|
@@ -2105,9 +2114,9 @@ var __webpack_exports__ = {};
|
|
|
2105
2114
|
if (!0 === enable || 'auto' === enable && isStrictSubdir(rootPath, targetPath)) return {
|
|
2106
2115
|
path: targetPath
|
|
2107
2116
|
};
|
|
2108
|
-
}, getPathInfo = (environment)=>{
|
|
2117
|
+
}, getPathInfo = (environment, isDev)=>{
|
|
2109
2118
|
let { rootPath } = api.context, { config, distPath } = environment, { enable, keep } = normalizeCleanDistPath(config.output.cleanDistPath);
|
|
2110
|
-
return 'auto' === enable ? isStrictSubdir(rootPath, distPath) ? {
|
|
2119
|
+
return 'auto' === enable ? isDev && !config.dev.writeToDisk ? void 0 : isStrictSubdir(rootPath, distPath) ? {
|
|
2111
2120
|
path: distPath,
|
|
2112
2121
|
keep
|
|
2113
2122
|
} : (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)}`), void rslog_index_js_namespaceObject.logger.warn(`Current dist path: ${index_js_default().dim(distPath)}`)) : !0 === enable ? {
|
|
@@ -2116,7 +2125,7 @@ var __webpack_exports__ = {};
|
|
|
2116
2125
|
} : void 0;
|
|
2117
2126
|
}, cleanAll = async (params)=>{
|
|
2118
2127
|
for (let pathInfo of [
|
|
2119
|
-
...Object.values(params.environments).reduce((result, curr)=>(result.find((item)=>item.distPath === curr.distPath) || result.push(curr), result), []).map(getPathInfo),
|
|
2128
|
+
...Object.values(params.environments).reduce((result, curr)=>(result.find((item)=>item.distPath === curr.distPath) || result.push(curr), result), []).map((environment)=>getPathInfo(environment, params.isDev)),
|
|
2120
2129
|
getRsbuildOutputPath()
|
|
2121
2130
|
].filter((pathInfo)=>!!pathInfo))await emptyDir(pathInfo.path, pathInfo.keep);
|
|
2122
2131
|
};
|
|
@@ -2124,7 +2133,12 @@ var __webpack_exports__ = {};
|
|
|
2124
2133
|
isFirstCompile && await cleanAll({
|
|
2125
2134
|
environments
|
|
2126
2135
|
});
|
|
2127
|
-
}), api.onBeforeStartDevServer(
|
|
2136
|
+
}), api.onBeforeStartDevServer(async ({ environments })=>{
|
|
2137
|
+
await cleanAll({
|
|
2138
|
+
environments,
|
|
2139
|
+
isDev: !0
|
|
2140
|
+
});
|
|
2141
|
+
});
|
|
2128
2142
|
}
|
|
2129
2143
|
}), dist_isNil = (o)=>null == o, dist_isFunction = (func)=>'function' == typeof func, dist_isObject = (obj)=>null !== obj && 'object' == typeof obj, dist_isPlainObject = (obj)=>dist_isObject(obj) && '[object Object]' === Object.prototype.toString.call(obj);
|
|
2130
2144
|
function reduceConfigs({ initial, config, mergeFn = Object.assign }) {
|
|
@@ -3025,27 +3039,27 @@ var __webpack_exports__ = {};
|
|
|
3025
3039
|
apply(compiler) {
|
|
3026
3040
|
let { splitChunks } = compiler.options.optimization;
|
|
3027
3041
|
if (!splitChunks) return;
|
|
3028
|
-
let applyPatch = (
|
|
3029
|
-
if ('object' != typeof
|
|
3030
|
-
let { chunks } =
|
|
3042
|
+
let applyPatch = (config)=>{
|
|
3043
|
+
if ('object' != typeof config || (0, types_namespaceObject.isRegExp)(config)) return;
|
|
3044
|
+
let { chunks } = config;
|
|
3031
3045
|
if (chunks && 'async' !== chunks) {
|
|
3032
3046
|
if ('function' == typeof chunks) {
|
|
3033
|
-
|
|
3047
|
+
config.chunks = (chunk)=>(!chunk.name || chunk.name !== this.name) && chunks(chunk);
|
|
3034
3048
|
return;
|
|
3035
3049
|
}
|
|
3036
3050
|
if ('all' === chunks) {
|
|
3037
|
-
|
|
3051
|
+
config.chunks = (chunk)=>!chunk.name || chunk.name !== this.name;
|
|
3038
3052
|
return;
|
|
3039
3053
|
}
|
|
3040
3054
|
if ('initial' === chunks) {
|
|
3041
|
-
|
|
3055
|
+
config.chunks = (chunk)=>(!chunk.name || chunk.name !== this.name) && chunk.isOnlyInitial();
|
|
3042
3056
|
return;
|
|
3043
3057
|
}
|
|
3044
3058
|
}
|
|
3045
3059
|
};
|
|
3046
3060
|
applyPatch(splitChunks);
|
|
3047
3061
|
let { cacheGroups } = splitChunks;
|
|
3048
|
-
if (cacheGroups) for (let cacheGroupKey of Object.keys(cacheGroups))applyPatch(cacheGroups[cacheGroupKey]);
|
|
3062
|
+
if (cacheGroups) for (let cacheGroupKey of Object.keys(cacheGroups))cacheGroups[cacheGroupKey] && applyPatch(cacheGroups[cacheGroupKey]);
|
|
3049
3063
|
}
|
|
3050
3064
|
constructor(name){
|
|
3051
3065
|
!function(obj, key, value) {
|
|
@@ -3227,12 +3241,16 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
3227
3241
|
detail.family !== familyV4Value || ipv4Interfaces.has(detail.address) || ipv4Interfaces.set(detail.address, detail);
|
|
3228
3242
|
}
|
|
3229
3243
|
return Array.from(ipv4Interfaces.values());
|
|
3230
|
-
},
|
|
3244
|
+
}, isWildcardHost = (host)=>new Set([
|
|
3245
|
+
'0.0.0.0',
|
|
3246
|
+
'::',
|
|
3247
|
+
'0000:0000:0000:0000:0000:0000:0000:0000'
|
|
3248
|
+
]).has(host), isLoopbackHost = (host)=>new Set([
|
|
3231
3249
|
'localhost',
|
|
3232
3250
|
'127.0.0.1',
|
|
3233
3251
|
'::1',
|
|
3234
3252
|
'0000:0000:0000:0000:0000:0000:0000:0001'
|
|
3235
|
-
].
|
|
3253
|
+
]).has(host), getHostInUrl = (host)=>host === DEFAULT_DEV_HOST ? 'localhost' : external_node_net_default().isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host, concatUrl = ({ host, port, protocol })=>`${protocol}://${host}:${port}`, LOCAL_LABEL = 'Local: ', NETWORK_LABEL = 'Network: ', getUrlLabel = (url)=>{
|
|
3236
3254
|
try {
|
|
3237
3255
|
let { host } = new URL(url);
|
|
3238
3256
|
return isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL;
|
|
@@ -3691,7 +3709,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
3691
3709
|
return;
|
|
3692
3710
|
}
|
|
3693
3711
|
try {
|
|
3694
|
-
|
|
3712
|
+
let moduleURL = 'win32' === process.platform ? (0, external_node_url_namespaceObject.pathToFileURL)(packagePath).href : packagePath;
|
|
3713
|
+
module = await import(moduleURL);
|
|
3695
3714
|
} catch (err) {
|
|
3696
3715
|
rslog_index_js_namespaceObject.logger.error(`\`process.env.RSDOCTOR\` enabled, but failed to load ${index_js_default().bold(index_js_default().yellow(packageName))} module.`);
|
|
3697
3716
|
return;
|
|
@@ -4227,16 +4246,17 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4227
4246
|
};
|
|
4228
4247
|
}
|
|
4229
4248
|
async function generateRspackConfig({ target, context, environment }) {
|
|
4230
|
-
let chainUtils = getChainUtils(target, context.environments[environment]), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, HotModuleReplacementPlugin } = core_namespaceObject.rspack, rspackConfig =
|
|
4249
|
+
let chainUtils = getChainUtils(target, context.environments[environment]), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = core_namespaceObject.rspack, rspackConfig = (await modifyBundlerChain(context, {
|
|
4231
4250
|
...chainUtils,
|
|
4232
4251
|
bundler: {
|
|
4233
4252
|
BannerPlugin,
|
|
4234
4253
|
DefinePlugin,
|
|
4235
4254
|
IgnorePlugin,
|
|
4236
4255
|
ProvidePlugin,
|
|
4256
|
+
SourceMapDevToolPlugin,
|
|
4237
4257
|
HotModuleReplacementPlugin
|
|
4238
4258
|
}
|
|
4239
|
-
}));
|
|
4259
|
+
})).toConfig();
|
|
4240
4260
|
return !function(config) {
|
|
4241
4261
|
if (config.plugins) {
|
|
4242
4262
|
for (let plugin of config.plugins)if (plugin && void 0 === plugin.apply && 'name' in plugin && 'setup' in plugin) {
|
|
@@ -4322,6 +4342,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4322
4342
|
])
|
|
4323
4343
|
})
|
|
4324
4344
|
};
|
|
4345
|
+
}, validateRsbuildConfig = (config)=>{
|
|
4346
|
+
if (config.server.base && !config.server.base.startsWith('/')) throw Error('[rsbuild:config] The "server.base" option should start with a slash, for example: "/base"');
|
|
4325
4347
|
};
|
|
4326
4348
|
async function initRsbuildConfig({ context, pluginManager }) {
|
|
4327
4349
|
if (context.normalizedConfig) return context.normalizedConfig;
|
|
@@ -4359,7 +4381,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4359
4381
|
}
|
|
4360
4382
|
return common.join(external_node_path_namespaceObject.sep);
|
|
4361
4383
|
}(distPaths);
|
|
4362
|
-
}(context), context.normalizedConfig;
|
|
4384
|
+
}(context), validateRsbuildConfig(context.normalizedConfig), context.normalizedConfig;
|
|
4363
4385
|
}
|
|
4364
4386
|
async function initConfigs({ context, pluginManager, rsbuildOptions }) {
|
|
4365
4387
|
let normalizedConfig = await initRsbuildConfig({
|
|
@@ -4449,6 +4471,31 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4449
4471
|
rl.close();
|
|
4450
4472
|
};
|
|
4451
4473
|
}
|
|
4474
|
+
let external_node_dns_namespaceObject = require("node:dns");
|
|
4475
|
+
async function getLocalhostResolvedAddress() {
|
|
4476
|
+
let [defaultLookup, explicitLookup] = await Promise.all([
|
|
4477
|
+
external_node_dns_namespaceObject.promises.lookup('localhost'),
|
|
4478
|
+
external_node_dns_namespaceObject.promises.lookup('localhost', {
|
|
4479
|
+
verbatim: !0
|
|
4480
|
+
})
|
|
4481
|
+
]);
|
|
4482
|
+
return defaultLookup.family === explicitLookup.family && defaultLookup.address === explicitLookup.address ? void 0 : defaultLookup.address;
|
|
4483
|
+
}
|
|
4484
|
+
async function resolveHostname(host = 'localhost') {
|
|
4485
|
+
if ('localhost' === host) {
|
|
4486
|
+
let resolvedAddress = await getLocalhostResolvedAddress();
|
|
4487
|
+
if (resolvedAddress) return resolvedAddress;
|
|
4488
|
+
}
|
|
4489
|
+
return void 0 === host || isWildcardHost(host) ? 'localhost' : host;
|
|
4490
|
+
}
|
|
4491
|
+
async function getResolvedClientConfig(clientConfig, serverConfig) {
|
|
4492
|
+
let resolvedHost = await resolveHostname(serverConfig.host);
|
|
4493
|
+
return {
|
|
4494
|
+
...clientConfig,
|
|
4495
|
+
host: resolvedHost,
|
|
4496
|
+
port: serverConfig.port
|
|
4497
|
+
};
|
|
4498
|
+
}
|
|
4452
4499
|
let isClientCompiler = (compiler)=>{
|
|
4453
4500
|
let { target } = compiler.options;
|
|
4454
4501
|
return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
|
|
@@ -4465,13 +4512,14 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4465
4512
|
}), done.tap('rsbuild-dev-server', hookCallbacks.onDone);
|
|
4466
4513
|
}, getDevMiddleware = async (multiCompiler)=>{
|
|
4467
4514
|
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js"));
|
|
4468
|
-
return (options)=>{
|
|
4469
|
-
let { clientPaths, clientConfig, callbacks, liveReload, ...restOptions } = options;
|
|
4515
|
+
return async (options)=>{
|
|
4516
|
+
let { clientPaths, clientConfig, callbacks, liveReload, serverConfig, ...restOptions } = options, resolvedClientConfig = await getResolvedClientConfig(clientConfig, serverConfig);
|
|
4470
4517
|
return applyToCompiler(multiCompiler, (compiler)=>{
|
|
4471
|
-
clientPaths && function({ compiler, clientPaths, clientConfig = {}, liveReload = !0 }) {
|
|
4518
|
+
clientPaths && function({ compiler, clientPaths, clientConfig = {}, resolvedClientConfig = {}, liveReload = !0 }) {
|
|
4472
4519
|
if (isClientCompiler(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
|
|
4473
4520
|
RSBUILD_COMPILATION_NAME: JSON.stringify(getCompilationId(compiler)),
|
|
4474
4521
|
RSBUILD_CLIENT_CONFIG: JSON.stringify(clientConfig),
|
|
4522
|
+
RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
|
|
4475
4523
|
RSBUILD_DEV_LIVE_RELOAD: liveReload
|
|
4476
4524
|
}).apply(compiler), clientPaths))new compiler.webpack.EntryPlugin(compiler.context, clientPath, {
|
|
4477
4525
|
name: void 0
|
|
@@ -4480,6 +4528,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4480
4528
|
compiler,
|
|
4481
4529
|
clientPaths,
|
|
4482
4530
|
clientConfig,
|
|
4531
|
+
resolvedClientConfig,
|
|
4483
4532
|
liveReload
|
|
4484
4533
|
}), setupServerHooks(compiler, callbacks);
|
|
4485
4534
|
}), rsbuildDevMiddleware(multiCompiler, restOptions);
|
|
@@ -4818,7 +4867,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4818
4867
|
class CompilerDevMiddleware {
|
|
4819
4868
|
async init() {
|
|
4820
4869
|
let devMiddleware = await getDevMiddleware(this.compiler);
|
|
4821
|
-
this.middleware = this.setupDevMiddleware(devMiddleware, this.publicPaths), await this.socketServer.prepare();
|
|
4870
|
+
this.middleware = await this.setupDevMiddleware(devMiddleware, this.publicPaths), await this.socketServer.prepare();
|
|
4822
4871
|
}
|
|
4823
4872
|
upgrade(req, sock, head) {
|
|
4824
4873
|
this.socketServer.upgrade(req, sock, head);
|
|
@@ -4840,8 +4889,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4840
4889
|
data
|
|
4841
4890
|
});
|
|
4842
4891
|
}
|
|
4843
|
-
setupDevMiddleware(devMiddleware, publicPaths) {
|
|
4844
|
-
let { devConfig, serverConfig
|
|
4892
|
+
async setupDevMiddleware(devMiddleware, publicPaths) {
|
|
4893
|
+
let { devConfig, serverConfig } = this, { headers, base } = serverConfig, clientPaths = function(devConfig) {
|
|
4894
|
+
var _devConfig_client;
|
|
4895
|
+
let clientPaths = [];
|
|
4896
|
+
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilerDevMiddleware_require.resolve('@rsbuild/core/client/hmr')), (null === (_devConfig_client = devConfig.client) || void 0 === _devConfig_client ? void 0 : _devConfig_client.overlay) && clientPaths.push(`${compilerDevMiddleware_require.resolve('@rsbuild/core/client/overlay')}`)), clientPaths;
|
|
4897
|
+
}(devConfig), middleware = await devMiddleware({
|
|
4845
4898
|
headers,
|
|
4846
4899
|
publicPath: '/',
|
|
4847
4900
|
stats: !1,
|
|
@@ -4863,16 +4916,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4863
4916
|
this.socketServer.updateStats(stats);
|
|
4864
4917
|
}
|
|
4865
4918
|
},
|
|
4866
|
-
clientPaths:
|
|
4867
|
-
var _devConfig_client;
|
|
4868
|
-
let clientPaths = [];
|
|
4869
|
-
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilerDevMiddleware_require.resolve('@rsbuild/core/client/hmr')), (null === (_devConfig_client = devConfig.client) || void 0 === _devConfig_client ? void 0 : _devConfig_client.overlay) && clientPaths.push(`${compilerDevMiddleware_require.resolve('@rsbuild/core/client/overlay')}`)), clientPaths;
|
|
4870
|
-
}(devConfig),
|
|
4919
|
+
clientPaths: clientPaths,
|
|
4871
4920
|
clientConfig: devConfig.client,
|
|
4872
4921
|
liveReload: devConfig.liveReload,
|
|
4873
4922
|
writeToDisk: devConfig.writeToDisk,
|
|
4874
4923
|
serverSideRender: !0,
|
|
4875
|
-
etag: 'weak'
|
|
4924
|
+
etag: 'weak',
|
|
4925
|
+
serverConfig
|
|
4876
4926
|
}), assetPrefixes = publicPaths.map(pathnameParse).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
4877
4927
|
let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
|
|
4878
4928
|
assetPrefix && '/' !== assetPrefix ? (req.url = url.slice(assetPrefix.length - 1), middleware(req, res, (...args)=>{
|
|
@@ -5300,7 +5350,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5300
5350
|
}(proxyOptions), proxyMiddlewares = [], middlewares = [], { createProxyMiddleware: baseMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/http-proxy-middleware/index.js"));
|
|
5301
5351
|
for (let opts of formattedOptions){
|
|
5302
5352
|
let proxyMiddleware = baseMiddleware(opts.context, opts), middleware = async (req, res, next)=>{
|
|
5303
|
-
let bypassUrl = 'function' == typeof opts.bypass ? opts.bypass(req, res, opts) : null;
|
|
5353
|
+
let bypassUrl = 'function' == typeof opts.bypass ? await opts.bypass(req, res, opts) : null;
|
|
5304
5354
|
!1 === bypassUrl ? (res.statusCode = 404, next()) : 'string' == typeof bypassUrl ? (req.url = bypassUrl, next()) : !0 === bypassUrl ? next() : proxyMiddleware(req, res, next);
|
|
5305
5355
|
};
|
|
5306
5356
|
middlewares.push(middleware), opts.ws && proxyMiddlewares.push(proxyMiddleware);
|
|
@@ -5960,7 +6010,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5960
6010
|
if (isFunction(plugin.apply)) {
|
|
5961
6011
|
let { name = 'SomeWebpackPlugin' } = plugin.constructor || {};
|
|
5962
6012
|
throw Error([
|
|
5963
|
-
`${index_js_default().yellow(name)} looks like a
|
|
6013
|
+
`${index_js_default().yellow(name)} looks like a webpack or Rspack plugin, please use ${index_js_default().yellow('`tools.rspack`')} to register it:`,
|
|
5964
6014
|
index_js_default().green(`
|
|
5965
6015
|
// rsbuild.config.ts
|
|
5966
6016
|
export default {
|
|
@@ -6567,7 +6617,9 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6567
6617
|
}
|
|
6568
6618
|
}
|
|
6569
6619
|
let cac_dist = (name = "")=>new CAC(name), applyCommonOptions = (cli)=>{
|
|
6570
|
-
cli.option('
|
|
6620
|
+
cli.option('--base <base>', 'specify the base path of the server').option('-c, --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'specify the loader to load the config file, can be `jiti` or `native`', {
|
|
6621
|
+
default: 'jiti'
|
|
6622
|
+
}).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', {
|
|
6571
6623
|
type: [
|
|
6572
6624
|
String
|
|
6573
6625
|
],
|
|
@@ -6588,12 +6640,12 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6588
6640
|
}
|
|
6589
6641
|
}(), process.title = 'rsbuild-node';
|
|
6590
6642
|
let { npm_execpath } = process.env;
|
|
6591
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.
|
|
6643
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.5\n`);
|
|
6592
6644
|
}();
|
|
6593
6645
|
try {
|
|
6594
6646
|
!function() {
|
|
6595
6647
|
let cli = cac_dist('rsbuild');
|
|
6596
|
-
cli.help(), cli.version("1.2.
|
|
6648
|
+
cli.help(), cli.version("1.2.5"), applyCommonOptions(cli);
|
|
6597
6649
|
let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
|
|
6598
6650
|
applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
|
|
6599
6651
|
try {
|
|
@@ -6644,7 +6696,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6644
6696
|
rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
|
|
6645
6697
|
}
|
|
6646
6698
|
}
|
|
6647
|
-
let src_rslib_entry_version = "1.2.
|
|
6699
|
+
let src_rslib_entry_version = "1.2.5";
|
|
6648
6700
|
})();
|
|
6649
6701
|
var __webpack_export_target__ = exports;
|
|
6650
6702
|
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|