@rsbuild/core 2.0.0-alpha.4 → 2.0.0-beta.0
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/dist/131.js +213 -174
- package/dist-types/helpers/index.d.ts +1 -0
- package/dist-types/helpers/vendors.d.ts +1 -0
- package/dist-types/index.d.ts +2 -2
- package/dist-types/pluginHelper.d.ts +1 -1
- package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +1 -1
- package/dist-types/server/assets-middleware/index.d.ts +1 -1
- package/dist-types/types/config.d.ts +21 -7
- package/package.json +1 -1
- package/dist-types/rspack.d.ts +0 -2
package/dist/131.js
CHANGED
|
@@ -14,12 +14,17 @@ import * as __rspack_external_os from "os";
|
|
|
14
14
|
import * as __rspack_external_path from "path";
|
|
15
15
|
import * as __rspack_external_url from "url";
|
|
16
16
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
17
|
+
import { rspack as core_rspack } from "@rspack/core";
|
|
17
18
|
import node_process from "node:process";
|
|
18
19
|
import node_os, { constants as external_node_os_constants, type as external_node_os_type } from "node:os";
|
|
19
20
|
import node_tty from "node:tty";
|
|
20
21
|
import { promisify as external_node_util_promisify, stripVTControlCharacters } from "node:util";
|
|
21
22
|
import { isPromise, isRegExp } from "node:util/types";
|
|
22
23
|
import node_zlib from "node:zlib";
|
|
24
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
25
|
+
let prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--', position = argv.indexOf(prefix + flag), terminatorPosition = argv.indexOf('--');
|
|
26
|
+
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
27
|
+
}
|
|
23
28
|
__webpack_require__.add({
|
|
24
29
|
"../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js" (module) {
|
|
25
30
|
var isMergeableObject = function isMergeableObject(value) {
|
|
@@ -1002,11 +1007,6 @@ __webpack_require__.add({
|
|
|
1002
1007
|
module.exports = __rspack_external_url;
|
|
1003
1008
|
}
|
|
1004
1009
|
});
|
|
1005
|
-
let external_node_module_ = __webpack_require__("node:module"), rspack_rspack = (0, external_node_module_.createRequire)(import.meta.url)('@rspack/core');
|
|
1006
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
1007
|
-
let prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--', position = argv.indexOf(prefix + flag), terminatorPosition = argv.indexOf('--');
|
|
1008
|
-
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
1009
|
-
}
|
|
1010
1010
|
let { env: dist_env } = node_process;
|
|
1011
1011
|
function envForceColor() {
|
|
1012
1012
|
if (!('FORCE_COLOR' in dist_env)) return;
|
|
@@ -2254,7 +2254,7 @@ class src_class extends ChainedMap {
|
|
|
2254
2254
|
]);
|
|
2255
2255
|
}
|
|
2256
2256
|
}
|
|
2257
|
-
let setNodeEnv = (env)=>{
|
|
2257
|
+
let external_node_module_ = __webpack_require__("node:module"), vendors_require = (0, external_node_module_.createRequire)(import.meta.url), requireCompiledPackage = (name)=>vendors_require(`${COMPILED_PATH}/${name}/index.js`), setNodeEnv = (env)=>{
|
|
2258
2258
|
process.env.NODE_ENV = env;
|
|
2259
2259
|
}, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>'[object Object]' === Object.prototype.toString.call(obj), objectPrototype = Object.prototype, getProto = Object.getPrototypeOf, isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && getProto(obj) === objectPrototype, helpers_castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
|
|
2260
2260
|
arr
|
|
@@ -2319,7 +2319,7 @@ let compiler_isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isAr
|
|
|
2319
2319
|
}, applyToCompiler = (compiler, apply)=>{
|
|
2320
2320
|
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach(apply) : apply(compiler, 0);
|
|
2321
2321
|
}, addCompilationError = (compilation, message)=>{
|
|
2322
|
-
compilation.errors.push(new
|
|
2322
|
+
compilation.errors.push(new core_rspack.WebpackError(message));
|
|
2323
2323
|
};
|
|
2324
2324
|
function resolveFileName(stats) {
|
|
2325
2325
|
let file = stats.file || stats.moduleName;
|
|
@@ -2864,7 +2864,7 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2864
2864
|
}, mergeRsbuildConfig = (...originalConfigs)=>{
|
|
2865
2865
|
let configs = originalConfigs.filter((config)=>void 0 !== config).map(normalizeConfigStructure);
|
|
2866
2866
|
return 2 === configs.length ? mergeConfig_merge(configs[0], configs[1]) : 1 === configs.length ? configs[0] : 0 === configs.length ? {} : configs.reduce((result, config)=>mergeConfig_merge(result, config), {});
|
|
2867
|
-
},
|
|
2867
|
+
}, defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, createDefaultConfig = ()=>({
|
|
2868
2868
|
dev: {
|
|
2869
2869
|
hmr: !0,
|
|
2870
2870
|
liveReload: !0,
|
|
@@ -2913,7 +2913,7 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2913
2913
|
scriptLoading: 'defer',
|
|
2914
2914
|
implementation: 'js'
|
|
2915
2915
|
},
|
|
2916
|
-
resolve: (swcHelpersPath || (swcHelpersPath = (0, external_node_path_.dirname)(
|
|
2916
|
+
resolve: (swcHelpersPath || (swcHelpersPath = (0, external_node_path_.dirname)(vendors_require.resolve('@swc/helpers/package.json'))), {
|
|
2917
2917
|
alias: {
|
|
2918
2918
|
'@swc/helpers': swcHelpersPath
|
|
2919
2919
|
},
|
|
@@ -2992,12 +2992,10 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2992
2992
|
enable: !1
|
|
2993
2993
|
}
|
|
2994
2994
|
},
|
|
2995
|
+
splitChunks: {},
|
|
2995
2996
|
performance: {
|
|
2996
2997
|
printFileSize: !0,
|
|
2997
|
-
removeConsole: !1
|
|
2998
|
-
chunkSplit: {
|
|
2999
|
-
strategy: 'split-by-experience'
|
|
3000
|
-
}
|
|
2998
|
+
removeConsole: !1
|
|
3001
2999
|
},
|
|
3002
3000
|
environments: {},
|
|
3003
3001
|
logLevel: 'info'
|
|
@@ -3177,7 +3175,7 @@ function getHTMLPathByEntry(entryName, config) {
|
|
|
3177
3175
|
return prefix.startsWith('/') && src_logger.warn(`${picocolors_default().dim('[rsbuild:config]')} Absolute path is not recommended at ${picocolors_default().yellow(`output.distPath.html: "${prefix}"`)}, use relative path instead.`), external_node_path_.posix.join(prefix, filename).replace(/^\/+/, '');
|
|
3178
3176
|
}
|
|
3179
3177
|
let mapProcessAssetsStage = (stage)=>{
|
|
3180
|
-
let { Compilation } =
|
|
3178
|
+
let { Compilation } = core_rspack;
|
|
3181
3179
|
switch(stage){
|
|
3182
3180
|
case 'additional':
|
|
3183
3181
|
return Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL;
|
|
@@ -3258,7 +3256,7 @@ function initPluginAPI({ context, pluginManager }) {
|
|
|
3258
3256
|
compilation.hooks.childCompiler.tap(pluginName, (childCompiler)=>{
|
|
3259
3257
|
childCompiler.__rsbuildTransformer = transformer;
|
|
3260
3258
|
});
|
|
3261
|
-
let { sources } =
|
|
3259
|
+
let { sources } = core_rspack;
|
|
3262
3260
|
for (let { descriptor, handler, environment: pluginEnvironment } of processAssetsFns)(!descriptor.targets || descriptor.targets.includes(target)) && (!descriptor.environments || descriptor.environments.includes(environment.name)) && (!pluginEnvironment || isEnvironmentMatch(pluginEnvironment, environment.name)) && compilation.hooks.processAssets.tapPromise({
|
|
3263
3261
|
name: pluginName,
|
|
3264
3262
|
stage: mapProcessAssetsStage(descriptor.stage)
|
|
@@ -3446,7 +3444,7 @@ function createPublicContext(context) {
|
|
|
3446
3444
|
async function createContext(options, userConfig) {
|
|
3447
3445
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
3448
3446
|
return {
|
|
3449
|
-
version: "2.0.0-
|
|
3447
|
+
version: "2.0.0-beta.0",
|
|
3450
3448
|
rootPath,
|
|
3451
3449
|
distPath: '',
|
|
3452
3450
|
cachePath,
|
|
@@ -3676,9 +3674,9 @@ let configChain_CHAIN_ID = {
|
|
|
3676
3674
|
JS: 'js',
|
|
3677
3675
|
CSS: 'css'
|
|
3678
3676
|
}
|
|
3679
|
-
}
|
|
3677
|
+
};
|
|
3680
3678
|
function pluginHelper_getHTMLPlugin(config) {
|
|
3681
|
-
return config?.html.implementation === 'native' ?
|
|
3679
|
+
return config?.html.implementation === 'native' ? core_rspack.HtmlRspackPlugin : (pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = requireCompiledPackage('html-rspack-plugin')), pluginHelper_htmlPlugin);
|
|
3682
3680
|
}
|
|
3683
3681
|
async function modifyRspackConfig(context, rspackConfig, chainUtils) {
|
|
3684
3682
|
src_logger.debug('applying modifyRspackConfig hook');
|
|
@@ -3734,7 +3732,7 @@ function getConfigUtils(getCurrentConfig, chainUtils) {
|
|
|
3734
3732
|
}
|
|
3735
3733
|
function getChainUtils(target, environment, environments) {
|
|
3736
3734
|
return {
|
|
3737
|
-
rspack:
|
|
3735
|
+
rspack: core_rspack,
|
|
3738
3736
|
environment,
|
|
3739
3737
|
environments,
|
|
3740
3738
|
env: process.env.NODE_ENV || '',
|
|
@@ -3757,7 +3755,7 @@ function validateRspackConfig(config) {
|
|
|
3757
3755
|
config.devServer && src_logger.warn(`${picocolors_default().dim('[rsbuild:config]')} Find invalid Rspack config: "${picocolors_default().yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`);
|
|
3758
3756
|
}
|
|
3759
3757
|
async function generateRspackConfig({ target, context, environmentName }) {
|
|
3760
|
-
let chainUtils = getChainUtils(target, context.environments[environmentName], context.environments), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } =
|
|
3758
|
+
let chainUtils = getChainUtils(target, context.environments[environmentName], context.environments), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = core_rspack, rspackConfig = (await modifyBundlerChain(context, {
|
|
3761
3759
|
...chainUtils,
|
|
3762
3760
|
bundler: {
|
|
3763
3761
|
BannerPlugin,
|
|
@@ -3807,13 +3805,13 @@ let createEnvironmentNotFoundError = (environments = [])=>{
|
|
|
3807
3805
|
};
|
|
3808
3806
|
async function initRsbuildConfig({ context, pluginManager }) {
|
|
3809
3807
|
var config, rootPath;
|
|
3810
|
-
let defaultConfig;
|
|
3808
|
+
let defaultConfig, host;
|
|
3811
3809
|
if (context.normalizedConfig) return context.normalizedConfig;
|
|
3812
3810
|
await initPlugins({
|
|
3813
3811
|
context,
|
|
3814
3812
|
pluginManager
|
|
3815
3813
|
}), await modifyRsbuildConfig(context);
|
|
3816
|
-
let normalizedBaseConfig = (config = context.config, rootPath = context.rootPath, config.server ||= {}, config.server.publicDir = ((rootPath, publicDir)=>{
|
|
3814
|
+
let normalizedBaseConfig = (config = context.config, rootPath = context.rootPath, config.server ||= {}, config.server.host = 'string' == typeof (host = config.server.host) ? host : !0 === host ? ALL_INTERFACES_IPV4 : LOCALHOST, config.server.publicDir = ((rootPath, publicDir)=>{
|
|
3817
3815
|
if (!1 === publicDir) return [];
|
|
3818
3816
|
let defaultConfig = {
|
|
3819
3817
|
name: (0, external_node_path_.join)(rootPath, 'public'),
|
|
@@ -3973,7 +3971,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
3973
3971
|
if (await context.hooks.onBeforeCreateCompiler.callBatch({
|
|
3974
3972
|
bundlerConfigs: rspackConfigs,
|
|
3975
3973
|
environments: context.environments
|
|
3976
|
-
}), (version =
|
|
3974
|
+
}), (version = core_rspack.rspackVersion).includes('-canary') && (version = version.split('-canary')[0]), !(!(version && /^[\d.]+$/.test(version)) || ((version1, version2)=>{
|
|
3977
3975
|
let parts1 = version1.split('.').map(Number), parts2 = version2.split('.').map(Number), len = Math.max(parts1.length, parts2.length);
|
|
3978
3976
|
for(let i = 0; i < len; i++){
|
|
3979
3977
|
let item1 = parts1[i] ?? 0, item2 = parts2[i] ?? 0;
|
|
@@ -3982,10 +3980,10 @@ async function createCompiler_createCompiler(options) {
|
|
|
3982
3980
|
}
|
|
3983
3981
|
return 0;
|
|
3984
3982
|
})(version, '1.5.0') >= 0)) throw Error(`${picocolors_default().dim('[rsbuild]')} The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${picocolors_default().green("1.5.0")}`);
|
|
3985
|
-
let isMultiCompiler = rspackConfigs.length > 1, compiler = isMultiCompiler ?
|
|
3983
|
+
let isMultiCompiler = rspackConfigs.length > 1, compiler = isMultiCompiler ? core_rspack(rspackConfigs) : core_rspack(rspackConfigs[0]);
|
|
3986
3984
|
'true' === process.env.RSPACK_UNSAFE_FAST_DROP && (compiler.unsafeFastDrop = !0);
|
|
3987
3985
|
let isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
|
|
3988
|
-
isVersionLogged || (src_logger.debug(`using Rspack v${
|
|
3986
|
+
isVersionLogged || (src_logger.debug(`using Rspack v${core_rspack.rspackVersion}`), isVersionLogged = !0);
|
|
3989
3987
|
}, lazyModules = new Set();
|
|
3990
3988
|
compiler.hooks.infrastructureLog.tap(HOOK_NAME, (name, _, args)=>{
|
|
3991
3989
|
let log = args[0];
|
|
@@ -4095,7 +4093,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
4095
4093
|
context,
|
|
4096
4094
|
compiler,
|
|
4097
4095
|
bundlerConfigs: rspackConfigs,
|
|
4098
|
-
MultiStatsCtor:
|
|
4096
|
+
MultiStatsCtor: core_rspack.MultiStats
|
|
4099
4097
|
}), await context.hooks.onAfterCreateCompiler.callBatch({
|
|
4100
4098
|
compiler,
|
|
4101
4099
|
environments: context.environments
|
|
@@ -4164,7 +4162,7 @@ let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOption
|
|
|
4164
4162
|
rspackConfigs,
|
|
4165
4163
|
compiler,
|
|
4166
4164
|
isWatch: !!watch,
|
|
4167
|
-
MultiStatsCtor:
|
|
4165
|
+
MultiStatsCtor: core_rspack.MultiStats
|
|
4168
4166
|
}), watch) {
|
|
4169
4167
|
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
4170
4168
|
return compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
@@ -4253,7 +4251,7 @@ function getRegExpForExts(exts) {
|
|
|
4253
4251
|
return RegExp(1 === normalizedExts.length ? `\\.${matcher}$` : `\\.(?:${matcher})$`, 'i');
|
|
4254
4252
|
}
|
|
4255
4253
|
function getCacheDirectory({ cacheDirectory }, context) {
|
|
4256
|
-
return cacheDirectory ? (0, external_node_path_.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_.join)(context.rootPath, cacheDirectory) : (0, external_node_path_.join)(context.cachePath,
|
|
4254
|
+
return cacheDirectory ? (0, external_node_path_.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_.join)(context.rootPath, cacheDirectory) : (0, external_node_path_.join)(context.cachePath, 'rspack');
|
|
4257
4255
|
}
|
|
4258
4256
|
async function getBuildDependencies(context, config, environmentContext, additionalDependencies) {
|
|
4259
4257
|
let rootPackageJson = (0, external_node_path_.join)(context.rootPath, 'package.json'), browserslistConfig = (0, external_node_path_.join)(context.rootPath, '.browserslistrc'), buildDependencies = {};
|
|
@@ -4691,7 +4689,7 @@ class RsbuildHtmlPlugin {
|
|
|
4691
4689
|
} catch (error) {
|
|
4692
4690
|
return src_logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${picocolors_default().dim('[rsbuild:html]')} Failed to read the favicon file at ${picocolors_default().yellow(inputFilename)}.`), null;
|
|
4693
4691
|
}
|
|
4694
|
-
let source = new
|
|
4692
|
+
let source = new core_rspack.sources.RawSource(fileContent, !1), outputFilename = external_node_path_.default.posix.join(faviconDistPath, name);
|
|
4695
4693
|
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
4696
4694
|
}, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath })=>{
|
|
4697
4695
|
let href = favicon;
|
|
@@ -5227,10 +5225,7 @@ function pluginModuleFederation() {
|
|
|
5227
5225
|
config.dev ||= {}, config.server ||= {}, userConfig.server?.cors === void 0 && (config.server.cors = !0), config.server?.port && !config.dev.client?.port && (config.dev.client ||= {}, config.dev.client.port = config.server.port), userConfig.dev?.assetPrefix === void 0 && config.dev.assetPrefix === config.server?.base && (config.dev.assetPrefix = !0);
|
|
5228
5226
|
}
|
|
5229
5227
|
}), api.modifyEnvironmentConfig((config)=>{
|
|
5230
|
-
config.moduleFederation?.options && (config.
|
|
5231
|
-
...config.performance.chunkSplit,
|
|
5232
|
-
strategy: 'custom'
|
|
5233
|
-
}), config.source.include = [
|
|
5228
|
+
config.moduleFederation?.options && (config.source.include = [
|
|
5234
5229
|
...config.source.include || [],
|
|
5235
5230
|
/@module-federation[\\/]/
|
|
5236
5231
|
]);
|
|
@@ -5238,7 +5233,7 @@ function pluginModuleFederation() {
|
|
|
5238
5233
|
let { config } = environment;
|
|
5239
5234
|
if (!config.moduleFederation?.options || 'web' !== target) return;
|
|
5240
5235
|
let { options } = config.moduleFederation;
|
|
5241
|
-
chain.plugin(CHAIN_ID.PLUGIN.MODULE_FEDERATION).use(
|
|
5236
|
+
chain.plugin(CHAIN_ID.PLUGIN.MODULE_FEDERATION).use(core_rspack.container.ModuleFederationPlugin, [
|
|
5242
5237
|
options
|
|
5243
5238
|
]), options.name && !chain.output.get('uniqueName') && chain.output.set('uniqueName', options.name);
|
|
5244
5239
|
});
|
|
@@ -5257,7 +5252,6 @@ function getPublicPath({ isDev, config, context }) {
|
|
|
5257
5252
|
let defaultPort = server.port ?? 3000;
|
|
5258
5253
|
return formatPublicPath(replacePortPlaceholder(publicPath, isDev ? context.devServer?.port ?? defaultPort : defaultPort));
|
|
5259
5254
|
}
|
|
5260
|
-
let resolve_require = (0, external_node_module_.createRequire)(import.meta.url);
|
|
5261
5255
|
function applyAlias({ chain, config, rootPath }) {
|
|
5262
5256
|
let mergedAlias = reduceConfigs({
|
|
5263
5257
|
initial: {},
|
|
@@ -5270,14 +5264,14 @@ function applyAlias({ chain, config, rootPath }) {
|
|
|
5270
5264
|
continue;
|
|
5271
5265
|
}
|
|
5272
5266
|
try {
|
|
5273
|
-
pkgPath = (0, external_node_path_.dirname)(
|
|
5267
|
+
pkgPath = (0, external_node_path_.dirname)(vendors_require.resolve(`${pkgName}/package.json`, {
|
|
5274
5268
|
paths: [
|
|
5275
5269
|
rootPath
|
|
5276
5270
|
]
|
|
5277
5271
|
}));
|
|
5278
5272
|
} catch {}
|
|
5279
5273
|
if (!pkgPath) try {
|
|
5280
|
-
pkgPath =
|
|
5274
|
+
pkgPath = vendors_require.resolve(pkgName, {
|
|
5281
5275
|
paths: [
|
|
5282
5276
|
rootPath
|
|
5283
5277
|
]
|
|
@@ -5407,7 +5401,7 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
|
5407
5401
|
rel,
|
|
5408
5402
|
...option
|
|
5409
5403
|
}
|
|
5410
|
-
}))
|
|
5404
|
+
}));
|
|
5411
5405
|
function resolveLayer(value) {
|
|
5412
5406
|
return "OVERVIEW" === value ? 'info' : "ALL" === value ? 'trace' : value;
|
|
5413
5407
|
}
|
|
@@ -5424,7 +5418,7 @@ async function applyProfile(root, filterValue, traceLayer = 'perfetto', traceOut
|
|
|
5424
5418
|
traceOutput = 'perfetto' === traceLayer ? defaultRustTracePerfettoOutput : 'stdout';
|
|
5425
5419
|
}
|
|
5426
5420
|
let filter = resolveLayer(filterValue);
|
|
5427
|
-
return await ensureFileDir(traceOutput), await
|
|
5421
|
+
return await ensureFileDir(traceOutput), await core_rspack.experiments.globalTrace.register(filter, traceLayer, traceOutput), traceOutput;
|
|
5428
5422
|
}
|
|
5429
5423
|
function getForceSplittingGroups(forceSplitting, strategy) {
|
|
5430
5424
|
let cacheGroups = {};
|
|
@@ -5440,6 +5434,56 @@ function getForceSplittingGroups(forceSplitting, strategy) {
|
|
|
5440
5434
|
};
|
|
5441
5435
|
return cacheGroups;
|
|
5442
5436
|
}
|
|
5437
|
+
function resolveDefaultPreset(config) {
|
|
5438
|
+
let { polyfill } = config.output;
|
|
5439
|
+
return 'entry' === polyfill || 'usage' === polyfill ? {
|
|
5440
|
+
cacheGroups: {
|
|
5441
|
+
'lib-polyfill': {
|
|
5442
|
+
name: 'lib-polyfill',
|
|
5443
|
+
test: /node_modules[\\/](?:tslib|core-js|@swc[\\/]helpers)[\\/]/,
|
|
5444
|
+
priority: 0
|
|
5445
|
+
}
|
|
5446
|
+
}
|
|
5447
|
+
} : {};
|
|
5448
|
+
}
|
|
5449
|
+
function resolvePerPackagePreset() {
|
|
5450
|
+
return {
|
|
5451
|
+
minSize: 0,
|
|
5452
|
+
maxInitialRequests: 1 / 0,
|
|
5453
|
+
cacheGroups: {
|
|
5454
|
+
vendors: {
|
|
5455
|
+
priority: -9,
|
|
5456
|
+
test: NODE_MODULES_REGEX,
|
|
5457
|
+
name: (module)=>module ? getPackageNameFromModulePath(module.context) : void 0
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
};
|
|
5461
|
+
}
|
|
5462
|
+
function resolveSingleVendorPreset() {
|
|
5463
|
+
return {
|
|
5464
|
+
cacheGroups: {
|
|
5465
|
+
singleVendor: {
|
|
5466
|
+
test: NODE_MODULES_REGEX,
|
|
5467
|
+
priority: 0,
|
|
5468
|
+
chunks: 'all',
|
|
5469
|
+
name: 'vendor',
|
|
5470
|
+
enforce: !0
|
|
5471
|
+
}
|
|
5472
|
+
}
|
|
5473
|
+
};
|
|
5474
|
+
}
|
|
5475
|
+
function splitByExperience(ctx) {
|
|
5476
|
+
let { override, config, forceSplittingGroups } = ctx;
|
|
5477
|
+
return {
|
|
5478
|
+
...getDefaultSplitChunksForWeb(config),
|
|
5479
|
+
...override,
|
|
5480
|
+
cacheGroups: {
|
|
5481
|
+
...resolveDefaultPreset(config)?.cacheGroups,
|
|
5482
|
+
...forceSplittingGroups,
|
|
5483
|
+
...override.cacheGroups
|
|
5484
|
+
}
|
|
5485
|
+
};
|
|
5486
|
+
}
|
|
5443
5487
|
let MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/;
|
|
5444
5488
|
function getPackageNameFromModulePath(modulePath) {
|
|
5445
5489
|
let handleModuleContext = modulePath?.match(MODULE_PATH_REGEX);
|
|
@@ -5451,98 +5495,93 @@ function getPackageNameFromModulePath(modulePath) {
|
|
|
5451
5495
|
name
|
|
5452
5496
|
].filter(Boolean).join('.');
|
|
5453
5497
|
}
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
name: key
|
|
5465
|
-
};
|
|
5498
|
+
function splitByModule(ctx) {
|
|
5499
|
+
let { config, override, forceSplittingGroups } = ctx, perPackageOptions = resolvePerPackagePreset();
|
|
5500
|
+
return {
|
|
5501
|
+
...getDefaultSplitChunksForWeb(config),
|
|
5502
|
+
...perPackageOptions,
|
|
5503
|
+
...override,
|
|
5504
|
+
cacheGroups: {
|
|
5505
|
+
...forceSplittingGroups,
|
|
5506
|
+
...perPackageOptions.cacheGroups,
|
|
5507
|
+
...override.cacheGroups
|
|
5466
5508
|
}
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
...
|
|
5504
|
-
cacheGroups
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
}
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
}
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
...forceSplittingGroups,
|
|
5541
|
-
...override.cacheGroups
|
|
5542
|
-
}
|
|
5543
|
-
};
|
|
5509
|
+
};
|
|
5510
|
+
}
|
|
5511
|
+
function splitBySize(ctx) {
|
|
5512
|
+
let { override, forceSplittingGroups, config } = ctx, { minSize = 0, maxSize = 1 / 0 } = config.performance.chunkSplit;
|
|
5513
|
+
return {
|
|
5514
|
+
...getDefaultSplitChunksForWeb(config),
|
|
5515
|
+
minSize,
|
|
5516
|
+
maxSize,
|
|
5517
|
+
...override,
|
|
5518
|
+
cacheGroups: {
|
|
5519
|
+
...forceSplittingGroups,
|
|
5520
|
+
...override.cacheGroups
|
|
5521
|
+
}
|
|
5522
|
+
};
|
|
5523
|
+
}
|
|
5524
|
+
function splitCustom(ctx) {
|
|
5525
|
+
let { config, override, forceSplittingGroups } = ctx;
|
|
5526
|
+
return {
|
|
5527
|
+
...getDefaultSplitChunksForWeb(config),
|
|
5528
|
+
...override,
|
|
5529
|
+
cacheGroups: {
|
|
5530
|
+
...forceSplittingGroups,
|
|
5531
|
+
...override.cacheGroups
|
|
5532
|
+
}
|
|
5533
|
+
};
|
|
5534
|
+
}
|
|
5535
|
+
function allInOne(_ctx) {
|
|
5536
|
+
return !1;
|
|
5537
|
+
}
|
|
5538
|
+
function singleVendor(ctx) {
|
|
5539
|
+
let { config, override, forceSplittingGroups } = ctx;
|
|
5540
|
+
return {
|
|
5541
|
+
...getDefaultSplitChunksForWeb(config),
|
|
5542
|
+
...override,
|
|
5543
|
+
cacheGroups: {
|
|
5544
|
+
...resolveSingleVendorPreset().cacheGroups,
|
|
5545
|
+
...forceSplittingGroups,
|
|
5546
|
+
...override.cacheGroups
|
|
5547
|
+
}
|
|
5548
|
+
};
|
|
5549
|
+
}
|
|
5550
|
+
let getDefaultSplitChunksForWeb = (config)=>({
|
|
5551
|
+
chunks: config.moduleFederation?.options?.exposes ? 'async' : 'all'
|
|
5552
|
+
});
|
|
5553
|
+
function makeLegacySplitChunksOptions(chunkSplit, config, rootPath) {
|
|
5554
|
+
let forceSplittingGroups = {};
|
|
5555
|
+
chunkSplit.forceSplitting && (forceSplittingGroups = getForceSplittingGroups(chunkSplit.forceSplitting, chunkSplit.strategy));
|
|
5556
|
+
let override = 'custom' === chunkSplit.strategy ? chunkSplit.splitChunks ?? chunkSplit.override : chunkSplit.override;
|
|
5557
|
+
return ({
|
|
5558
|
+
'all-in-one': allInOne,
|
|
5559
|
+
'split-by-experience': splitByExperience,
|
|
5560
|
+
'split-by-module': splitByModule,
|
|
5561
|
+
'split-by-size': splitBySize,
|
|
5562
|
+
'single-vendor': singleVendor,
|
|
5563
|
+
custom: splitCustom
|
|
5564
|
+
})[chunkSplit.strategy || 'split-by-experience']({
|
|
5565
|
+
config,
|
|
5566
|
+
rootPath,
|
|
5567
|
+
override: override || {},
|
|
5568
|
+
forceSplittingGroups
|
|
5569
|
+
});
|
|
5570
|
+
}
|
|
5571
|
+
function getSplitChunksByPreset(config, preset) {
|
|
5572
|
+
if (!preset) return {};
|
|
5573
|
+
switch(preset){
|
|
5574
|
+
case 'default':
|
|
5575
|
+
return resolveDefaultPreset(config);
|
|
5576
|
+
case 'single-vendor':
|
|
5577
|
+
return resolveSingleVendorPreset();
|
|
5578
|
+
case 'per-package':
|
|
5579
|
+
return resolvePerPackagePreset();
|
|
5580
|
+
default:
|
|
5581
|
+
throw Error(`[rsbuild] Unknown splitChunks preset: ${preset}`);
|
|
5544
5582
|
}
|
|
5545
|
-
}
|
|
5583
|
+
}
|
|
5584
|
+
let builtinSwcLoaderName = 'builtin:swc-loader';
|
|
5546
5585
|
function applyScriptCondition({ rule, isDev, config, rsbuildTarget }) {
|
|
5547
5586
|
for (let condition of (rule.include.add({
|
|
5548
5587
|
not: NODE_MODULES_REGEX
|
|
@@ -5579,7 +5618,7 @@ function getDefaultSwcConfig({ browserslist, cacheRoot, config, isProd }) {
|
|
|
5579
5618
|
function applyCoreJs(swcConfig, polyfillMode, rootPath) {
|
|
5580
5619
|
let coreJsPath = ((rootPath)=>{
|
|
5581
5620
|
try {
|
|
5582
|
-
return
|
|
5621
|
+
return vendors_require.resolve('core-js/package.json', {
|
|
5583
5622
|
paths: [
|
|
5584
5623
|
rootPath,
|
|
5585
5624
|
import.meta.dirname
|
|
@@ -5983,7 +6022,7 @@ init(
|
|
|
5983
6022
|
${JSON.stringify(config.dev.client.logLevel)}
|
|
5984
6023
|
)
|
|
5985
6024
|
`;
|
|
5986
|
-
new
|
|
6025
|
+
new core_rspack.EntryPlugin(compiler.context, createVirtualModule(hmrEntry), {
|
|
5987
6026
|
name: void 0
|
|
5988
6027
|
}).apply(compiler);
|
|
5989
6028
|
}
|
|
@@ -6221,10 +6260,7 @@ let isValidMethodName = (methodName)=>'<unknown>' !== methodName && !/[\\/]/.tes
|
|
|
6221
6260
|
fullStack && (log1 += fullStack);
|
|
6222
6261
|
}
|
|
6223
6262
|
}
|
|
6224
|
-
return (log = log1).includes('ReferenceError: process is not defined') ? `${log}\n${picocolors_default().yellow(
|
|
6225
|
-
- To access \`process.env.*\`, define them in a \`.env\` file with the \`PUBLIC_\` prefix.
|
|
6226
|
-
- Or configure them via \`source.define\`.
|
|
6227
|
-
- Alternatively, install \`@rsbuild/plugin-node-polyfill\` to polyfill Node.js globals.`)}` : log;
|
|
6263
|
+
return (log = log1).includes('ReferenceError: process is not defined') ? `${log}\n${picocolors_default().yellow(" - `process` is a Node.js global and not available in browsers.\n - To access `process.env.*`, define them in a `.env` file with the `PUBLIC_` prefix.\n - Or configure them via `source.define`.\n - Alternatively, install `@rsbuild/plugin-node-polyfill` to polyfill Node.js globals.")}` : log;
|
|
6228
6264
|
}, styles = {
|
|
6229
6265
|
1: 'font-weight:bold',
|
|
6230
6266
|
2: 'opacity:0.5',
|
|
@@ -6746,7 +6782,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServerA
|
|
|
6746
6782
|
let { compress } = server;
|
|
6747
6783
|
if (compress && middlewares.push(gzipMiddleware_gzipMiddleware('object' == typeof compress ? compress : void 0)), 'dev' === context.action && buildManager) {
|
|
6748
6784
|
let { compiler } = buildManager;
|
|
6749
|
-
(compiler_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>childCompiler.options.lazyCompilation) : compiler.options.lazyCompilation) && middlewares.push(
|
|
6785
|
+
(compiler_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>childCompiler.options.lazyCompilation) : compiler.options.lazyCompilation) && middlewares.push(core_rspack.lazyCompilationMiddleware(compiler));
|
|
6750
6786
|
}
|
|
6751
6787
|
server.base && '/' !== server.base && middlewares.push(getBaseUrlMiddleware({
|
|
6752
6788
|
base: server.base
|
|
@@ -6962,7 +6998,7 @@ class BasicRunner {
|
|
|
6962
6998
|
});
|
|
6963
6999
|
}
|
|
6964
7000
|
}
|
|
6965
|
-
let
|
|
7001
|
+
let cjs_define = (...args)=>{
|
|
6966
7002
|
args.pop()();
|
|
6967
7003
|
};
|
|
6968
7004
|
class CommonJsRunner extends BasicRunner {
|
|
@@ -7004,16 +7040,16 @@ class CommonJsRunner extends BasicRunner {
|
|
|
7004
7040
|
}
|
|
7005
7041
|
createMissRequirer() {
|
|
7006
7042
|
return (_currentDirectory, modulePath, _context = {})=>{
|
|
7007
|
-
let resolvedPath =
|
|
7043
|
+
let resolvedPath = vendors_require.resolve(modulePath, {
|
|
7008
7044
|
paths: [
|
|
7009
7045
|
_currentDirectory
|
|
7010
7046
|
]
|
|
7011
7047
|
});
|
|
7012
|
-
return
|
|
7048
|
+
return vendors_require(resolvedPath.startsWith('node:') ? resolvedPath.slice(5) : resolvedPath);
|
|
7013
7049
|
};
|
|
7014
7050
|
}
|
|
7015
7051
|
createCjsRequirer() {
|
|
7016
|
-
let requireCache = Object.create(null), vm =
|
|
7052
|
+
let requireCache = Object.create(null), vm = vendors_require('node:vm');
|
|
7017
7053
|
return (currentDirectory, modulePath, context = {})=>{
|
|
7018
7054
|
let file = context.file || this.getFile(modulePath, currentDirectory);
|
|
7019
7055
|
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
@@ -7034,7 +7070,6 @@ class CommonJsRunner extends BasicRunner {
|
|
|
7034
7070
|
};
|
|
7035
7071
|
}
|
|
7036
7072
|
}
|
|
7037
|
-
let esm_require = (0, external_node_module_.createRequire)(import.meta.url);
|
|
7038
7073
|
class EsmRunner extends CommonJsRunner {
|
|
7039
7074
|
createRunner() {
|
|
7040
7075
|
super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
|
|
@@ -7051,7 +7086,7 @@ class EsmRunner extends CommonJsRunner {
|
|
|
7051
7086
|
});
|
|
7052
7087
|
}
|
|
7053
7088
|
createEsmRequirer() {
|
|
7054
|
-
let esmCache = new Map(), esmIdentifier = this._options.name, vm =
|
|
7089
|
+
let esmCache = new Map(), esmIdentifier = this._options.name, vm = vendors_require('node:vm');
|
|
7055
7090
|
return (currentDirectory, modulePath, context = {})=>{
|
|
7056
7091
|
if (!vm.SourceTextModule) throw Error(`${picocolors_default().dim('[rsbuild:runner]')} Running ESM bundle needs add Node.js option ${picocolors_default().yellow('--experimental-vm-modules')}.`);
|
|
7057
7092
|
let _require = this.getRequire(), file = context.file || this.getFile(modulePath, currentDirectory);
|
|
@@ -8117,7 +8152,7 @@ try {
|
|
|
8117
8152
|
config: config.tools.styleLoader
|
|
8118
8153
|
});
|
|
8119
8154
|
mainRule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
|
|
8120
|
-
} else mainRule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader((cssExtractPlugin ||
|
|
8155
|
+
} else mainRule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader((cssExtractPlugin || core_rspack.CssExtractRspackPlugin).loader).options(config.tools.cssExtract.loaderOptions);
|
|
8121
8156
|
else mainRule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_.default.join(dirname, 'ignoreCssLoader.mjs'));
|
|
8122
8157
|
let importLoaders = {
|
|
8123
8158
|
normal: 0,
|
|
@@ -8205,7 +8240,7 @@ try {
|
|
|
8205
8240
|
let isStringExport = 'string' === cssLoaderOptions.exportType;
|
|
8206
8241
|
if (isStringExport && mainRule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT) && mainRule.uses.delete(CHAIN_ID.USE.MINI_CSS_EXTRACT), emitCss && !config.output.injectStyles && !isStringExport) {
|
|
8207
8242
|
let extractPluginOptions = config.tools.cssExtract.pluginOptions, cssPath = config.output.distPath.css, cssFilename = getFilename(config, 'css', isProd), isCssFilenameFn = 'function' == typeof cssFilename, cssAsyncPath = config.output.distPath.cssAsync ?? (cssPath ? `${cssPath}/async` : 'async');
|
|
8208
|
-
chain.plugin(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT).use(cssExtractPlugin ||
|
|
8243
|
+
chain.plugin(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT).use(cssExtractPlugin || core_rspack.CssExtractRspackPlugin, [
|
|
8209
8244
|
{
|
|
8210
8245
|
filename: isCssFilenameFn ? (...args)=>{
|
|
8211
8246
|
let name = cssFilename(...args);
|
|
@@ -8339,29 +8374,34 @@ try {
|
|
|
8339
8374
|
{
|
|
8340
8375
|
name: 'rsbuild:split-chunks',
|
|
8341
8376
|
setup (api) {
|
|
8342
|
-
api.modifyBundlerChain(
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8377
|
+
api.modifyBundlerChain((chain, { environment, isServer, isWebWorker })=>{
|
|
8378
|
+
let { config } = environment, { splitChunks } = config;
|
|
8379
|
+
if (isWebWorker && chain.module.parser.merge({
|
|
8380
|
+
javascript: {
|
|
8381
|
+
dynamicImportMode: 'eager'
|
|
8382
|
+
}
|
|
8383
|
+
}), isServer || isWebWorker) {
|
|
8384
|
+
if (!1 === splitChunks || 0 === Object.keys(splitChunks).length) chain.optimization.splitChunks(!1);
|
|
8385
|
+
else {
|
|
8386
|
+
let { preset, ...rest } = splitChunks;
|
|
8387
|
+
chain.optimization.splitChunks({
|
|
8388
|
+
...getSplitChunksByPreset(config, preset),
|
|
8389
|
+
...rest
|
|
8390
|
+
});
|
|
8391
|
+
}
|
|
8349
8392
|
return;
|
|
8350
8393
|
}
|
|
8351
|
-
let {
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
polyfill: config.output.polyfill
|
|
8363
|
-
});
|
|
8364
|
-
chain.optimization.splitChunks(splitChunksOptions);
|
|
8394
|
+
let { chunkSplit } = config.performance;
|
|
8395
|
+
if (chunkSplit && !1 !== splitChunks && 0 === Object.keys(splitChunks).length) return void chain.optimization.splitChunks(makeLegacySplitChunksOptions(chunkSplit, config, api.context.rootPath));
|
|
8396
|
+
if (chunkSplit && src_logger.warn('[rsbuild:config] Both `performance.chunkSplit` and `splitChunks` are set. The `performance.chunkSplit` option is deprecated and will not work. Use `splitChunks` instead.'), !1 === splitChunks) chain.optimization.splitChunks(!1);
|
|
8397
|
+
else {
|
|
8398
|
+
let { preset = 'default', ...rest } = splitChunks;
|
|
8399
|
+
chain.optimization.splitChunks({
|
|
8400
|
+
...getDefaultSplitChunksForWeb(config),
|
|
8401
|
+
...getSplitChunksByPreset(config, preset),
|
|
8402
|
+
...rest
|
|
8403
|
+
});
|
|
8404
|
+
}
|
|
8365
8405
|
});
|
|
8366
8406
|
}
|
|
8367
8407
|
},
|
|
@@ -8452,7 +8492,7 @@ try {
|
|
|
8452
8492
|
for (let config of bundlerConfigs)if (config.plugins?.some((plugin)=>isRsdoctorPlugin(plugin))) return;
|
|
8453
8493
|
let packageName = '@rsdoctor/rspack-plugin';
|
|
8454
8494
|
try {
|
|
8455
|
-
packagePath =
|
|
8495
|
+
packagePath = vendors_require.resolve(packageName, {
|
|
8456
8496
|
paths: [
|
|
8457
8497
|
api.context.rootPath
|
|
8458
8498
|
]
|
|
@@ -8678,7 +8718,7 @@ try {
|
|
|
8678
8718
|
api.onBeforeBuild(async ({ isFirstCompile })=>{
|
|
8679
8719
|
isFirstCompile && await onStart();
|
|
8680
8720
|
}), api.onBeforeStartDevServer(onStart), api.onExit(()=>{
|
|
8681
|
-
traceOutput && (
|
|
8721
|
+
traceOutput && (core_rspack.experiments.globalTrace.cleanup(), src_logger.info(`profile file saved to ${picocolors_default().cyan(traceOutput)}`));
|
|
8682
8722
|
});
|
|
8683
8723
|
}
|
|
8684
8724
|
},
|
|
@@ -8733,7 +8773,7 @@ try {
|
|
|
8733
8773
|
let nonce = nonces[index], environment = environmentList.find((item)=>item.index === index);
|
|
8734
8774
|
if (!Object.keys(environment?.htmlPaths ?? {}).length || !nonce) return;
|
|
8735
8775
|
let injectCode = createVirtualModule(`__webpack_nonce__ = "${nonce}";`);
|
|
8736
|
-
new
|
|
8776
|
+
new core_rspack.EntryPlugin(compiler.context, injectCode, {
|
|
8737
8777
|
name: void 0
|
|
8738
8778
|
}).apply(compiler);
|
|
8739
8779
|
});
|
|
@@ -8969,7 +9009,6 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta,
|
|
|
8969
9009
|
moduleCache: !1,
|
|
8970
9010
|
interopDefault: !0,
|
|
8971
9011
|
nativeModules: [
|
|
8972
|
-
'@rspack/core',
|
|
8973
9012
|
"typescript"
|
|
8974
9013
|
]
|
|
8975
9014
|
});
|
|
@@ -9005,7 +9044,7 @@ let commonOpts = {}, init_loadConfig = async (root)=>{
|
|
|
9005
9044
|
envMode: commonOpts.envMode,
|
|
9006
9045
|
loader: commonOpts.configLoader
|
|
9007
9046
|
});
|
|
9008
|
-
return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), commonOpts.logLevel && (config.logLevel = commonOpts.logLevel), commonOpts.open && !config.server?.open && (config.server.open = commonOpts.open), commonOpts.host && (config.server.host =
|
|
9047
|
+
return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), commonOpts.logLevel && (config.logLevel = commonOpts.logLevel), commonOpts.open && !config.server?.open && (config.server.open = commonOpts.open), void 0 !== commonOpts.host && (config.server.host = commonOpts.host), commonOpts.port && (config.server.port = commonOpts.port), void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
|
|
9009
9048
|
...config.dev.watchFiles ? helpers_castArray(config.dev.watchFiles) : [],
|
|
9010
9049
|
{
|
|
9011
9050
|
paths: filePath,
|
|
@@ -9103,7 +9142,7 @@ let applyServerOptions = (command)=>{
|
|
|
9103
9142
|
};
|
|
9104
9143
|
function setupCommands() {
|
|
9105
9144
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
9106
|
-
cli.version("2.0.0-
|
|
9145
|
+
cli.version("2.0.0-beta.0"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
|
|
9107
9146
|
default: 'auto'
|
|
9108
9147
|
}).option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
|
|
9109
9148
|
type: [
|
|
@@ -9172,7 +9211,7 @@ function initNodeEnv() {
|
|
|
9172
9211
|
}
|
|
9173
9212
|
function showGreeting() {
|
|
9174
9213
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
9175
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.0-
|
|
9214
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.0-beta.0\n`);
|
|
9176
9215
|
}
|
|
9177
9216
|
function setupLogLevel() {
|
|
9178
9217
|
let logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
@@ -9193,5 +9232,5 @@ function runCLI() {
|
|
|
9193
9232
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
9194
9233
|
}
|
|
9195
9234
|
}
|
|
9196
|
-
let src_version = "2.0.0-
|
|
9197
|
-
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, external_node_os_type, external_node_util_promisify, loadConfig_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, node_os, node_process,
|
|
9235
|
+
let src_version = "2.0.0-beta.0";
|
|
9236
|
+
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, external_node_os_type, external_node_util_promisify, loadConfig_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, node_os, node_process, runCLI, src_logger as logger, src_version as version };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import color from 'picocolors';
|
|
2
2
|
import RspackChain from '../../compiled/rspack-chain/types';
|
|
3
3
|
import type { FilenameConfig, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildTarget, Rspack } from '../types';
|
|
4
|
+
export { require } from './vendors';
|
|
4
5
|
export { color, RspackChain };
|
|
5
6
|
export declare const getNodeEnv: () => string;
|
|
6
7
|
export declare const setNodeEnv: (env: string) => void;
|
|
@@ -4,6 +4,7 @@ type CompiledPackages = {
|
|
|
4
4
|
'html-rspack-plugin': typeof import('../../compiled/html-rspack-plugin').default;
|
|
5
5
|
'http-proxy-middleware': typeof import('../../compiled/http-proxy-middleware');
|
|
6
6
|
};
|
|
7
|
+
export declare const require: NodeJS.Require;
|
|
7
8
|
/**
|
|
8
9
|
* Load compiled package from `compiled` folder.
|
|
9
10
|
* use `require()` as compiled packages are CommonJS modules.
|
package/dist-types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the public API of @rsbuild/core.
|
|
4
4
|
*/
|
|
5
5
|
import type * as Rspack from '@rspack/core';
|
|
6
|
-
import { rspack } from '
|
|
6
|
+
import { rspack } from '@rspack/core';
|
|
7
7
|
export { runCLI } from './cli';
|
|
8
8
|
export { createRsbuild } from './createRsbuild';
|
|
9
9
|
export { type ConfigParams, defineConfig, type LoadConfigOptions, type LoadConfigResult, loadConfig, } from './loadConfig';
|
|
@@ -19,4 +19,4 @@ export { type Logger, logger } from './logger';
|
|
|
19
19
|
export { mergeRsbuildConfig } from './mergeConfig';
|
|
20
20
|
export type { RsbuildDevServer } from './server/devServer';
|
|
21
21
|
export type { StartServerResult } from './server/helper';
|
|
22
|
-
export type { AliasStrategy, AppIcon, AppIconItem, Build, BuildOptions, BuildResult, Charset, CleanDistPath, CleanDistPathObject, ClientConfig, CliShortcut, CompressOptions, ConfigChain, ConfigChainWithContext, Connect, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentConfig, EnvironmentContext, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlBasicTag, HtmlConfig, HtmlFallback, HtmlRspackPlugin, HtmlTag, HtmlTagContext, HtmlTagDescriptor, HtmlTagHandler, InitConfigsOptions, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InspectConfigOptions, InspectConfigResult, InternalContext, LegalComments, LogLevel, ManifestConfig, ManifestData, ManifestObjectConfig, MergedEnvironmentConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLContext, ModifyHTMLFn, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModuleFederationConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedResolveConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDevCompileFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDevCompileFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreconnectOption, PreviewOptions, PrintUrls, ProcessAssetsDescriptor, ProcessAssetsHandler, ProcessAssetsHook, ProgressBarConfig, ProxyBypass, ProxyConfig, ProxyFilter, ProxyOptions, PublicDir, PublicDirOptions, RequestHandler, ResolveConfig, ResolvedCreateRsbuildOptions, ResolveHandler, ResolveHook, ResourceHintsIncludeType, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildTarget, RspackChain, RspackRule, ScriptInject, ScriptLoading, SecurityConfig, ServerConfig, SetupMiddlewaresContext, SetupMiddlewaresFn, SourceConfig, SourceMap, SplitChunks, SriAlgorithm, SriOptions, StartDevServerOptions, StyleLoaderOptions, ToolsConfig, TransformContext, TransformDescriptor, TransformHandler, TransformHook, TransformImport, WatchFiles, } from './types';
|
|
22
|
+
export type { AliasStrategy, AppIcon, AppIconItem, Build, BuildOptions, BuildResult, Charset, CleanDistPath, CleanDistPathObject, ClientConfig, CliShortcut, CompressOptions, ConfigChain, ConfigChainWithContext, Connect, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentConfig, EnvironmentContext, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlBasicTag, HtmlConfig, HtmlFallback, HtmlRspackPlugin, HtmlTag, HtmlTagContext, HtmlTagDescriptor, HtmlTagHandler, InitConfigsOptions, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InspectConfigOptions, InspectConfigResult, InternalContext, LegalComments, LogLevel, ManifestConfig, ManifestData, ManifestObjectConfig, MergedEnvironmentConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLContext, ModifyHTMLFn, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModuleFederationConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedResolveConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedSplitChunksConfig, NormalizedToolsConfig, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDevCompileFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDevCompileFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreconnectOption, PreviewOptions, PrintUrls, ProcessAssetsDescriptor, ProcessAssetsHandler, ProcessAssetsHook, ProgressBarConfig, ProxyBypass, ProxyConfig, ProxyFilter, ProxyOptions, PublicDir, PublicDirOptions, RequestHandler, ResolveConfig, ResolvedCreateRsbuildOptions, ResolveHandler, ResolveHook, ResourceHintsIncludeType, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildTarget, RspackChain, RspackRule, ScriptInject, ScriptLoading, SecurityConfig, ServerConfig, SetupMiddlewaresContext, SetupMiddlewaresFn, SourceConfig, SourceMap, SplitChunks, SplitChunksConfig, SplitChunksPreset, SriAlgorithm, SriOptions, StartDevServerOptions, StyleLoaderOptions, ToolsConfig, TransformContext, TransformDescriptor, TransformHandler, TransformHook, TransformImport, WatchFiles, } from './types';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file is used to get/set the global instance for html-plugin and css-extract plugin.
|
|
3
3
|
*/
|
|
4
|
-
import { rspack } from '
|
|
4
|
+
import { rspack } from '@rspack/core';
|
|
5
5
|
import type { HtmlRspackPlugin, NormalizedEnvironmentConfig } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* This method is used to override the Rsbuild default html-plugin (html-rspack-plugin).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Compiler } from '@rspack/core';
|
|
2
2
|
import type { EnvironmentContext, HtmlRspackPlugin, HtmlTag, HtmlTagDescriptor, InternalContext } from '../types';
|
|
3
3
|
type HtmlTagObject = HtmlRspackPlugin.HtmlTagObject;
|
|
4
4
|
export type TagConfig = {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Copyright JS Foundation and other contributors
|
|
7
7
|
* https://github.com/webpack/webpack-dev-middleware/blob/master/LICENSE
|
|
8
8
|
*/
|
|
9
|
-
import type
|
|
9
|
+
import { type Compiler, type MultiCompiler } from '@rspack/core';
|
|
10
10
|
import type { InternalContext, NormalizedConfig, RequestHandler } from '../../types';
|
|
11
11
|
import type { SocketServer } from '../socketServer';
|
|
12
12
|
export type MultiWatching = ReturnType<MultiCompiler['watch']>;
|
|
@@ -370,9 +370,12 @@ export interface ServerConfig {
|
|
|
370
370
|
https?: HttpsServerOptions | SecureServerSessionOptions;
|
|
371
371
|
/**
|
|
372
372
|
* Specify the host that the Rsbuild server listens to.
|
|
373
|
-
*
|
|
373
|
+
* - `string`: specify a hostname or IP address to listen on.
|
|
374
|
+
* - `true`: equals to `0.0.0.0`, listen on all interfaces.
|
|
375
|
+
* - `false`: equals to `localhost`
|
|
376
|
+
* @default 'localhost'
|
|
374
377
|
*/
|
|
375
|
-
host?: string;
|
|
378
|
+
host?: string | boolean;
|
|
376
379
|
/**
|
|
377
380
|
* Adds headers to all responses.
|
|
378
381
|
*/
|
|
@@ -437,8 +440,9 @@ export interface ServerConfig {
|
|
|
437
440
|
middlewareMode?: boolean;
|
|
438
441
|
}
|
|
439
442
|
export type NormalizedServerConfig = {
|
|
443
|
+
host: string;
|
|
440
444
|
publicDir: Required<PublicDirOptions>[];
|
|
441
|
-
} & Omit<Optional<Required<ServerConfig>, 'headers' | 'https' | 'historyApiFallback' | 'proxy'>, 'publicDir'>;
|
|
445
|
+
} & Omit<Optional<Required<ServerConfig>, 'headers' | 'https' | 'historyApiFallback' | 'proxy'>, 'host' | 'publicDir'>;
|
|
442
446
|
export type SriAlgorithm = 'sha256' | 'sha384' | 'sha512';
|
|
443
447
|
export type SriOptions = {
|
|
444
448
|
/**
|
|
@@ -606,7 +610,7 @@ export interface PerformanceConfig {
|
|
|
606
610
|
printFileSize?: PrintFileSizeOptions | boolean;
|
|
607
611
|
/**
|
|
608
612
|
* Configure the chunk splitting strategy.
|
|
609
|
-
* @
|
|
613
|
+
* @deprecated Use `splitChunks` instead.
|
|
610
614
|
*/
|
|
611
615
|
chunkSplit?: ChunkSplit;
|
|
612
616
|
/**
|
|
@@ -659,9 +663,13 @@ export interface PerformanceConfig {
|
|
|
659
663
|
}
|
|
660
664
|
export interface NormalizedPerformanceConfig extends PerformanceConfig {
|
|
661
665
|
printFileSize: PrintFileSizeOptions | boolean;
|
|
662
|
-
chunkSplit: ChunkSplit;
|
|
663
666
|
}
|
|
664
667
|
export type SplitChunks = Rspack.OptimizationSplitChunksOptions | false;
|
|
668
|
+
export type SplitChunksPreset = 'default' | 'single-vendor' | 'per-package';
|
|
669
|
+
export type SplitChunksConfig = Rspack.OptimizationSplitChunksOptions & {
|
|
670
|
+
preset?: SplitChunksPreset;
|
|
671
|
+
};
|
|
672
|
+
export type NormalizedSplitChunksConfig = SplitChunksConfig;
|
|
665
673
|
export type ForceSplitting = RegExp[] | Record<string, RegExp>;
|
|
666
674
|
export interface BaseSplitRules {
|
|
667
675
|
strategy?: string;
|
|
@@ -1750,6 +1758,10 @@ export interface EnvironmentConfig {
|
|
|
1750
1758
|
* Options for build performance and runtime performance.
|
|
1751
1759
|
*/
|
|
1752
1760
|
performance?: PerformanceConfig;
|
|
1761
|
+
/**
|
|
1762
|
+
* Options for chunk splitting.
|
|
1763
|
+
*/
|
|
1764
|
+
splitChunks?: SplitChunksConfig | false;
|
|
1753
1765
|
/**
|
|
1754
1766
|
* Options for module federation.
|
|
1755
1767
|
*/
|
|
@@ -1791,8 +1803,9 @@ export interface RsbuildConfig extends EnvironmentConfig {
|
|
|
1791
1803
|
*/
|
|
1792
1804
|
dev?: DevConfig;
|
|
1793
1805
|
/**
|
|
1794
|
-
* Options for the Rsbuild server
|
|
1795
|
-
*
|
|
1806
|
+
* Options for the Rsbuild server.
|
|
1807
|
+
* Mainly applies to local development and preview.
|
|
1808
|
+
* Some options (e.g. `publicDir`, `base`) also affect production builds.
|
|
1796
1809
|
*/
|
|
1797
1810
|
server?: ServerConfig;
|
|
1798
1811
|
/**
|
|
@@ -1820,6 +1833,7 @@ export type MergedEnvironmentConfig = {
|
|
|
1820
1833
|
plugins?: RsbuildPlugins;
|
|
1821
1834
|
security: NormalizedSecurityConfig;
|
|
1822
1835
|
performance: NormalizedPerformanceConfig;
|
|
1836
|
+
splitChunks: NormalizedSplitChunksConfig | false;
|
|
1823
1837
|
moduleFederation?: ModuleFederationConfig;
|
|
1824
1838
|
};
|
|
1825
1839
|
/**
|
package/package.json
CHANGED
package/dist-types/rspack.d.ts
DELETED