@rsbuild/core 1.4.13 → 1.4.15
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/rslog/index.d.ts +63 -69
- package/compiled/rslog/index.js +1 -0
- package/compiled/rslog/package.json +1 -1
- package/compiled/rspack-chain/package.json +1 -1
- package/dist/client/hmr.js +10 -9
- package/dist/index.cjs +673 -682
- package/dist/index.js +644 -654
- package/dist-types/cli/index.d.ts +1 -1
- package/dist-types/createContext.d.ts +2 -2
- package/dist-types/helpers/index.d.ts +2 -2
- package/dist-types/index.d.ts +1 -1
- package/dist-types/inspectConfig.d.ts +2 -2
- package/dist-types/provider/rspackConfig.d.ts +1 -1
- package/dist-types/restart.d.ts +1 -1
- package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +2 -2
- package/dist-types/server/cliShortcuts.d.ts +2 -2
- package/dist-types/server/compilationManager.d.ts +7 -7
- package/dist-types/server/compilationMiddleware.d.ts +11 -11
- package/dist-types/server/devMiddlewares.d.ts +5 -6
- package/dist-types/server/environment.d.ts +2 -2
- package/dist-types/server/helper.d.ts +2 -2
- package/dist-types/server/hmrFallback.d.ts +1 -2
- package/dist-types/server/watchFiles.d.ts +2 -3
- package/dist-types/types/config.d.ts +8 -7
- package/dist-types/types/hooks.d.ts +3 -3
- package/dist-types/types/plugin.d.ts +4 -0
- package/dist-types/types/rsbuild.d.ts +6 -5
- package/package.json +8 -9
package/dist/index.cjs
CHANGED
|
@@ -1204,17 +1204,17 @@ for(var __webpack_i__ in (()=>{
|
|
|
1204
1204
|
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
1205
1205
|
PLUGIN_CSS_NAME: ()=>PLUGIN_CSS_NAME,
|
|
1206
1206
|
createRsbuild: ()=>createRsbuild,
|
|
1207
|
-
loadEnv: ()=>loadEnv,
|
|
1208
1207
|
logger: ()=>index_js_namespaceObject.logger,
|
|
1209
1208
|
mergeRsbuildConfig: ()=>mergeRsbuildConfig,
|
|
1210
|
-
version: ()=>src_version,
|
|
1211
1209
|
loadConfig: ()=>loadConfig_loadConfig,
|
|
1212
1210
|
PLUGIN_SWC_NAME: ()=>PLUGIN_SWC_NAME,
|
|
1213
1211
|
defaultAllowedOrigins: ()=>defaultAllowedOrigins,
|
|
1214
1212
|
ensureAssetPrefix: ()=>ensureAssetPrefix,
|
|
1213
|
+
loadEnv: ()=>loadEnv,
|
|
1215
1214
|
rspack: ()=>rspack_rspack,
|
|
1216
1215
|
runCLI: ()=>runCLI,
|
|
1217
|
-
defineConfig: ()=>defineConfig
|
|
1216
|
+
defineConfig: ()=>defineConfig,
|
|
1217
|
+
version: ()=>src_version
|
|
1218
1218
|
});
|
|
1219
1219
|
var provider_helpers_namespaceObject = {};
|
|
1220
1220
|
__webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(provider_helpers_namespaceObject, {
|
|
@@ -2254,18 +2254,7 @@ for(var __webpack_i__ in (()=>{
|
|
|
2254
2254
|
arr
|
|
2255
2255
|
], cloneDeep = (value)=>null == value ? value : cjs_default()({}, value, {
|
|
2256
2256
|
isMergeableObject: isPlainObject
|
|
2257
|
-
}),
|
|
2258
|
-
let version = originalVersion;
|
|
2259
|
-
return version.includes('-canary') && (version = version.split('-canary')[0]), !(version && /^[\d.]+$/.test(version)) || ((version1, version2)=>{
|
|
2260
|
-
let parts1 = version1.split('.').map(Number), parts2 = version2.split('.').map(Number), len = Math.max(parts1.length, parts2.length);
|
|
2261
|
-
for(let i = 0; i < len; i++){
|
|
2262
|
-
let item1 = parts1[i] ?? 0, item2 = parts2[i] ?? 0;
|
|
2263
|
-
if (item1 > item2) return 1;
|
|
2264
|
-
if (item1 < item2) return -1;
|
|
2265
|
-
}
|
|
2266
|
-
return 0;
|
|
2267
|
-
})(version, rspackMinVersion) >= 0;
|
|
2268
|
-
}, removeLeadingSlash = (s)=>s.replace(/^\/+/, ''), addTrailingSlash = (s)=>s.endsWith('/') ? s : `${s}/`, formatPublicPath = (publicPath, withSlash = !0)=>'auto' === publicPath ? publicPath : withSlash ? addTrailingSlash(publicPath) : publicPath.replace(/\/+$/, ''), getPublicPathFromChain = (chain, withSlash = !0)=>{
|
|
2257
|
+
}), removeLeadingSlash = (s)=>s.replace(/^\/+/, ''), addTrailingSlash = (s)=>s.endsWith('/') ? s : `${s}/`, formatPublicPath = (publicPath, withSlash = !0)=>'auto' === publicPath ? publicPath : withSlash ? addTrailingSlash(publicPath) : publicPath.replace(/\/+$/, ''), getPublicPathFromChain = (chain, withSlash = !0)=>{
|
|
2269
2258
|
let publicPath = chain.output.get('publicPath');
|
|
2270
2259
|
return 'string' == typeof publicPath ? formatPublicPath(publicPath, withSlash) : formatPublicPath(DEFAULT_ASSET_PREFIX, withSlash);
|
|
2271
2260
|
}, getPublicPathFromCompiler = (compiler)=>{
|
|
@@ -2673,7 +2662,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2673
2662
|
handler
|
|
2674
2663
|
});
|
|
2675
2664
|
},
|
|
2676
|
-
callChain: async ({ environment, args: params })=>{
|
|
2665
|
+
callChain: async ({ environment, args: params, afterEach })=>{
|
|
2677
2666
|
for (let callback of [
|
|
2678
2667
|
...preGroup,
|
|
2679
2668
|
...defaultGroup,
|
|
@@ -2681,7 +2670,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2681
2670
|
]){
|
|
2682
2671
|
if (environment && callback.environment && callback.environment !== environment) continue;
|
|
2683
2672
|
let result = await callback.handler(...params);
|
|
2684
|
-
void 0 !== result && (params[0] = result);
|
|
2673
|
+
void 0 !== result && (params[0] = result), afterEach && afterEach(params);
|
|
2685
2674
|
}
|
|
2686
2675
|
return params;
|
|
2687
2676
|
},
|
|
@@ -3242,54 +3231,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3242
3231
|
default:
|
|
3243
3232
|
throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} Invalid process assets stage: ${stage}`);
|
|
3244
3233
|
}
|
|
3245
|
-
}, browsersListCache = new Map()
|
|
3246
|
-
async function getBrowserslist(path) {
|
|
3247
|
-
let env = process.env.NODE_ENV, cacheKey = path + env;
|
|
3248
|
-
if (browsersListCache.has(cacheKey)) return browsersListCache.get(cacheKey);
|
|
3249
|
-
let result = function(opts) {
|
|
3250
|
-
if (opts.config) return pickEnv(parsePackageOrReadConfig(opts.config), opts);
|
|
3251
|
-
if (opts.path) {
|
|
3252
|
-
let config = function(from) {
|
|
3253
|
-
let resolved, fromDir = isFile(from = external_node_path_namespaceObject.resolve(from)) ? external_node_path_namespaceObject.dirname(from) : from;
|
|
3254
|
-
if (fromDir in configCache) return configCache[fromDir];
|
|
3255
|
-
let configFile = eachParent(from, (dir)=>{
|
|
3256
|
-
let pkgBrowserslist, config = external_node_path_namespaceObject.join(dir, 'browserslist'), pkg = external_node_path_namespaceObject.join(dir, 'package.json'), rc = external_node_path_namespaceObject.join(dir, '.browserslistrc');
|
|
3257
|
-
if (isFile(pkg)) try {
|
|
3258
|
-
pkgBrowserslist = parsePackage(pkg);
|
|
3259
|
-
} catch (e) {
|
|
3260
|
-
if (e instanceof BrowserslistError) throw e;
|
|
3261
|
-
console.warn(`[Browserslist] Could not parse ${pkg}. Ignoring it.`);
|
|
3262
|
-
}
|
|
3263
|
-
if (isFile(config) && pkgBrowserslist) throw new BrowserslistError(`${dir} contains both browserslist and package.json with browsers`);
|
|
3264
|
-
if (isFile(rc) && pkgBrowserslist) throw new BrowserslistError(`${dir} contains both .browserslistrc and package.json with browsers`);
|
|
3265
|
-
if (isFile(config) && isFile(rc)) throw new BrowserslistError(`${dir} contains both .browserslistrc and browserslist`);
|
|
3266
|
-
return isFile(config) ? config : isFile(rc) ? rc : pkgBrowserslist ? pkg : void 0;
|
|
3267
|
-
});
|
|
3268
|
-
configFile && (resolved = parsePackageOrReadConfig(configFile));
|
|
3269
|
-
let configDir = configFile && external_node_path_namespaceObject.dirname(configFile);
|
|
3270
|
-
return eachParent(from, (dir)=>{
|
|
3271
|
-
if (resolved && (configCache[dir] = resolved), dir === configDir) return null;
|
|
3272
|
-
}), resolved;
|
|
3273
|
-
}(opts.path);
|
|
3274
|
-
if (!config) return;
|
|
3275
|
-
return pickEnv(config, opts);
|
|
3276
|
-
}
|
|
3277
|
-
}({
|
|
3278
|
-
path,
|
|
3279
|
-
env
|
|
3280
|
-
});
|
|
3281
|
-
return result ? (browsersListCache.set(cacheKey, result), result) : null;
|
|
3282
|
-
}
|
|
3283
|
-
async function getBrowserslistByEnvironment(path, config) {
|
|
3284
|
-
let { target, overrideBrowserslist } = config.output;
|
|
3285
|
-
if (Array.isArray(overrideBrowserslist)) return overrideBrowserslist;
|
|
3286
|
-
if ('web' === target || 'web-worker' === target) {
|
|
3287
|
-
let browserslistrc = await getBrowserslist(path);
|
|
3288
|
-
if (browserslistrc) return browserslistrc;
|
|
3289
|
-
}
|
|
3290
|
-
return DEFAULT_BROWSERSLIST[target];
|
|
3291
|
-
}
|
|
3292
|
-
let getEnvironmentHTMLPaths = (entry, config)=>'web' !== config.output.target || !1 === config.tools.htmlPlugin ? {} : Object.keys(entry).reduce((prev, key)=>{
|
|
3234
|
+
}, browsersListCache = new Map(), getEnvironmentHTMLPaths = (entry, config)=>'web' !== config.output.target || !1 === config.tools.htmlPlugin ? {} : Object.keys(entry).reduce((prev, key)=>{
|
|
3293
3235
|
let entryValue = entry[key];
|
|
3294
3236
|
return ('string' == typeof entryValue || Array.isArray(entryValue) || !1 !== entryValue.html) && (prev[key] = function(entryName, config) {
|
|
3295
3237
|
let filename;
|
|
@@ -3300,7 +3242,51 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3300
3242
|
}, {});
|
|
3301
3243
|
async function updateEnvironmentContext(context, configs) {
|
|
3302
3244
|
for (let [index, [name, config]] of (context.environments ||= {}, Object.entries(configs).entries())){
|
|
3303
|
-
let browserslist =
|
|
3245
|
+
let browserslist = function(path, config) {
|
|
3246
|
+
let { target, overrideBrowserslist } = config.output;
|
|
3247
|
+
if (Array.isArray(overrideBrowserslist)) return overrideBrowserslist;
|
|
3248
|
+
if ('web' === target || 'web-worker' === target) {
|
|
3249
|
+
let browserslistrc = function(path) {
|
|
3250
|
+
let env = process.env.NODE_ENV, cacheKey = path + env;
|
|
3251
|
+
if (browsersListCache.has(cacheKey)) return browsersListCache.get(cacheKey);
|
|
3252
|
+
let result = function(opts) {
|
|
3253
|
+
if (opts.config) return pickEnv(parsePackageOrReadConfig(opts.config), opts);
|
|
3254
|
+
if (opts.path) {
|
|
3255
|
+
let config = function(from) {
|
|
3256
|
+
let resolved, fromDir = isFile(from = external_node_path_namespaceObject.resolve(from)) ? external_node_path_namespaceObject.dirname(from) : from;
|
|
3257
|
+
if (fromDir in configCache) return configCache[fromDir];
|
|
3258
|
+
let configFile = eachParent(from, (dir)=>{
|
|
3259
|
+
let pkgBrowserslist, config = external_node_path_namespaceObject.join(dir, 'browserslist'), pkg = external_node_path_namespaceObject.join(dir, 'package.json'), rc = external_node_path_namespaceObject.join(dir, '.browserslistrc');
|
|
3260
|
+
if (isFile(pkg)) try {
|
|
3261
|
+
pkgBrowserslist = parsePackage(pkg);
|
|
3262
|
+
} catch (e) {
|
|
3263
|
+
if (e instanceof BrowserslistError) throw e;
|
|
3264
|
+
console.warn(`[Browserslist] Could not parse ${pkg}. Ignoring it.`);
|
|
3265
|
+
}
|
|
3266
|
+
if (isFile(config) && pkgBrowserslist) throw new BrowserslistError(`${dir} contains both browserslist and package.json with browsers`);
|
|
3267
|
+
if (isFile(rc) && pkgBrowserslist) throw new BrowserslistError(`${dir} contains both .browserslistrc and package.json with browsers`);
|
|
3268
|
+
if (isFile(config) && isFile(rc)) throw new BrowserslistError(`${dir} contains both .browserslistrc and browserslist`);
|
|
3269
|
+
return isFile(config) ? config : isFile(rc) ? rc : pkgBrowserslist ? pkg : void 0;
|
|
3270
|
+
});
|
|
3271
|
+
configFile && (resolved = parsePackageOrReadConfig(configFile));
|
|
3272
|
+
let configDir = configFile && external_node_path_namespaceObject.dirname(configFile);
|
|
3273
|
+
return eachParent(from, (dir)=>{
|
|
3274
|
+
if (resolved && (configCache[dir] = resolved), dir === configDir) return null;
|
|
3275
|
+
}), resolved;
|
|
3276
|
+
}(opts.path);
|
|
3277
|
+
if (!config) return;
|
|
3278
|
+
return pickEnv(config, opts);
|
|
3279
|
+
}
|
|
3280
|
+
}({
|
|
3281
|
+
path,
|
|
3282
|
+
env
|
|
3283
|
+
});
|
|
3284
|
+
return result ? (browsersListCache.set(cacheKey, result), result) : null;
|
|
3285
|
+
}(path);
|
|
3286
|
+
if (browserslistrc) return browserslistrc;
|
|
3287
|
+
}
|
|
3288
|
+
return DEFAULT_BROWSERSLIST[target];
|
|
3289
|
+
}(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config), webSocketToken = 'dev' === context.action ? await helpers_hash(context.rootPath + name) : '', environmentContext = {
|
|
3304
3290
|
index,
|
|
3305
3291
|
name,
|
|
3306
3292
|
distPath: function(cwd, config) {
|
|
@@ -3323,7 +3309,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3323
3309
|
async function createContext(options, userConfig) {
|
|
3324
3310
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(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, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
|
|
3325
3311
|
return {
|
|
3326
|
-
version: "1.4.
|
|
3312
|
+
version: "1.4.15",
|
|
3327
3313
|
rootPath,
|
|
3328
3314
|
distPath: '',
|
|
3329
3315
|
cachePath,
|
|
@@ -3604,16 +3590,16 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3604
3590
|
async function modifyRspackConfig(context, rspackConfig, chainUtils) {
|
|
3605
3591
|
var _utils_environment_config_tools;
|
|
3606
3592
|
index_js_namespaceObject.logger.debug('modify Rspack config');
|
|
3607
|
-
let currentConfig = rspackConfig,
|
|
3608
|
-
get: (_, prop)=>currentConfig[prop],
|
|
3609
|
-
set: (_, prop, value)=>(currentConfig[prop] = value, !0)
|
|
3610
|
-
}), utils = await getConfigUtils(proxiedConfig, chainUtils);
|
|
3593
|
+
let currentConfig = rspackConfig, utils = getConfigUtils(()=>currentConfig, chainUtils);
|
|
3611
3594
|
if ([currentConfig] = await context.hooks.modifyRspackConfig.callChain({
|
|
3612
3595
|
environment: utils.environment.name,
|
|
3613
3596
|
args: [
|
|
3614
3597
|
rspackConfig,
|
|
3615
3598
|
utils
|
|
3616
|
-
]
|
|
3599
|
+
],
|
|
3600
|
+
afterEach: ([config])=>{
|
|
3601
|
+
currentConfig = config;
|
|
3602
|
+
}
|
|
3617
3603
|
}), null == (_utils_environment_config_tools = utils.environment.config.tools) ? void 0 : _utils_environment_config_tools.rspack) {
|
|
3618
3604
|
let toolsRspackConfig = utils.environment.config.tools.rspack;
|
|
3619
3605
|
currentConfig = await reduceConfigsAsyncWithContext({
|
|
@@ -3625,27 +3611,28 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3625
3611
|
}
|
|
3626
3612
|
return index_js_namespaceObject.logger.debug('modify Rspack config done'), currentConfig;
|
|
3627
3613
|
}
|
|
3628
|
-
|
|
3614
|
+
function getConfigUtils(getCurrentConfig, chainUtils) {
|
|
3629
3615
|
return {
|
|
3630
3616
|
...chainUtils,
|
|
3631
3617
|
mergeConfig: webpack_merge_dist.merge,
|
|
3632
3618
|
addRules (rules) {
|
|
3633
|
-
let ruleArr = helpers_castArray(rules);
|
|
3619
|
+
let config = getCurrentConfig(), ruleArr = helpers_castArray(rules);
|
|
3634
3620
|
config.module || (config.module = {}), config.module.rules || (config.module.rules = []), config.module.rules.unshift(...ruleArr);
|
|
3635
3621
|
},
|
|
3636
3622
|
appendRules (rules) {
|
|
3637
|
-
let ruleArr = helpers_castArray(rules);
|
|
3623
|
+
let config = getCurrentConfig(), ruleArr = helpers_castArray(rules);
|
|
3638
3624
|
config.module || (config.module = {}), config.module.rules || (config.module.rules = []), config.module.rules.push(...ruleArr);
|
|
3639
3625
|
},
|
|
3640
3626
|
prependPlugins (plugins) {
|
|
3641
|
-
let pluginArr = helpers_castArray(plugins);
|
|
3627
|
+
let config = getCurrentConfig(), pluginArr = helpers_castArray(plugins);
|
|
3642
3628
|
config.plugins || (config.plugins = []), config.plugins.unshift(...pluginArr);
|
|
3643
3629
|
},
|
|
3644
3630
|
appendPlugins (plugins) {
|
|
3645
|
-
let pluginArr = helpers_castArray(plugins);
|
|
3631
|
+
let config = getCurrentConfig(), pluginArr = helpers_castArray(plugins);
|
|
3646
3632
|
config.plugins || (config.plugins = []), config.plugins.push(...pluginArr);
|
|
3647
3633
|
},
|
|
3648
3634
|
removePlugin (pluginName) {
|
|
3635
|
+
let config = getCurrentConfig();
|
|
3649
3636
|
config.plugins && (config.plugins = config.plugins.filter((plugin)=>!plugin || (plugin.name || plugin.constructor.name) !== pluginName));
|
|
3650
3637
|
}
|
|
3651
3638
|
};
|
|
@@ -3687,6 +3674,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3687
3674
|
}
|
|
3688
3675
|
let allowedEnvironmentDevKeys = [
|
|
3689
3676
|
'hmr',
|
|
3677
|
+
'client',
|
|
3690
3678
|
'liveReload',
|
|
3691
3679
|
'writeToDisk',
|
|
3692
3680
|
'assetPrefix',
|
|
@@ -3715,6 +3703,10 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3715
3703
|
});
|
|
3716
3704
|
return index_js_namespaceObject.logger.debug(`modify Rsbuild environment(${name}) config done`), modified;
|
|
3717
3705
|
}
|
|
3706
|
+
let createEnvironmentNotFoundError = (environments = [])=>{
|
|
3707
|
+
let envList = picocolors_index_js_default().yellow(environments.join(','));
|
|
3708
|
+
return Error(`${picocolors_index_js_default().dim('[rsbuild:config]')} The current build is specified to run only in the ${envList} environment, but the configuration of the specified environment was not found.`);
|
|
3709
|
+
};
|
|
3718
3710
|
async function initRsbuildConfig({ context, pluginManager }) {
|
|
3719
3711
|
if (context.normalizedConfig) return context.normalizedConfig;
|
|
3720
3712
|
await initPlugins({
|
|
@@ -3734,7 +3726,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3734
3726
|
watchFiles
|
|
3735
3727
|
]), mergedConfig;
|
|
3736
3728
|
})(context.config), environments = {}, mergedEnvironments = ((normalizedConfig, rootPath, specifiedEnvironments)=>{
|
|
3737
|
-
let defaultEntry, { environments, dev, server: _server, provider: _provider, ...
|
|
3729
|
+
let defaultEntry, { environments, dev, server: _server, provider: _provider, ...baseConfig } = normalizedConfig, isEnvironmentEnabled = (name)=>!specifiedEnvironments || specifiedEnvironments.includes(name), applyEnvironmentDefaultConfig = (config)=>{
|
|
3738
3730
|
config.source.entry && 0 !== Object.keys(config.source.entry).length || (config.source.entry = (defaultEntry || (defaultEntry = function(root) {
|
|
3739
3731
|
let entryFile = findExists([
|
|
3740
3732
|
'ts',
|
|
@@ -3753,24 +3745,24 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3753
3745
|
let isServer = 'node' === config.output.target;
|
|
3754
3746
|
return void 0 === config.output.distPath.js && (config.output.distPath.js = isServer ? '' : 'static/js'), config;
|
|
3755
3747
|
};
|
|
3756
|
-
if (environments && Object.keys(environments).length) {
|
|
3748
|
+
if (environments && Object.keys(environments).length > 0) {
|
|
3757
3749
|
let resolvedEnvironments = Object.fromEntries(Object.entries(environments).filter(([name])=>isEnvironmentEnabled(name)).map(([name, config])=>[
|
|
3758
3750
|
name,
|
|
3759
3751
|
applyEnvironmentDefaultConfig({
|
|
3760
3752
|
...mergeRsbuildConfig({
|
|
3761
|
-
...
|
|
3753
|
+
...baseConfig,
|
|
3762
3754
|
dev: pick(dev, allowedEnvironmentDevKeys)
|
|
3763
3755
|
}, config)
|
|
3764
3756
|
})
|
|
3765
3757
|
]));
|
|
3766
|
-
if (
|
|
3758
|
+
if (0 === Object.keys(resolvedEnvironments).length) throw createEnvironmentNotFoundError(specifiedEnvironments);
|
|
3767
3759
|
return resolvedEnvironments;
|
|
3768
3760
|
}
|
|
3769
|
-
let defaultEnvironmentName =
|
|
3770
|
-
if (!isEnvironmentEnabled(defaultEnvironmentName)) throw
|
|
3761
|
+
let defaultEnvironmentName = baseConfig.output.target.replace(/[-_](\w)/g, (_, c)=>c.toUpperCase());
|
|
3762
|
+
if (!isEnvironmentEnabled(defaultEnvironmentName)) throw createEnvironmentNotFoundError(specifiedEnvironments);
|
|
3771
3763
|
return {
|
|
3772
3764
|
[defaultEnvironmentName]: applyEnvironmentDefaultConfig({
|
|
3773
|
-
...
|
|
3765
|
+
...baseConfig,
|
|
3774
3766
|
dev: pick(dev, allowedEnvironmentDevKeys)
|
|
3775
3767
|
})
|
|
3776
3768
|
};
|
|
@@ -3873,12 +3865,21 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3873
3865
|
return files.length > 1 ? `${fileInfo} and ${files.length - 1} more` : fileInfo;
|
|
3874
3866
|
}
|
|
3875
3867
|
async function createCompiler_createCompiler(options) {
|
|
3868
|
+
let version;
|
|
3876
3869
|
index_js_namespaceObject.logger.debug('create compiler');
|
|
3877
3870
|
let { context } = options, { rspackConfigs } = await initConfigs(options);
|
|
3878
3871
|
if (await context.hooks.onBeforeCreateCompiler.callBatch({
|
|
3879
3872
|
bundlerConfigs: rspackConfigs,
|
|
3880
3873
|
environments: context.environments
|
|
3881
|
-
}),
|
|
3874
|
+
}), (version = rspack_rspack.rspackVersion).includes('-canary') && (version = version.split('-canary')[0]), !(!(version && /^[\d.]+$/.test(version)) || ((version1, version2)=>{
|
|
3875
|
+
let parts1 = version1.split('.').map(Number), parts2 = version2.split('.').map(Number), len = Math.max(parts1.length, parts2.length);
|
|
3876
|
+
for(let i = 0; i < len; i++){
|
|
3877
|
+
let item1 = parts1[i] ?? 0, item2 = parts2[i] ?? 0;
|
|
3878
|
+
if (item1 > item2) return 1;
|
|
3879
|
+
if (item1 < item2) return -1;
|
|
3880
|
+
}
|
|
3881
|
+
return 0;
|
|
3882
|
+
})(version, rspackMinVersion) >= 0)) throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${picocolors_index_js_default().green(rspackMinVersion)}`);
|
|
3882
3883
|
let isMultiCompiler = rspackConfigs.length > 1, compiler = isMultiCompiler ? rspack_rspack(rspackConfigs) : rspack_rspack(rspackConfigs[0]), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
|
|
3883
3884
|
isVersionLogged || (index_js_namespaceObject.logger.debug(`use Rspack v${rspack_rspack.rspackVersion}`), isVersionLogged = !0);
|
|
3884
3885
|
};
|
|
@@ -5356,19 +5357,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5356
5357
|
}
|
|
5357
5358
|
};
|
|
5358
5359
|
}
|
|
5359
|
-
}, swc_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), builtinSwcLoaderName = 'builtin:swc-loader';
|
|
5360
|
-
async function applyCoreJs(swcConfig, polyfillMode) {
|
|
5361
|
-
let coreJsPath = swc_require.resolve('core-js/package.json'), version = ((corejsPkgPath)=>{
|
|
5362
|
-
try {
|
|
5363
|
-
let rawJson = external_node_fs_default().readFileSync(corejsPkgPath, 'utf-8'), { version } = JSON.parse(rawJson), [major, minor] = version.split('.');
|
|
5364
|
-
return `${major}.${minor}`;
|
|
5365
|
-
} catch {
|
|
5366
|
-
return '3';
|
|
5367
|
-
}
|
|
5368
|
-
})(coreJsPath), coreJsDir = external_node_path_default().dirname(coreJsPath);
|
|
5369
|
-
return swcConfig.env.coreJs = version, 'usage' === polyfillMode && (swcConfig.env.shippedProposals = !0), coreJsDir;
|
|
5370
|
-
}
|
|
5371
|
-
let isCliShortcutsEnabled = (devConfig)=>devConfig.cliShortcuts && isTTY('stdin');
|
|
5360
|
+
}, swc_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), builtinSwcLoaderName = 'builtin:swc-loader', isCliShortcutsEnabled = (config)=>config.dev.cliShortcuts && isTTY('stdin');
|
|
5372
5361
|
async function setupCliShortcuts({ help = !0, openPage, closeServer, printUrls, restartServer, customShortcuts }) {
|
|
5373
5362
|
let shortcuts = [
|
|
5374
5363
|
{
|
|
@@ -5442,21 +5431,13 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5442
5431
|
'0000:0000:0000:0000:0000:0000:0000:0000'
|
|
5443
5432
|
]).has(host1)) ? 'localhost' : host;
|
|
5444
5433
|
}
|
|
5445
|
-
|
|
5446
|
-
let resolvedHost = await resolveHostname(
|
|
5447
|
-
return {
|
|
5448
|
-
...clientConfig,
|
|
5449
|
-
host: resolvedHost,
|
|
5450
|
-
port: serverConfig.port
|
|
5451
|
-
};
|
|
5452
|
-
}
|
|
5453
|
-
let compilationMiddleware_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), getCompilationMiddleware = async (compiler, options)=>{
|
|
5454
|
-
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js")), { callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
|
|
5434
|
+
let compilationMiddleware_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), getCompilationMiddleware = async ({ config, compiler, callbacks, environments, resolvedPort })=>{
|
|
5435
|
+
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js")), resolvedHost = await resolveHostname(config.server.host);
|
|
5455
5436
|
return applyToCompiler(compiler, (compiler, index)=>{
|
|
5456
|
-
let environment = Object.values(
|
|
5437
|
+
let environment = Object.values(environments).find((env)=>env.index === index);
|
|
5457
5438
|
if (!environment) return;
|
|
5458
5439
|
let token = environment.webSocketToken;
|
|
5459
|
-
token && (!function({ config, compiler,
|
|
5440
|
+
token && (!function({ config, compiler, token, resolvedHost, resolvedPort }) {
|
|
5460
5441
|
if (!((compiler)=>{
|
|
5461
5442
|
let { target } = compiler.options;
|
|
5462
5443
|
return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
|
|
@@ -5466,20 +5447,25 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5466
5447
|
let clientPaths = [];
|
|
5467
5448
|
return (devConfig.hmr || devConfig.liveReload) && (hmrClientPath || (hmrClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/hmr')), clientPaths.push(hmrClientPath), (null == (_devConfig_client = devConfig.client) ? void 0 : _devConfig_client.overlay) && (overlayClientPath || (overlayClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/overlay')), clientPaths.push(overlayClientPath))), clientPaths;
|
|
5468
5449
|
}(config.dev);
|
|
5469
|
-
if (clientPaths.length)
|
|
5450
|
+
if (!clientPaths.length) return;
|
|
5451
|
+
let clientConfig = {
|
|
5452
|
+
...config.dev.client
|
|
5453
|
+
};
|
|
5454
|
+
for (let clientPath of ('<port>' === clientConfig.port && (clientConfig.port = resolvedPort), new compiler.webpack.DefinePlugin({
|
|
5470
5455
|
RSBUILD_WEB_SOCKET_TOKEN: JSON.stringify(token),
|
|
5471
|
-
RSBUILD_CLIENT_CONFIG: JSON.stringify(
|
|
5472
|
-
|
|
5473
|
-
|
|
5456
|
+
RSBUILD_CLIENT_CONFIG: JSON.stringify(clientConfig),
|
|
5457
|
+
RSBUILD_SERVER_HOST: JSON.stringify(resolvedHost),
|
|
5458
|
+
RSBUILD_SERVER_PORT: JSON.stringify(resolvedPort),
|
|
5459
|
+
RSBUILD_DEV_LIVE_RELOAD: config.dev.liveReload
|
|
5474
5460
|
}).apply(compiler), clientPaths))new compiler.webpack.EntryPlugin(compiler.context, clientPath, {
|
|
5475
5461
|
name: void 0
|
|
5476
5462
|
}).apply(compiler);
|
|
5477
5463
|
}({
|
|
5478
|
-
compiler,
|
|
5479
|
-
devConfig,
|
|
5480
|
-
resolvedClientConfig,
|
|
5481
5464
|
token,
|
|
5482
|
-
config: environment.config
|
|
5465
|
+
config: environment.config,
|
|
5466
|
+
compiler,
|
|
5467
|
+
resolvedHost,
|
|
5468
|
+
resolvedPort
|
|
5483
5469
|
}), (({ compiler, token, callbacks: { onDone, onInvalid } })=>{
|
|
5484
5470
|
if (((compiler)=>{
|
|
5485
5471
|
let { target } = compiler.options;
|
|
@@ -5503,7 +5489,13 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5503
5489
|
publicPath: '/',
|
|
5504
5490
|
stats: !1,
|
|
5505
5491
|
serverSideRender: !0,
|
|
5506
|
-
writeToDisk:
|
|
5492
|
+
writeToDisk: ((config, environments)=>{
|
|
5493
|
+
let writeToDiskValues = Object.values(environments).map((env)=>env.config.dev.writeToDisk);
|
|
5494
|
+
return 1 === new Set(writeToDiskValues).size ? writeToDiskValues[0] : (filePath, name)=>{
|
|
5495
|
+
let { writeToDisk } = config;
|
|
5496
|
+
return name && environments[name] && (writeToDisk = environments[name].config.dev.writeToDisk ?? writeToDisk), 'function' == typeof writeToDisk ? writeToDisk(filePath) : writeToDisk;
|
|
5497
|
+
};
|
|
5498
|
+
})(config.dev, environments)
|
|
5507
5499
|
});
|
|
5508
5500
|
}, styles = {
|
|
5509
5501
|
1: 'font-weight:bold',
|
|
@@ -5869,7 +5861,9 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5869
5861
|
});
|
|
5870
5862
|
}
|
|
5871
5863
|
async setupCompilationMiddleware() {
|
|
5872
|
-
let {
|
|
5864
|
+
let { config, publicPaths, environments } = this, middleware = await getCompilationMiddleware({
|
|
5865
|
+
config,
|
|
5866
|
+
compiler: this.compiler,
|
|
5873
5867
|
callbacks: {
|
|
5874
5868
|
onInvalid: (token, fileName)=>{
|
|
5875
5869
|
if ('string' == typeof fileName && fileName.endsWith('.html')) return void this.socketServer.sockWrite({
|
|
@@ -5880,10 +5874,9 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5880
5874
|
this.socketServer.updateStats(stats, token);
|
|
5881
5875
|
}
|
|
5882
5876
|
},
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
}), { base } = serverConfig, assetPrefixes = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
5877
|
+
environments,
|
|
5878
|
+
resolvedPort: this.resolvedPort
|
|
5879
|
+
}), { base } = config.server, assetPrefixes = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = (req, res, next)=>{
|
|
5887
5880
|
let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
|
|
5888
5881
|
assetPrefix && '/' !== assetPrefix ? (req.url = url.slice(assetPrefix.length - 1), middleware(req, res, (...args)=>{
|
|
5889
5882
|
req.url = url, next(...args);
|
|
@@ -5891,20 +5884,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
5891
5884
|
};
|
|
5892
5885
|
wrapper.close = middleware.close, wrapper.watch = middleware.watch, this.middleware = wrapper;
|
|
5893
5886
|
}
|
|
5894
|
-
constructor({
|
|
5895
|
-
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "
|
|
5896
|
-
let writeToDiskValues = Object.values(environments).map((env)=>env.config.dev.writeToDisk);
|
|
5897
|
-
return 1 === new Set(writeToDiskValues).size ? {
|
|
5898
|
-
...config,
|
|
5899
|
-
writeToDisk: writeToDiskValues[0]
|
|
5900
|
-
} : {
|
|
5901
|
-
...config,
|
|
5902
|
-
writeToDisk (filePath, compilationName) {
|
|
5903
|
-
let { writeToDisk } = config;
|
|
5904
|
-
return compilationName && environments[compilationName] && (writeToDisk = environments[compilationName].config.dev.writeToDisk ?? writeToDisk), 'function' == typeof writeToDisk ? writeToDisk(filePath) : writeToDisk;
|
|
5905
|
-
}
|
|
5906
|
-
};
|
|
5907
|
-
})(dev, environments), this.serverConfig = server, this.compiler = compiler, this.environments = environments, this.publicPaths = publicPaths, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(dev, environments);
|
|
5887
|
+
constructor({ config, compiler, publicPaths, resolvedPort, environments }){
|
|
5888
|
+
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "config", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "environments", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "resolvedPort", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : external_node_fs_default().readFileSync(fileName, 'utf-8')), this.config = config, this.compiler = compiler, this.environments = environments, this.publicPaths = publicPaths, this.resolvedPort = resolvedPort, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(config.dev, environments);
|
|
5908
5889
|
}
|
|
5909
5890
|
}
|
|
5910
5891
|
let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, gzipMiddleware = ({ filter, level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
@@ -6020,7 +6001,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6020
6001
|
if (!req.url || !req.headers || 'GET' !== req.method && 'HEAD' !== req.method) return !1;
|
|
6021
6002
|
let { accept } = req.headers;
|
|
6022
6003
|
return 'string' == typeof accept && (accept.includes('text/html') || accept.includes('*/*'));
|
|
6023
|
-
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getBaseMiddleware = ({ base })=>
|
|
6004
|
+
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getBaseMiddleware = ({ base })=>(req, res, next)=>{
|
|
6024
6005
|
var _req_headers_accept;
|
|
6025
6006
|
let url = req.url, pathname = getUrlPathname(url);
|
|
6026
6007
|
if (pathname.startsWith(base)) {
|
|
@@ -6078,8 +6059,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6078
6059
|
for (let middleware of proxyMiddlewares)'function' == typeof middleware.upgrade && middleware.upgrade(req, socket, head);
|
|
6079
6060
|
}
|
|
6080
6061
|
};
|
|
6081
|
-
}, applyDefaultMiddlewares = async ({
|
|
6082
|
-
let upgradeEvents = [];
|
|
6062
|
+
}, applyDefaultMiddlewares = async ({ config, compilationManager, context, devServerAPI, middlewares, pwd, postCallbacks })=>{
|
|
6063
|
+
let upgradeEvents = [], { server } = config;
|
|
6083
6064
|
if (server.cors) {
|
|
6084
6065
|
let { default: corsMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/cors/index.js"));
|
|
6085
6066
|
middlewares.push(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
@@ -6222,8 +6203,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6222
6203
|
}, getDevMiddlewares = async (options)=>{
|
|
6223
6204
|
let middlewares = [], { compilationManager } = options;
|
|
6224
6205
|
'verbose' === index_js_namespaceObject.logger.level && middlewares.push(await getRequestLoggerMiddleware());
|
|
6225
|
-
let { before, after } = ((
|
|
6226
|
-
let setupMiddlewares = dev.setupMiddlewares || [], serverOptions = pick(devServerAPI, [
|
|
6206
|
+
let { before, after } = ((config, devServerAPI)=>{
|
|
6207
|
+
let setupMiddlewares = config.dev.setupMiddlewares || [], serverOptions = pick(devServerAPI, [
|
|
6227
6208
|
'sockWrite',
|
|
6228
6209
|
'environments'
|
|
6229
6210
|
]), before = [], after = [];
|
|
@@ -6235,7 +6216,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6235
6216
|
before,
|
|
6236
6217
|
after
|
|
6237
6218
|
};
|
|
6238
|
-
})(options.
|
|
6219
|
+
})(options.config, options.devServerAPI);
|
|
6239
6220
|
middlewares.push(...before);
|
|
6240
6221
|
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
6241
6222
|
...options,
|
|
@@ -6457,7 +6438,10 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6457
6438
|
}(this, "name", void 0), this.name = name;
|
|
6458
6439
|
}
|
|
6459
6440
|
}
|
|
6460
|
-
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>
|
|
6441
|
+
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
6442
|
+
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
6443
|
+
return await runner.run(bundlePath);
|
|
6444
|
+
}, loadBundle = async (stats, entryName, utils)=>{
|
|
6461
6445
|
let { chunks, entrypoints, outputPath } = stats.toJson({
|
|
6462
6446
|
all: !1,
|
|
6463
6447
|
chunks: !0,
|
|
@@ -6482,11 +6466,6 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6482
6466
|
readFileSync: utils.readFileSync,
|
|
6483
6467
|
isBundleOutput: (modulePath)=>allChunkFiles.includes(modulePath)
|
|
6484
6468
|
});
|
|
6485
|
-
}, getTransformedHtml = async (entryName, utils)=>{
|
|
6486
|
-
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
6487
|
-
if (!htmlPath) throw Error(`${picocolors_index_js_default().dim('[rsbuild:getTransformedHtml]')} Failed to get HTML file by entryName: ${picocolors_index_js_default().yellow(entryName)}`);
|
|
6488
|
-
let fileName = (0, external_node_path_namespaceObject.join)(distPath, htmlPath);
|
|
6489
|
-
return utils.readFileSync(fileName);
|
|
6490
6469
|
}, createCacheableFunction = (getter)=>{
|
|
6491
6470
|
let cache = new WeakMap();
|
|
6492
6471
|
return async (stats, entryName, utils)=>{
|
|
@@ -6539,14 +6518,14 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6539
6518
|
return createServer(middlewares);
|
|
6540
6519
|
};
|
|
6541
6520
|
async function setupWatchFiles(options) {
|
|
6542
|
-
let {
|
|
6521
|
+
let { config, root, compilationManager } = options, { hmr, liveReload } = config.dev;
|
|
6543
6522
|
if (!hmr && !liveReload || !compilationManager) return;
|
|
6544
|
-
let closeDevFilesWatcher = await watchDevFiles(dev, compilationManager, root), serverFilesWatcher = await function(serverConfig, compilationManager, root) {
|
|
6523
|
+
let closeDevFilesWatcher = await watchDevFiles(config.dev, compilationManager, root), serverFilesWatcher = await function(serverConfig, compilationManager, root) {
|
|
6545
6524
|
let publicDirs = normalizePublicDirs(serverConfig.publicDir);
|
|
6546
6525
|
if (!publicDirs.length) return;
|
|
6547
6526
|
let watchPaths = publicDirs.filter((item)=>item.watch).map((item)=>item.name);
|
|
6548
6527
|
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), compilationManager, root);
|
|
6549
|
-
}(server, compilationManager, root);
|
|
6528
|
+
}(config.server, compilationManager, root);
|
|
6550
6529
|
return {
|
|
6551
6530
|
async close () {
|
|
6552
6531
|
await Promise.all([
|
|
@@ -6602,15 +6581,14 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6602
6581
|
}), watcher;
|
|
6603
6582
|
}
|
|
6604
6583
|
async function devServer_createDevServer(options, createCompiler, config, { compiler: customCompiler, getPortSilently, runCompile = !0 } = {}) {
|
|
6605
|
-
var config1, port;
|
|
6606
6584
|
let lastStats, fileWatcher, devMiddlewares;
|
|
6607
6585
|
index_js_namespaceObject.logger.debug('create dev server');
|
|
6608
|
-
let { port
|
|
6586
|
+
let { port, host, https, portTip } = await getServerConfig({
|
|
6609
6587
|
config
|
|
6610
|
-
}), { middlewareMode } = config.server, { context } = options,
|
|
6588
|
+
}), { middlewareMode } = config.server, { context } = options, routes = getRoutes(context), root = context.rootPath;
|
|
6611
6589
|
context.devServer = {
|
|
6612
6590
|
hostname: host,
|
|
6613
|
-
port
|
|
6591
|
+
port,
|
|
6614
6592
|
https
|
|
6615
6593
|
};
|
|
6616
6594
|
let waitLastCompileDoneResolve = null, waitLastCompileDone = new Promise((resolve)=>{
|
|
@@ -6632,30 +6610,27 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6632
6610
|
let publicPaths = helpers_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
6633
6611
|
getPublicPathFromCompiler(compiler)
|
|
6634
6612
|
], compilationManager = new CompilationManager({
|
|
6635
|
-
|
|
6636
|
-
server: {
|
|
6637
|
-
...config.server,
|
|
6638
|
-
port: port1
|
|
6639
|
-
},
|
|
6640
|
-
publicPaths: publicPaths,
|
|
6613
|
+
config,
|
|
6641
6614
|
compiler,
|
|
6615
|
+
publicPaths: publicPaths,
|
|
6616
|
+
resolvedPort: port,
|
|
6642
6617
|
environments: context.environments
|
|
6643
6618
|
});
|
|
6644
6619
|
return await compilationManager.init(), compilationManager;
|
|
6645
6620
|
}, protocol = https ? 'https' : 'http', urls = await getAddressUrls({
|
|
6646
6621
|
protocol,
|
|
6647
|
-
port
|
|
6622
|
+
port,
|
|
6648
6623
|
host
|
|
6649
|
-
}), cliShortcutsEnabled = isCliShortcutsEnabled(
|
|
6624
|
+
}), cliShortcutsEnabled = isCliShortcutsEnabled(config), printUrls = ()=>printServerURLs({
|
|
6650
6625
|
urls,
|
|
6651
|
-
port
|
|
6626
|
+
port,
|
|
6652
6627
|
routes,
|
|
6653
6628
|
protocol,
|
|
6654
6629
|
printUrls: config.server.printUrls,
|
|
6655
6630
|
trailingLineBreak: !cliShortcutsEnabled
|
|
6656
6631
|
}), openPage = async ()=>server_open_open({
|
|
6657
6632
|
https,
|
|
6658
|
-
port
|
|
6633
|
+
port,
|
|
6659
6634
|
routes,
|
|
6660
6635
|
config,
|
|
6661
6636
|
clearCache: !0
|
|
@@ -6668,7 +6643,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6668
6643
|
middlewareMode || registerCleanup(closeServer);
|
|
6669
6644
|
let beforeCreateCompiler = async ()=>{
|
|
6670
6645
|
if (printUrls(), cliShortcutsEnabled) {
|
|
6671
|
-
let shortcutsOptions = 'boolean' == typeof
|
|
6646
|
+
let shortcutsOptions = 'boolean' == typeof config.dev.cliShortcuts ? {} : config.dev.cliShortcuts, cleanup = await setupCliShortcuts({
|
|
6672
6647
|
openPage,
|
|
6673
6648
|
closeServer,
|
|
6674
6649
|
printUrls,
|
|
@@ -6681,7 +6656,12 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6681
6656
|
context.hooks.onCloseDevServer.tap(cleanup);
|
|
6682
6657
|
}
|
|
6683
6658
|
!getPortSilently && portTip && index_js_namespaceObject.logger.info(portTip);
|
|
6684
|
-
}, cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>
|
|
6659
|
+
}, cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>((entryName, utils)=>{
|
|
6660
|
+
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
6661
|
+
if (!htmlPath) throw Error(`${picocolors_index_js_default().dim('[rsbuild:getTransformedHtml]')} Failed to get HTML file by entryName: ${picocolors_index_js_default().yellow(entryName)}`);
|
|
6662
|
+
let fileName = (0, external_node_path_namespaceObject.join)(distPath, htmlPath);
|
|
6663
|
+
return utils.readFileSync(fileName);
|
|
6664
|
+
})(entryName, utils)), environmentAPI = Object.fromEntries(Object.entries(context.environments).map(([name, environment])=>[
|
|
6685
6665
|
name,
|
|
6686
6666
|
{
|
|
6687
6667
|
getStats: async ()=>{
|
|
@@ -6708,7 +6688,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6708
6688
|
serverConfig: config.server,
|
|
6709
6689
|
middlewares
|
|
6710
6690
|
}), devServerAPI = {
|
|
6711
|
-
port
|
|
6691
|
+
port,
|
|
6712
6692
|
middlewares,
|
|
6713
6693
|
environments: environmentAPI,
|
|
6714
6694
|
httpServer,
|
|
@@ -6722,11 +6702,11 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6722
6702
|
return index_js_namespaceObject.logger.debug('listen dev server'), context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
|
|
6723
6703
|
httpServer.listen({
|
|
6724
6704
|
host,
|
|
6725
|
-
port
|
|
6705
|
+
port
|
|
6726
6706
|
}, async (err)=>{
|
|
6727
6707
|
if (err) throw err;
|
|
6728
6708
|
middlewares.use(optionsFallbackMiddleware), middlewares.use(notFoundMiddleware), devMiddlewares && httpServer.on('upgrade', devMiddlewares.onUpgrade), index_js_namespaceObject.logger.debug('listen dev server done'), await devServerAPI.afterListen(), onBeforeRestartServer(devServerAPI.close), resolve({
|
|
6729
|
-
port
|
|
6709
|
+
port,
|
|
6730
6710
|
urls: urls.map((item)=>item.url),
|
|
6731
6711
|
server: {
|
|
6732
6712
|
close: devServerAPI.close
|
|
@@ -6737,7 +6717,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6737
6717
|
},
|
|
6738
6718
|
afterListen: async ()=>{
|
|
6739
6719
|
await context.hooks.onAfterStartDevServer.callBatch({
|
|
6740
|
-
port
|
|
6720
|
+
port,
|
|
6741
6721
|
routes,
|
|
6742
6722
|
environments: context.environments
|
|
6743
6723
|
});
|
|
@@ -6755,22 +6735,20 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6755
6735
|
runCompile ? context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : await beforeCreateCompiler();
|
|
6756
6736
|
let compilationManager = runCompile ? await startCompile() : void 0;
|
|
6757
6737
|
for (let item of (fileWatcher = await setupWatchFiles({
|
|
6758
|
-
|
|
6759
|
-
server: config.server,
|
|
6738
|
+
config,
|
|
6760
6739
|
compilationManager,
|
|
6761
6740
|
root
|
|
6762
6741
|
}), (devMiddlewares = await getDevMiddlewares({
|
|
6763
6742
|
pwd: root,
|
|
6764
6743
|
compilationManager,
|
|
6765
|
-
|
|
6744
|
+
config,
|
|
6766
6745
|
devServerAPI,
|
|
6767
6746
|
context,
|
|
6768
|
-
server: config.server,
|
|
6769
6747
|
postCallbacks
|
|
6770
6748
|
})).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
|
|
6771
6749
|
return null == compilationManager || compilationManager.watch(), index_js_namespaceObject.logger.debug('create dev server done'), devServerAPI;
|
|
6772
6750
|
}
|
|
6773
|
-
let rspackProvider =
|
|
6751
|
+
let rspackProvider = ({ context, pluginManager, rsbuildOptions })=>{
|
|
6774
6752
|
let createCompiler = async ()=>(await createCompiler_createCompiler({
|
|
6775
6753
|
context,
|
|
6776
6754
|
pluginManager,
|
|
@@ -6806,7 +6784,12 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6806
6784
|
pluginManager,
|
|
6807
6785
|
rsbuildOptions
|
|
6808
6786
|
}, options),
|
|
6809
|
-
async initConfigs () {
|
|
6787
|
+
async initConfigs (options) {
|
|
6788
|
+
if (context.action && (null == options ? void 0 : options.action) && context.action !== options.action) throw Error(`\
|
|
6789
|
+
[rsbuild] initConfigs() can only be called with the same action type.
|
|
6790
|
+
- Expected: ${context.action}
|
|
6791
|
+
- Actual: ${null == options ? void 0 : options.action}`);
|
|
6792
|
+
(null == options ? void 0 : options.action) && (context.action = options.action);
|
|
6810
6793
|
let { rspackConfigs } = await initConfigs({
|
|
6811
6794
|
context,
|
|
6812
6795
|
pluginManager,
|
|
@@ -6919,7 +6902,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6919
6902
|
protocol,
|
|
6920
6903
|
port,
|
|
6921
6904
|
host
|
|
6922
|
-
}), cliShortcutsEnabled = isCliShortcutsEnabled(config
|
|
6905
|
+
}), cliShortcutsEnabled = isCliShortcutsEnabled(config), cleanupGracefulShutdown = setupGracefulShutdown(), closeServer = async ()=>{
|
|
6923
6906
|
removeCleanup(closeServer), cleanupGracefulShutdown(), await Promise.all([
|
|
6924
6907
|
server.close(),
|
|
6925
6908
|
serverTerminator()
|
|
@@ -6960,147 +6943,442 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6960
6943
|
});
|
|
6961
6944
|
});
|
|
6962
6945
|
}
|
|
6963
|
-
async function
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
{
|
|
6980
|
-
test: /\.css$/,
|
|
6981
|
-
filename: '[file].map[query]'
|
|
6982
|
-
}
|
|
6983
|
-
]), chain.context(api.context.rootPath), chain.mode(environment.config.mode), chain.infrastructureLogging({
|
|
6984
|
-
level: 'error'
|
|
6985
|
-
}), chain.watchOptions({
|
|
6986
|
-
aggregateTimeout: 0
|
|
6987
|
-
}), chain.performance.hints(!1), chain.module.parser.merge({
|
|
6988
|
-
javascript: {
|
|
6989
|
-
exportsPresence: 'error',
|
|
6990
|
-
typeReexportsPresence: 'tolerant'
|
|
6991
|
-
}
|
|
6992
|
-
}), isDev && config.dev.hmr && 'web' === target && chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin), isDev && chain.output.devtoolModuleFilenameTemplate((info)=>toPosixPath(info.absoluteResourcePath)), 'rspack' === api.context.bundlerType && chain.experiments({
|
|
6993
|
-
...chain.get('experiments'),
|
|
6994
|
-
typeReexportsPresence: !0,
|
|
6995
|
-
rspackFuture: {
|
|
6996
|
-
bundlerInfo: {
|
|
6997
|
-
force: !1
|
|
6998
|
-
}
|
|
6999
|
-
}
|
|
7000
|
-
}), process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-silent';
|
|
7001
|
-
});
|
|
6946
|
+
async function createRsbuild(options = {}) {
|
|
6947
|
+
var pluginManager, context;
|
|
6948
|
+
let plugins, context1, envs = options.loadEnv ? loadEnv({
|
|
6949
|
+
cwd: options.cwd,
|
|
6950
|
+
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
6951
|
+
}) : null, config = isFunction(options.rsbuildConfig) ? await options.rsbuildConfig() : options.rsbuildConfig || {};
|
|
6952
|
+
config.logLevel && (index_js_namespaceObject.logger.level = config.logLevel), function(config, envs) {
|
|
6953
|
+
var _config_performance;
|
|
6954
|
+
if (null !== envs && (config.source ||= {}, config.source.define = {
|
|
6955
|
+
...envs.publicVars,
|
|
6956
|
+
...config.source.define
|
|
6957
|
+
}, 0 !== envs.filePaths.length && (config.dev ||= {}, config.dev.watchFiles = [
|
|
6958
|
+
...config.dev.watchFiles ? helpers_castArray(config.dev.watchFiles) : [],
|
|
6959
|
+
{
|
|
6960
|
+
paths: envs.filePaths,
|
|
6961
|
+
type: 'reload-server'
|
|
7002
6962
|
}
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
6963
|
+
], null == (_config_performance = config.performance) ? void 0 : _config_performance.buildCache))) {
|
|
6964
|
+
let { buildCache } = config.performance;
|
|
6965
|
+
!0 === buildCache ? config.performance.buildCache = {
|
|
6966
|
+
buildDependencies: envs.filePaths
|
|
6967
|
+
} : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
|
|
6968
|
+
}
|
|
6969
|
+
}(config, envs);
|
|
6970
|
+
let resolvedOptions = {
|
|
6971
|
+
cwd: process.cwd(),
|
|
6972
|
+
callerName: 'rsbuild',
|
|
6973
|
+
...options,
|
|
6974
|
+
rsbuildConfig: config
|
|
6975
|
+
}, pluginManager1 = (plugins = [], {
|
|
6976
|
+
getPlugins: (options = {})=>plugins.filter((plugin)=>isEnvironmentMatch(plugin.environment, options.environment)).map(({ instance })=>instance),
|
|
6977
|
+
getAllPluginsWithMeta: ()=>plugins,
|
|
6978
|
+
addPlugins: (newPlugins, options)=>{
|
|
6979
|
+
let { before, environment } = options || {};
|
|
6980
|
+
for (let newPlugin of newPlugins)if (newPlugin) {
|
|
6981
|
+
var plugin = newPlugin;
|
|
6982
|
+
let type = typeof plugin;
|
|
6983
|
+
if ('object' !== type || null === plugin) throw Error(`${picocolors_index_js_default().dim('[rsbuild:plugin]')} Expect Rsbuild plugin instance to be an object, but got ${picocolors_index_js_default().yellow(type)}.`);
|
|
6984
|
+
if (!isFunction(plugin.setup)) {
|
|
6985
|
+
if (isFunction(plugin.apply)) {
|
|
6986
|
+
let { name = 'SomeWebpackPlugin' } = plugin.constructor || {};
|
|
6987
|
+
throw Error([
|
|
6988
|
+
`${picocolors_index_js_default().yellow(name)} looks like a webpack or Rspack plugin, please use ${picocolors_index_js_default().yellow('`tools.rspack`')} to register it:`,
|
|
6989
|
+
picocolors_index_js_default().green(`
|
|
6990
|
+
// rsbuild.config.ts
|
|
6991
|
+
export default {
|
|
6992
|
+
tools: {
|
|
6993
|
+
rspack: {
|
|
6994
|
+
plugins: [new ${name}()]
|
|
6995
|
+
}
|
|
6996
|
+
}
|
|
6997
|
+
};
|
|
6998
|
+
`)
|
|
6999
|
+
].join('\n'));
|
|
7017
7000
|
}
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
let { config } = environment, { bundlerType } = api.context, buildCache = config.performance.buildCache ?? 'webpack' === bundlerType;
|
|
7029
|
-
if (!1 === buildCache) return;
|
|
7030
|
-
cacheEnabled = !0;
|
|
7031
|
-
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = function({ cacheDirectory }, context) {
|
|
7032
|
-
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);
|
|
7033
|
-
}(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment, cacheConfig.buildDependencies ? {
|
|
7034
|
-
userBuildDependencies: cacheConfig.buildDependencies
|
|
7035
|
-
} : {});
|
|
7036
|
-
'webpack' === bundlerType && await validateWebpackCache(cacheDirectory, buildDependencies);
|
|
7037
|
-
let cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${await helpers_hash(JSON.stringify(cacheConfig.cacheDigest))}` : `${environment.name}-${env}`;
|
|
7038
|
-
'rspack' === bundlerType ? (chain.cache(!0), chain.experiments({
|
|
7039
|
-
...chain.get('experiments'),
|
|
7040
|
-
cache: {
|
|
7041
|
-
type: 'persistent',
|
|
7042
|
-
version: cacheVersion,
|
|
7043
|
-
storage: {
|
|
7044
|
-
type: 'filesystem',
|
|
7045
|
-
directory: cacheDirectory
|
|
7046
|
-
},
|
|
7047
|
-
buildDependencies: Object.values(buildDependencies).flat()
|
|
7048
|
-
}
|
|
7049
|
-
})) : chain.cache({
|
|
7050
|
-
name: cacheVersion,
|
|
7051
|
-
type: 'filesystem',
|
|
7052
|
-
cacheDirectory,
|
|
7053
|
-
buildDependencies
|
|
7001
|
+
throw Error(`${picocolors_index_js_default().dim('[rsbuild:plugin]')} Expect the setup function of Rsbuild plugin to be a function, but got ${picocolors_index_js_default().yellow(type)}.`);
|
|
7002
|
+
}
|
|
7003
|
+
if (before) {
|
|
7004
|
+
let index = plugins.findIndex((item)=>item.instance.name === before);
|
|
7005
|
+
-1 === index ? (index_js_namespaceObject.logger.warn(`Plugin "${before}" does not exist.`), plugins.push({
|
|
7006
|
+
environment,
|
|
7007
|
+
instance: newPlugin
|
|
7008
|
+
})) : plugins.splice(index, 0, {
|
|
7009
|
+
environment,
|
|
7010
|
+
instance: newPlugin
|
|
7054
7011
|
});
|
|
7055
|
-
}
|
|
7056
|
-
|
|
7012
|
+
} else plugins.push({
|
|
7013
|
+
environment,
|
|
7014
|
+
instance: newPlugin
|
|
7057
7015
|
});
|
|
7058
7016
|
}
|
|
7059
7017
|
},
|
|
7060
|
-
{
|
|
7061
|
-
name
|
|
7062
|
-
setup (api) {
|
|
7063
|
-
api.modifyBundlerChain({
|
|
7064
|
-
order: 'pre',
|
|
7065
|
-
handler: async (chain, { target, environment })=>{
|
|
7066
|
-
if ('node' === target) return void chain.target('node');
|
|
7067
|
-
let { browserslist } = environment, isDefaultBrowserslist = browserslist.join(',') === DEFAULT_WEB_BROWSERSLIST.join(',');
|
|
7068
|
-
if ('web-worker' === target) return void chain.target(isDefaultBrowserslist ? [
|
|
7069
|
-
'webworker',
|
|
7070
|
-
'es2017'
|
|
7071
|
-
] : [
|
|
7072
|
-
'webworker',
|
|
7073
|
-
'es5'
|
|
7074
|
-
]);
|
|
7075
|
-
let esQuery = isDefaultBrowserslist ? 'es2017' : `browserslist:${browserslist.join(',')}`;
|
|
7076
|
-
chain.target([
|
|
7077
|
-
'web',
|
|
7078
|
-
esQuery
|
|
7079
|
-
]);
|
|
7080
|
-
}
|
|
7081
|
-
});
|
|
7082
|
-
}
|
|
7018
|
+
removePlugins: (pluginNames, options = {})=>{
|
|
7019
|
+
plugins = plugins.filter((plugin)=>!(pluginNames.includes(plugin.instance.name) && (!options.environment || plugin.environment === options.environment)));
|
|
7083
7020
|
},
|
|
7084
|
-
{
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7021
|
+
isPluginExists: (pluginName, options = {})=>plugins.some((plugin)=>plugin.instance.name === pluginName && isEnvironmentMatch(plugin.environment, options.environment))
|
|
7022
|
+
}), context2 = await createContext(resolvedOptions, config), getPluginAPI = function({ context, pluginManager }) {
|
|
7023
|
+
let { hooks } = context, publicContext = function(context) {
|
|
7024
|
+
let exposedKeys = [
|
|
7025
|
+
'action',
|
|
7026
|
+
'version',
|
|
7027
|
+
'rootPath',
|
|
7028
|
+
'distPath',
|
|
7029
|
+
'devServer',
|
|
7030
|
+
'cachePath',
|
|
7031
|
+
'callerName',
|
|
7032
|
+
'bundlerType'
|
|
7033
|
+
];
|
|
7034
|
+
return new Proxy(context, {
|
|
7035
|
+
get (target, prop) {
|
|
7036
|
+
if (exposedKeys.includes(prop)) return target[prop];
|
|
7037
|
+
},
|
|
7038
|
+
set: (_, prop)=>(index_js_namespaceObject.logger.error(`Context is readonly, you can not assign to the "context.${prop}" prop.`), !0)
|
|
7039
|
+
});
|
|
7040
|
+
}(context);
|
|
7041
|
+
function getNormalizedConfig(options) {
|
|
7042
|
+
if (context.normalizedConfig) {
|
|
7043
|
+
if (null == options ? void 0 : options.environment) {
|
|
7044
|
+
let config = context.normalizedConfig.environments[options.environment];
|
|
7045
|
+
if (!config) throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} Cannot find normalized config by environment: ${options.environment}.`);
|
|
7046
|
+
return config;
|
|
7047
|
+
}
|
|
7048
|
+
return context.normalizedConfig;
|
|
7049
|
+
}
|
|
7050
|
+
throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} Cannot access normalized config until ${picocolors_index_js_default().yellow('modifyRsbuildConfig')} is called.`);
|
|
7051
|
+
}
|
|
7052
|
+
let getRsbuildConfig = (type = 'current')=>{
|
|
7053
|
+
switch(type){
|
|
7054
|
+
case 'original':
|
|
7055
|
+
return context.originalConfig;
|
|
7056
|
+
case 'current':
|
|
7057
|
+
return context.config;
|
|
7058
|
+
case 'normalized':
|
|
7059
|
+
return getNormalizedConfig();
|
|
7060
|
+
}
|
|
7061
|
+
throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} ${picocolors_index_js_default().yellow('getRsbuildConfig')} get an invalid type param.`);
|
|
7062
|
+
}, exposed = [], expose = (id, api)=>{
|
|
7063
|
+
exposed.push({
|
|
7064
|
+
id,
|
|
7065
|
+
api
|
|
7066
|
+
});
|
|
7067
|
+
}, useExposed = (id)=>{
|
|
7068
|
+
let matched = exposed.find((item)=>item.id === id);
|
|
7069
|
+
if (matched) return matched.api;
|
|
7070
|
+
}, transformId = 0, transformer = {}, processAssetsFns = [], resolveFns = [];
|
|
7071
|
+
hooks.modifyBundlerChain.tap((chain, { target, environment })=>{
|
|
7072
|
+
let pluginName = 'RsbuildCorePlugin';
|
|
7073
|
+
chain.plugin(pluginName).use(class {
|
|
7074
|
+
apply(compiler) {
|
|
7075
|
+
for (let { handler, environment: pluginEnvironment } of (compiler.__rsbuildTransformer = transformer, resolveFns))(!pluginEnvironment || isEnvironmentMatch(pluginEnvironment, environment.name)) && compiler.hooks.compilation.tap(pluginName, (compilation, { normalModuleFactory })=>{
|
|
7076
|
+
normalModuleFactory.hooks.resolve.tapPromise(pluginName, async (resolveData)=>handler({
|
|
7077
|
+
compiler,
|
|
7078
|
+
compilation,
|
|
7079
|
+
environment,
|
|
7080
|
+
resolveData
|
|
7081
|
+
}));
|
|
7082
|
+
});
|
|
7083
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation)=>{
|
|
7084
|
+
compilation.hooks.childCompiler.tap(pluginName, (childCompiler)=>{
|
|
7085
|
+
childCompiler.__rsbuildTransformer = transformer;
|
|
7086
|
+
});
|
|
7087
|
+
let { sources } = compiler.webpack;
|
|
7088
|
+
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({
|
|
7089
|
+
name: pluginName,
|
|
7090
|
+
stage: mapProcessAssetsStage(compiler, descriptor.stage)
|
|
7091
|
+
}, async (assets)=>handler({
|
|
7092
|
+
assets,
|
|
7093
|
+
compiler,
|
|
7094
|
+
compilation,
|
|
7095
|
+
environment,
|
|
7096
|
+
sources
|
|
7097
|
+
}));
|
|
7098
|
+
});
|
|
7099
|
+
}
|
|
7100
|
+
constructor(){
|
|
7101
|
+
!function(obj, key, value) {
|
|
7102
|
+
key in obj ? Object.defineProperty(obj, key, {
|
|
7103
|
+
value: value,
|
|
7104
|
+
enumerable: !0,
|
|
7105
|
+
configurable: !0,
|
|
7106
|
+
writable: !0
|
|
7107
|
+
}) : obj[key] = value;
|
|
7108
|
+
}(this, "name", pluginName);
|
|
7109
|
+
}
|
|
7110
|
+
});
|
|
7111
|
+
});
|
|
7112
|
+
let onExitListened = !1, onExit = (cb)=>{
|
|
7113
|
+
if (!onExitListened) {
|
|
7114
|
+
var onExit;
|
|
7115
|
+
onExit = (exitCode)=>{
|
|
7116
|
+
hooks.onExit.callBatch({
|
|
7117
|
+
exitCode
|
|
7118
|
+
});
|
|
7119
|
+
}, exitHook_callbacks.add(onExit), isRegistered || (isRegistered = !0, external_node_process_default().on('SIGINT', ()=>{
|
|
7120
|
+
exit(external_node_os_namespaceObject.constants.signals.SIGINT + 128, 'SIGINT');
|
|
7121
|
+
}), external_node_process_default().once('SIGTERM', ()=>{
|
|
7122
|
+
exit(external_node_os_namespaceObject.constants.signals.SIGTERM + 128, 'SIGTERM');
|
|
7123
|
+
}), external_node_process_default().once('exit', (exitCode)=>{
|
|
7124
|
+
exit(exitCode, 'exit');
|
|
7125
|
+
})), onExitListened = !0;
|
|
7126
|
+
}
|
|
7127
|
+
hooks.onExit.tap(cb);
|
|
7128
|
+
};
|
|
7129
|
+
return (environment)=>{
|
|
7130
|
+
let environment1, environment2, environment3;
|
|
7131
|
+
return {
|
|
7132
|
+
context: publicContext,
|
|
7133
|
+
expose,
|
|
7134
|
+
logger: index_js_namespaceObject.logger,
|
|
7135
|
+
transform: (environment1 = environment, (descriptor, handler)=>{
|
|
7136
|
+
let id = `rsbuild-transform-${transformId++}`;
|
|
7137
|
+
transformer[id] = handler, hooks.modifyBundlerChain.tapEnvironment({
|
|
7138
|
+
environment: environment1,
|
|
7139
|
+
handler: (chain, { target, environment })=>{
|
|
7140
|
+
if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environment.name)) return;
|
|
7141
|
+
let rule = chain.module.rule(id);
|
|
7142
|
+
descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer), descriptor.issuer && rule.issuer(descriptor.issuer), descriptor.with && rule.with(descriptor.with), descriptor.mimetype && rule.mimetype(descriptor.mimetype), descriptor.order && 'default' !== descriptor.order ? rule.enforce(descriptor.order) : descriptor.enforce && rule.enforce(descriptor.enforce);
|
|
7143
|
+
let loaderName = descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs', loaderPath = (0, external_node_path_namespaceObject.join)(LOADER_PATH, loaderName);
|
|
7144
|
+
rule.use(id).loader(loaderPath).options({
|
|
7145
|
+
id,
|
|
7146
|
+
getEnvironment: ()=>environment
|
|
7147
|
+
});
|
|
7148
|
+
}
|
|
7149
|
+
});
|
|
7150
|
+
}),
|
|
7151
|
+
useExposed,
|
|
7152
|
+
processAssets: (environment2 = environment, (descriptor, handler)=>{
|
|
7153
|
+
processAssetsFns.push({
|
|
7154
|
+
environment: environment2,
|
|
7155
|
+
descriptor,
|
|
7156
|
+
handler
|
|
7157
|
+
});
|
|
7158
|
+
}),
|
|
7159
|
+
resolve: (environment3 = environment, (handler)=>{
|
|
7160
|
+
resolveFns.push({
|
|
7161
|
+
environment: environment3,
|
|
7162
|
+
handler
|
|
7163
|
+
});
|
|
7164
|
+
}),
|
|
7165
|
+
getRsbuildConfig,
|
|
7166
|
+
getNormalizedConfig,
|
|
7167
|
+
isPluginExists: pluginManager.isPluginExists,
|
|
7168
|
+
onExit,
|
|
7169
|
+
onAfterBuild: hooks.onAfterBuild.tap,
|
|
7170
|
+
onCloseBuild: hooks.onCloseBuild.tap,
|
|
7171
|
+
onBeforeBuild: hooks.onBeforeBuild.tap,
|
|
7172
|
+
onCloseDevServer: hooks.onCloseDevServer.tap,
|
|
7173
|
+
onDevCompileDone: hooks.onDevCompileDone.tap,
|
|
7174
|
+
onAfterCreateCompiler: hooks.onAfterCreateCompiler.tap,
|
|
7175
|
+
onAfterStartDevServer: hooks.onAfterStartDevServer.tap,
|
|
7176
|
+
onBeforeCreateCompiler: hooks.onBeforeCreateCompiler.tap,
|
|
7177
|
+
onBeforeStartDevServer: hooks.onBeforeStartDevServer.tap,
|
|
7178
|
+
onAfterStartProdServer: hooks.onAfterStartProdServer.tap,
|
|
7179
|
+
onBeforeStartProdServer: hooks.onBeforeStartProdServer.tap,
|
|
7180
|
+
modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap,
|
|
7181
|
+
modifyHTML: (handler)=>{
|
|
7182
|
+
hooks.modifyHTML.tapEnvironment({
|
|
7183
|
+
environment,
|
|
7184
|
+
handler
|
|
7185
|
+
});
|
|
7186
|
+
},
|
|
7187
|
+
modifyHTMLTags: (handler)=>{
|
|
7188
|
+
hooks.modifyHTMLTags.tapEnvironment({
|
|
7189
|
+
environment,
|
|
7190
|
+
handler
|
|
7191
|
+
});
|
|
7192
|
+
},
|
|
7193
|
+
modifyBundlerChain: (handler)=>{
|
|
7194
|
+
hooks.modifyBundlerChain.tapEnvironment({
|
|
7195
|
+
environment,
|
|
7196
|
+
handler
|
|
7197
|
+
});
|
|
7198
|
+
},
|
|
7199
|
+
modifyRspackConfig: (handler)=>{
|
|
7200
|
+
hooks.modifyRspackConfig.tapEnvironment({
|
|
7201
|
+
environment,
|
|
7202
|
+
handler
|
|
7203
|
+
});
|
|
7204
|
+
},
|
|
7205
|
+
modifyWebpackChain: (handler)=>{
|
|
7206
|
+
hooks.modifyWebpackChain.tapEnvironment({
|
|
7207
|
+
environment,
|
|
7208
|
+
handler
|
|
7209
|
+
});
|
|
7210
|
+
},
|
|
7211
|
+
modifyWebpackConfig: (handler)=>{
|
|
7212
|
+
hooks.modifyWebpackConfig.tapEnvironment({
|
|
7213
|
+
environment,
|
|
7214
|
+
handler
|
|
7215
|
+
});
|
|
7216
|
+
},
|
|
7217
|
+
modifyEnvironmentConfig: (handler)=>{
|
|
7218
|
+
hooks.modifyEnvironmentConfig.tapEnvironment({
|
|
7219
|
+
environment,
|
|
7220
|
+
handler
|
|
7221
|
+
});
|
|
7222
|
+
},
|
|
7223
|
+
onAfterEnvironmentCompile: (handler)=>{
|
|
7224
|
+
hooks.onAfterEnvironmentCompile.tapEnvironment({
|
|
7225
|
+
environment,
|
|
7226
|
+
handler
|
|
7227
|
+
});
|
|
7228
|
+
},
|
|
7229
|
+
onBeforeEnvironmentCompile: (handler)=>{
|
|
7230
|
+
hooks.onBeforeEnvironmentCompile.tapEnvironment({
|
|
7231
|
+
environment,
|
|
7232
|
+
handler
|
|
7233
|
+
});
|
|
7234
|
+
}
|
|
7235
|
+
};
|
|
7236
|
+
};
|
|
7237
|
+
}({
|
|
7238
|
+
context: context2,
|
|
7239
|
+
pluginManager: pluginManager1
|
|
7240
|
+
});
|
|
7241
|
+
context2.getPluginAPI = getPluginAPI;
|
|
7242
|
+
let globalPluginAPI = getPluginAPI();
|
|
7243
|
+
index_js_namespaceObject.logger.debug('add default plugins'), pluginManager = pluginManager1, context = context2, pluginManager.addPlugins([
|
|
7244
|
+
{
|
|
7245
|
+
name: 'rsbuild:basic',
|
|
7246
|
+
setup (api) {
|
|
7247
|
+
api.modifyBundlerChain((chain, { isDev, target, bundler, environment, CHAIN_ID })=>{
|
|
7248
|
+
let { config } = environment;
|
|
7249
|
+
chain.name(environment.name);
|
|
7250
|
+
let devtool = ((config)=>{
|
|
7251
|
+
let { sourceMap } = config.output, isProd = 'production' === config.mode;
|
|
7252
|
+
return !1 !== sourceMap && (!0 === sourceMap ? isProd ? 'source-map' : 'cheap-module-source-map' : void 0 === sourceMap.js ? !isProd && 'cheap-module-source-map' : sourceMap.js);
|
|
7253
|
+
})(config);
|
|
7254
|
+
chain.devtool(devtool);
|
|
7255
|
+
let { sourceMap } = config.output;
|
|
7256
|
+
!devtool && 'object' == typeof sourceMap && sourceMap.css && chain.plugin('source-map-css').use(bundler.SourceMapDevToolPlugin, [
|
|
7257
|
+
{
|
|
7258
|
+
test: /\.css$/,
|
|
7259
|
+
filename: '[file].map[query]'
|
|
7260
|
+
}
|
|
7261
|
+
]), chain.context(api.context.rootPath), chain.mode(environment.config.mode), chain.infrastructureLogging({
|
|
7262
|
+
level: 'error'
|
|
7263
|
+
}), chain.watchOptions({
|
|
7264
|
+
aggregateTimeout: 0
|
|
7265
|
+
}), chain.performance.hints(!1), chain.module.parser.merge({
|
|
7266
|
+
javascript: {
|
|
7267
|
+
exportsPresence: 'error',
|
|
7268
|
+
typeReexportsPresence: 'tolerant'
|
|
7269
|
+
}
|
|
7270
|
+
}), isDev && config.dev.hmr && 'web' === target && chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin), isDev && chain.output.devtoolModuleFilenameTemplate((info)=>toPosixPath(info.absoluteResourcePath)), 'rspack' === api.context.bundlerType && chain.experiments({
|
|
7271
|
+
...chain.get('experiments'),
|
|
7272
|
+
typeReexportsPresence: !0,
|
|
7273
|
+
rspackFuture: {
|
|
7274
|
+
bundlerInfo: {
|
|
7275
|
+
force: !1
|
|
7276
|
+
}
|
|
7277
|
+
}
|
|
7278
|
+
}), process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-silent';
|
|
7279
|
+
});
|
|
7280
|
+
}
|
|
7281
|
+
},
|
|
7282
|
+
{
|
|
7283
|
+
name: 'rsbuild:entry',
|
|
7284
|
+
setup (api) {
|
|
7285
|
+
api.modifyBundlerChain((chain, { environment, isServer })=>{
|
|
7286
|
+
let { config, entry } = environment, { preEntry } = config.source, injectCoreJsEntry = 'entry' === config.output.polyfill && !isServer;
|
|
7287
|
+
for (let entryName of Object.keys(entry)){
|
|
7288
|
+
let entryPoint = chain.entry(entryName), addEntry = (item)=>{
|
|
7289
|
+
if ('object' == typeof item && 'html' in item) {
|
|
7290
|
+
let { html: _html, ...rest } = item;
|
|
7291
|
+
entryPoint.add(rest);
|
|
7292
|
+
} else entryPoint.add(item);
|
|
7293
|
+
};
|
|
7294
|
+
preEntry.forEach(addEntry), injectCoreJsEntry && addEntry(createVirtualModule('import "core-js";')), helpers_castArray(entry[entryName]).forEach(addEntry);
|
|
7295
|
+
}
|
|
7296
|
+
}), api.onBeforeCreateCompiler(({ bundlerConfigs })=>{
|
|
7297
|
+
if (bundlerConfigs.every((config)=>!config.entry)) throw Error(`${picocolors_index_js_default().dim('[rsbuild:config]')} Could not find any entry module, please make sure that ${picocolors_index_js_default().yellow('src/index.(ts|js|tsx|jsx|mts|cts|mjs|cjs)')} exists, or customize entry through the ${picocolors_index_js_default().yellow('source.entry')} configuration.`);
|
|
7298
|
+
});
|
|
7299
|
+
}
|
|
7300
|
+
},
|
|
7301
|
+
{
|
|
7302
|
+
name: 'rsbuild:cache',
|
|
7303
|
+
setup (api) {
|
|
7304
|
+
let cacheEnabled = !1;
|
|
7305
|
+
api.modifyBundlerChain(async (chain, { environment, env })=>{
|
|
7306
|
+
let { config } = environment, { bundlerType } = api.context, buildCache = config.performance.buildCache ?? 'webpack' === bundlerType;
|
|
7307
|
+
if (!1 === buildCache) return;
|
|
7308
|
+
cacheEnabled = !0;
|
|
7309
|
+
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = function({ cacheDirectory }, context) {
|
|
7310
|
+
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);
|
|
7311
|
+
}(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment, cacheConfig.buildDependencies ? {
|
|
7312
|
+
userBuildDependencies: cacheConfig.buildDependencies
|
|
7313
|
+
} : {});
|
|
7314
|
+
'webpack' === bundlerType && await validateWebpackCache(cacheDirectory, buildDependencies);
|
|
7315
|
+
let cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${await helpers_hash(JSON.stringify(cacheConfig.cacheDigest))}` : `${environment.name}-${env}`;
|
|
7316
|
+
'rspack' === bundlerType ? (chain.cache(!0), chain.experiments({
|
|
7317
|
+
...chain.get('experiments'),
|
|
7318
|
+
cache: {
|
|
7319
|
+
type: 'persistent',
|
|
7320
|
+
version: cacheVersion,
|
|
7321
|
+
storage: {
|
|
7322
|
+
type: 'filesystem',
|
|
7323
|
+
directory: cacheDirectory
|
|
7324
|
+
},
|
|
7325
|
+
buildDependencies: Object.values(buildDependencies).flat()
|
|
7326
|
+
}
|
|
7327
|
+
})) : chain.cache({
|
|
7328
|
+
name: cacheVersion,
|
|
7329
|
+
type: 'filesystem',
|
|
7330
|
+
cacheDirectory,
|
|
7331
|
+
buildDependencies
|
|
7332
|
+
});
|
|
7333
|
+
}), api.onAfterCreateCompiler(()=>{
|
|
7334
|
+
cacheEnabled && 'rspack' === api.context.bundlerType && index_js_namespaceObject.logger.debug('Rspack persistent cache enabled');
|
|
7335
|
+
});
|
|
7336
|
+
}
|
|
7337
|
+
},
|
|
7338
|
+
{
|
|
7339
|
+
name: 'rsbuild:target',
|
|
7340
|
+
setup (api) {
|
|
7341
|
+
api.modifyBundlerChain({
|
|
7342
|
+
order: 'pre',
|
|
7343
|
+
handler: (chain, { target, environment })=>{
|
|
7344
|
+
if ('node' === target) return void chain.target('node');
|
|
7345
|
+
let { browserslist } = environment, isDefaultBrowserslist = browserslist.join(',') === DEFAULT_WEB_BROWSERSLIST.join(',');
|
|
7346
|
+
if ('web-worker' === target) return void chain.target(isDefaultBrowserslist ? [
|
|
7347
|
+
'webworker',
|
|
7348
|
+
'es2017'
|
|
7349
|
+
] : [
|
|
7350
|
+
'webworker',
|
|
7351
|
+
'es5'
|
|
7352
|
+
]);
|
|
7353
|
+
let esQuery = isDefaultBrowserslist ? 'es2017' : `browserslist:${browserslist.join(',')}`;
|
|
7354
|
+
chain.target([
|
|
7355
|
+
'web',
|
|
7356
|
+
esQuery
|
|
7357
|
+
]);
|
|
7358
|
+
}
|
|
7359
|
+
});
|
|
7360
|
+
}
|
|
7361
|
+
},
|
|
7362
|
+
{
|
|
7363
|
+
name: 'rsbuild:output',
|
|
7364
|
+
setup (api) {
|
|
7365
|
+
api.modifyBundlerChain((chain, { CHAIN_ID, isDev, isProd, isServer, environment, rspack })=>{
|
|
7366
|
+
var jsPath, isServer1, jsAsync;
|
|
7367
|
+
let { distPath, config } = environment, publicPath = function({ isDev, config, context }) {
|
|
7368
|
+
var _context_devServer, _context_devServer1, _context_devServer2;
|
|
7369
|
+
let { dev, output, server } = config, publicPath = DEFAULT_ASSET_PREFIX;
|
|
7370
|
+
if (isDev) {
|
|
7371
|
+
if ('string' == typeof dev.assetPrefix) publicPath = dev.assetPrefix;
|
|
7372
|
+
else if (dev.assetPrefix) {
|
|
7373
|
+
let protocol = (null == (_context_devServer1 = context.devServer) ? void 0 : _context_devServer1.https) ? 'https' : 'http', hostname = (null == (_context_devServer2 = context.devServer) ? void 0 : _context_devServer2.hostname) || DEFAULT_DEV_HOST;
|
|
7374
|
+
publicPath = hostname === DEFAULT_DEV_HOST ? `${protocol}://localhost:<port>/` : `${protocol}://${hostname}:<port>/`, server.base && '/' !== server.base && (publicPath = urlJoin(publicPath, server.base));
|
|
7375
|
+
}
|
|
7376
|
+
} else 'string' == typeof output.assetPrefix && (publicPath = output.assetPrefix);
|
|
7377
|
+
let defaultPort = server.port ?? 3000;
|
|
7378
|
+
return formatPublicPath(replacePortPlaceholder(publicPath, isDev ? (null == (_context_devServer = context.devServer) ? void 0 : _context_devServer.port) ?? defaultPort : defaultPort));
|
|
7379
|
+
}({
|
|
7380
|
+
config,
|
|
7381
|
+
isDev,
|
|
7104
7382
|
context: api.context
|
|
7105
7383
|
}), jsPath1 = config.output.distPath.js, jsAsyncPath = (jsPath = jsPath1, isServer1 = isServer, void 0 !== (jsAsync = config.output.distPath.jsAsync) ? jsAsync : isServer1 ? jsPath : jsPath ? `${jsPath}/async` : 'async'), jsFilename = getFilename(config, 'js', isProd, isServer), isJsFilenameFn = 'function' == typeof jsFilename;
|
|
7106
7384
|
if (chain.output.path(distPath).filename(isJsFilenameFn ? (...args)=>{
|
|
@@ -7549,7 +7827,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
7549
7827
|
{
|
|
7550
7828
|
name: 'rsbuild:wasm',
|
|
7551
7829
|
setup (api) {
|
|
7552
|
-
api.modifyBundlerChain(
|
|
7830
|
+
api.modifyBundlerChain((chain, { CHAIN_ID, environment, isProd })=>{
|
|
7553
7831
|
let { config } = environment, distPath = config.output.distPath.wasm, filename = external_node_path_namespaceObject.posix.join(distPath, getFilename(config, 'wasm', isProd));
|
|
7554
7832
|
chain.experiments({
|
|
7555
7833
|
...chain.get('experiments'),
|
|
@@ -7563,7 +7841,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
7563
7841
|
{
|
|
7564
7842
|
name: 'rsbuild:moment',
|
|
7565
7843
|
setup (api) {
|
|
7566
|
-
api.modifyBundlerChain(
|
|
7844
|
+
api.modifyBundlerChain((chain, { environment, bundler })=>{
|
|
7567
7845
|
let { config } = environment;
|
|
7568
7846
|
config.performance.removeMomentLocale && chain.plugin('remove-moment-locale').use(bundler.IgnorePlugin, [
|
|
7569
7847
|
{
|
|
@@ -7759,7 +8037,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7759
8037
|
name: 'rsbuild:minimize',
|
|
7760
8038
|
setup (api) {
|
|
7761
8039
|
let isRspack = 'rspack' === api.context.bundlerType;
|
|
7762
|
-
api.modifyBundlerChain(
|
|
8040
|
+
api.modifyBundlerChain((chain, { environment, CHAIN_ID, rspack })=>{
|
|
7763
8041
|
let { config } = environment, { minifyJs, minifyCss, jsOptions, cssOptions } = parseMinifyOptions(config);
|
|
7764
8042
|
if (chain.optimization.minimize(minifyJs || minifyCss), minifyJs && isRspack && chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).use(rspack.SwcJsMinimizerRspackPlugin, [
|
|
7765
8043
|
((config, jsOptions)=>{
|
|
@@ -7812,7 +8090,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7812
8090
|
{
|
|
7813
8091
|
name: 'rsbuild:progress',
|
|
7814
8092
|
setup (api) {
|
|
7815
|
-
'webpack' !== api.context.bundlerType && api.modifyBundlerChain(
|
|
8093
|
+
'webpack' !== api.context.bundlerType && api.modifyBundlerChain((chain, { CHAIN_ID, environment, rspack })=>{
|
|
7816
8094
|
let { config } = environment, options = config.dev.progressBar;
|
|
7817
8095
|
if (!options) return;
|
|
7818
8096
|
let prefix = !0 !== options && void 0 !== options.id ? options.id : environment.name;
|
|
@@ -7830,7 +8108,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7830
8108
|
setup (api) {
|
|
7831
8109
|
api.modifyBundlerChain({
|
|
7832
8110
|
order: 'pre',
|
|
7833
|
-
handler:
|
|
8111
|
+
handler: (chain, { CHAIN_ID, isDev, target, environment })=>{
|
|
7834
8112
|
var target1;
|
|
7835
8113
|
let { config, browserslist } = 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({
|
|
7836
8114
|
not: 'url'
|
|
@@ -7914,7 +8192,17 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7914
8192
|
if ('off' === polyfillMode) swcConfig.env.mode = void 0;
|
|
7915
8193
|
else {
|
|
7916
8194
|
swcConfig.env.mode = polyfillMode;
|
|
7917
|
-
let coreJsDir =
|
|
8195
|
+
let coreJsDir = function(swcConfig, polyfillMode) {
|
|
8196
|
+
let coreJsPath = swc_require.resolve('core-js/package.json'), version = ((corejsPkgPath)=>{
|
|
8197
|
+
try {
|
|
8198
|
+
let rawJson = external_node_fs_default().readFileSync(corejsPkgPath, 'utf-8'), { version } = JSON.parse(rawJson), [major, minor] = version.split('.');
|
|
8199
|
+
return `${major}.${minor}`;
|
|
8200
|
+
} catch {
|
|
8201
|
+
return '3';
|
|
8202
|
+
}
|
|
8203
|
+
})(coreJsPath), coreJsDir = external_node_path_default().dirname(coreJsPath);
|
|
8204
|
+
return swcConfig.env.coreJs = version, 'usage' === polyfillMode && (swcConfig.env.shippedProposals = !0), coreJsDir;
|
|
8205
|
+
}(swcConfig, polyfillMode);
|
|
7918
8206
|
for (let item of [
|
|
7919
8207
|
rule,
|
|
7920
8208
|
dataUriRule
|
|
@@ -8117,7 +8405,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8117
8405
|
headTags,
|
|
8118
8406
|
bodyTags
|
|
8119
8407
|
};
|
|
8120
|
-
}), api.modifyBundlerChain(
|
|
8408
|
+
}), api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
8121
8409
|
let { config, htmlPaths } = environment;
|
|
8122
8410
|
if (0 === Object.keys(htmlPaths).length) return;
|
|
8123
8411
|
let { performance: { preload, prefetch } } = config, HTMLCount = chain.entryPoints.values().length, excludes = ((config)=>{
|
|
@@ -8204,7 +8492,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8204
8492
|
{
|
|
8205
8493
|
name: 'rsbuild:server',
|
|
8206
8494
|
setup (api) {
|
|
8207
|
-
let onStartServer =
|
|
8495
|
+
let onStartServer = ({ port, routes })=>{
|
|
8208
8496
|
let config = api.getNormalizedConfig();
|
|
8209
8497
|
if (config.server.open) {
|
|
8210
8498
|
var _api_context_devServer;
|
|
@@ -8338,7 +8626,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8338
8626
|
...config.source.include || [],
|
|
8339
8627
|
/@module-federation[\\/]/
|
|
8340
8628
|
]);
|
|
8341
|
-
}), api.modifyBundlerChain(
|
|
8629
|
+
}), api.modifyBundlerChain((chain, { CHAIN_ID, target, environment })=>{
|
|
8342
8630
|
var _config_moduleFederation;
|
|
8343
8631
|
let { config } = environment;
|
|
8344
8632
|
if (!(null == (_config_moduleFederation = config.moduleFederation) ? void 0 : _config_moduleFederation.options) || 'web' !== target) return;
|
|
@@ -8353,7 +8641,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8353
8641
|
},
|
|
8354
8642
|
{
|
|
8355
8643
|
name: 'rsbuild:rspack-profile',
|
|
8356
|
-
|
|
8644
|
+
setup (api) {
|
|
8357
8645
|
let traceOutput;
|
|
8358
8646
|
if ('webpack' === api.context.bundlerType) return;
|
|
8359
8647
|
let { RSPACK_PROFILE } = process.env;
|
|
@@ -8412,363 +8700,66 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8412
8700
|
(!1 === crossorigin || void 0 === crossorigin) && chain.output.crossOriginLoading('anonymous');
|
|
8413
8701
|
let { algorithm = 'sha384' } = sri;
|
|
8414
8702
|
chain.plugin(CHAIN_ID.PLUGIN.SUBRESOURCE_INTEGRITY).use(rspack.experiments.SubresourceIntegrityPlugin, [
|
|
8415
|
-
{
|
|
8416
|
-
enabled: !0,
|
|
8417
|
-
hashFuncNames: [
|
|
8418
|
-
algorithm
|
|
8419
|
-
],
|
|
8420
|
-
htmlPlugin: external_node_path_default().join(COMPILED_PATH, 'html-rspack-plugin/index.js')
|
|
8421
|
-
}
|
|
8422
|
-
]);
|
|
8423
|
-
});
|
|
8424
|
-
}
|
|
8425
|
-
},
|
|
8426
|
-
{
|
|
8427
|
-
name: 'rsbuild:nonce',
|
|
8428
|
-
setup (api) {
|
|
8429
|
-
api.onAfterCreateCompiler(({ compiler, environments })=>{
|
|
8430
|
-
let nonces = Object.values(environments).map((environment)=>{
|
|
8431
|
-
let { nonce } = environment.config.security;
|
|
8432
|
-
return nonce;
|
|
8433
|
-
});
|
|
8434
|
-
if (!nonces.some((nonce)=>!!nonce)) return;
|
|
8435
|
-
let environmentList = Object.values(environments);
|
|
8436
|
-
applyToCompiler(compiler, (compiler, index)=>{
|
|
8437
|
-
let nonce = nonces[index], environment = environmentList.find((item)=>item.index === index);
|
|
8438
|
-
if (!Object.keys((null == environment ? void 0 : environment.htmlPaths) ?? {}).length || !nonce) return;
|
|
8439
|
-
let injectCode = createVirtualModule(`__webpack_nonce__ = "${nonce}";`);
|
|
8440
|
-
new compiler.webpack.EntryPlugin(compiler.context, injectCode, {
|
|
8441
|
-
name: void 0
|
|
8442
|
-
}).apply(compiler);
|
|
8443
|
-
});
|
|
8444
|
-
}), api.modifyHTMLTags({
|
|
8445
|
-
order: 'post',
|
|
8446
|
-
handler: ({ headTags, bodyTags }, { environment })=>{
|
|
8447
|
-
let { config } = environment, { nonce } = config.security, allTags = [
|
|
8448
|
-
...headTags,
|
|
8449
|
-
...bodyTags
|
|
8450
|
-
];
|
|
8451
|
-
if (nonce) for (let tag of allTags){
|
|
8452
|
-
var _tag_attrs, _tag_attrs1;
|
|
8453
|
-
("script" === tag.tag || 'style' === tag.tag || 'link' === tag.tag && (null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.rel) === 'preload' && (null == (_tag_attrs1 = tag.attrs) ? void 0 : _tag_attrs1.as) === "script") && (tag.attrs ??= {}, tag.attrs.nonce = nonce);
|
|
8454
|
-
}
|
|
8455
|
-
return {
|
|
8456
|
-
headTags,
|
|
8457
|
-
bodyTags
|
|
8458
|
-
};
|
|
8459
|
-
}
|
|
8460
|
-
});
|
|
8461
|
-
}
|
|
8462
|
-
}
|
|
8463
|
-
]);
|
|
8464
|
-
}
|
|
8465
|
-
async function createRsbuild(options = {}) {
|
|
8466
|
-
let plugins, envs = options.loadEnv ? loadEnv({
|
|
8467
|
-
cwd: options.cwd,
|
|
8468
|
-
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
8469
|
-
}) : null, config = isFunction(options.rsbuildConfig) ? await options.rsbuildConfig() : options.rsbuildConfig || {};
|
|
8470
|
-
config.logLevel && (index_js_namespaceObject.logger.level = config.logLevel), function(config, envs) {
|
|
8471
|
-
var _config_performance;
|
|
8472
|
-
if (null !== envs && (config.source ||= {}, config.source.define = {
|
|
8473
|
-
...envs.publicVars,
|
|
8474
|
-
...config.source.define
|
|
8475
|
-
}, 0 !== envs.filePaths.length && (config.dev ||= {}, config.dev.watchFiles = [
|
|
8476
|
-
...config.dev.watchFiles ? helpers_castArray(config.dev.watchFiles) : [],
|
|
8477
|
-
{
|
|
8478
|
-
paths: envs.filePaths,
|
|
8479
|
-
type: 'reload-server'
|
|
8480
|
-
}
|
|
8481
|
-
], null == (_config_performance = config.performance) ? void 0 : _config_performance.buildCache))) {
|
|
8482
|
-
let { buildCache } = config.performance;
|
|
8483
|
-
!0 === buildCache ? config.performance.buildCache = {
|
|
8484
|
-
buildDependencies: envs.filePaths
|
|
8485
|
-
} : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
|
|
8486
|
-
}
|
|
8487
|
-
}(config, envs);
|
|
8488
|
-
let resolvedOptions = {
|
|
8489
|
-
cwd: process.cwd(),
|
|
8490
|
-
callerName: 'rsbuild',
|
|
8491
|
-
...options,
|
|
8492
|
-
rsbuildConfig: config
|
|
8493
|
-
}, pluginManager = (plugins = [], {
|
|
8494
|
-
getPlugins: (options = {})=>plugins.filter((plugin)=>isEnvironmentMatch(plugin.environment, options.environment)).map(({ instance })=>instance),
|
|
8495
|
-
getAllPluginsWithMeta: ()=>plugins,
|
|
8496
|
-
addPlugins: (newPlugins, options)=>{
|
|
8497
|
-
let { before, environment } = options || {};
|
|
8498
|
-
for (let newPlugin of newPlugins)if (newPlugin) {
|
|
8499
|
-
var plugin = newPlugin;
|
|
8500
|
-
let type = typeof plugin;
|
|
8501
|
-
if ('object' !== type || null === plugin) throw Error(`${picocolors_index_js_default().dim('[rsbuild:plugin]')} Expect Rsbuild plugin instance to be an object, but got ${picocolors_index_js_default().yellow(type)}.`);
|
|
8502
|
-
if (!isFunction(plugin.setup)) {
|
|
8503
|
-
if (isFunction(plugin.apply)) {
|
|
8504
|
-
let { name = 'SomeWebpackPlugin' } = plugin.constructor || {};
|
|
8505
|
-
throw Error([
|
|
8506
|
-
`${picocolors_index_js_default().yellow(name)} looks like a webpack or Rspack plugin, please use ${picocolors_index_js_default().yellow('`tools.rspack`')} to register it:`,
|
|
8507
|
-
picocolors_index_js_default().green(`
|
|
8508
|
-
// rsbuild.config.ts
|
|
8509
|
-
export default {
|
|
8510
|
-
tools: {
|
|
8511
|
-
rspack: {
|
|
8512
|
-
plugins: [new ${name}()]
|
|
8513
|
-
}
|
|
8514
|
-
}
|
|
8515
|
-
};
|
|
8516
|
-
`)
|
|
8517
|
-
].join('\n'));
|
|
8518
|
-
}
|
|
8519
|
-
throw Error(`${picocolors_index_js_default().dim('[rsbuild:plugin]')} Expect the setup function of Rsbuild plugin to be a function, but got ${picocolors_index_js_default().yellow(type)}.`);
|
|
8520
|
-
}
|
|
8521
|
-
if (before) {
|
|
8522
|
-
let index = plugins.findIndex((item)=>item.instance.name === before);
|
|
8523
|
-
-1 === index ? (index_js_namespaceObject.logger.warn(`Plugin "${before}" does not exist.`), plugins.push({
|
|
8524
|
-
environment,
|
|
8525
|
-
instance: newPlugin
|
|
8526
|
-
})) : plugins.splice(index, 0, {
|
|
8527
|
-
environment,
|
|
8528
|
-
instance: newPlugin
|
|
8529
|
-
});
|
|
8530
|
-
} else plugins.push({
|
|
8531
|
-
environment,
|
|
8532
|
-
instance: newPlugin
|
|
8703
|
+
{
|
|
8704
|
+
enabled: !0,
|
|
8705
|
+
hashFuncNames: [
|
|
8706
|
+
algorithm
|
|
8707
|
+
],
|
|
8708
|
+
htmlPlugin: external_node_path_default().join(COMPILED_PATH, 'html-rspack-plugin/index.js')
|
|
8709
|
+
}
|
|
8710
|
+
]);
|
|
8533
8711
|
});
|
|
8534
8712
|
}
|
|
8535
8713
|
},
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
'action',
|
|
8544
|
-
'version',
|
|
8545
|
-
'rootPath',
|
|
8546
|
-
'distPath',
|
|
8547
|
-
'devServer',
|
|
8548
|
-
'cachePath',
|
|
8549
|
-
'callerName',
|
|
8550
|
-
'bundlerType'
|
|
8551
|
-
];
|
|
8552
|
-
return new Proxy(context, {
|
|
8553
|
-
get (target, prop) {
|
|
8554
|
-
if (exposedKeys.includes(prop)) return target[prop];
|
|
8555
|
-
},
|
|
8556
|
-
set: (_, prop)=>(index_js_namespaceObject.logger.error(`Context is readonly, you can not assign to the "context.${prop}" prop.`), !0)
|
|
8557
|
-
});
|
|
8558
|
-
}(context);
|
|
8559
|
-
function getNormalizedConfig(options) {
|
|
8560
|
-
if (context.normalizedConfig) {
|
|
8561
|
-
if (null == options ? void 0 : options.environment) {
|
|
8562
|
-
let config = context.normalizedConfig.environments[options.environment];
|
|
8563
|
-
if (!config) throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} Cannot find normalized config by environment: ${options.environment}.`);
|
|
8564
|
-
return config;
|
|
8565
|
-
}
|
|
8566
|
-
return context.normalizedConfig;
|
|
8567
|
-
}
|
|
8568
|
-
throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} Cannot access normalized config until ${picocolors_index_js_default().yellow('modifyRsbuildConfig')} is called.`);
|
|
8569
|
-
}
|
|
8570
|
-
let getRsbuildConfig = (type = 'current')=>{
|
|
8571
|
-
switch(type){
|
|
8572
|
-
case 'original':
|
|
8573
|
-
return context.originalConfig;
|
|
8574
|
-
case 'current':
|
|
8575
|
-
return context.config;
|
|
8576
|
-
case 'normalized':
|
|
8577
|
-
return getNormalizedConfig();
|
|
8578
|
-
}
|
|
8579
|
-
throw Error(`${picocolors_index_js_default().dim('[rsbuild]')} ${picocolors_index_js_default().yellow('getRsbuildConfig')} get an invalid type param.`);
|
|
8580
|
-
}, exposed = [], expose = (id, api)=>{
|
|
8581
|
-
exposed.push({
|
|
8582
|
-
id,
|
|
8583
|
-
api
|
|
8584
|
-
});
|
|
8585
|
-
}, useExposed = (id)=>{
|
|
8586
|
-
let matched = exposed.find((item)=>item.id === id);
|
|
8587
|
-
if (matched) return matched.api;
|
|
8588
|
-
}, transformId = 0, transformer = {}, processAssetsFns = [], resolveFns = [];
|
|
8589
|
-
hooks.modifyBundlerChain.tap((chain, { target, environment })=>{
|
|
8590
|
-
let pluginName = 'RsbuildCorePlugin';
|
|
8591
|
-
chain.plugin(pluginName).use(class {
|
|
8592
|
-
apply(compiler) {
|
|
8593
|
-
for (let { handler, environment: pluginEnvironment } of (compiler.__rsbuildTransformer = transformer, resolveFns))(!pluginEnvironment || isEnvironmentMatch(pluginEnvironment, environment.name)) && compiler.hooks.compilation.tap(pluginName, (compilation, { normalModuleFactory })=>{
|
|
8594
|
-
normalModuleFactory.hooks.resolve.tapPromise(pluginName, async (resolveData)=>handler({
|
|
8595
|
-
compiler,
|
|
8596
|
-
compilation,
|
|
8597
|
-
environment,
|
|
8598
|
-
resolveData
|
|
8599
|
-
}));
|
|
8600
|
-
});
|
|
8601
|
-
compiler.hooks.thisCompilation.tap(pluginName, (compilation)=>{
|
|
8602
|
-
compilation.hooks.childCompiler.tap(pluginName, (childCompiler)=>{
|
|
8603
|
-
childCompiler.__rsbuildTransformer = transformer;
|
|
8604
|
-
});
|
|
8605
|
-
let { sources } = compiler.webpack;
|
|
8606
|
-
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({
|
|
8607
|
-
name: pluginName,
|
|
8608
|
-
stage: mapProcessAssetsStage(compiler, descriptor.stage)
|
|
8609
|
-
}, async (assets)=>handler({
|
|
8610
|
-
assets,
|
|
8611
|
-
compiler,
|
|
8612
|
-
compilation,
|
|
8613
|
-
environment,
|
|
8614
|
-
sources
|
|
8615
|
-
}));
|
|
8714
|
+
{
|
|
8715
|
+
name: 'rsbuild:nonce',
|
|
8716
|
+
setup (api) {
|
|
8717
|
+
api.onAfterCreateCompiler(({ compiler, environments })=>{
|
|
8718
|
+
let nonces = Object.values(environments).map((environment)=>{
|
|
8719
|
+
let { nonce } = environment.config.security;
|
|
8720
|
+
return nonce;
|
|
8616
8721
|
});
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
}
|
|
8627
|
-
});
|
|
8628
|
-
});
|
|
8629
|
-
let onExitListened = !1, onExit = (cb)=>{
|
|
8630
|
-
if (!onExitListened) {
|
|
8631
|
-
var onExit;
|
|
8632
|
-
onExit = (exitCode)=>{
|
|
8633
|
-
hooks.onExit.callBatch({
|
|
8634
|
-
exitCode
|
|
8722
|
+
if (!nonces.some((nonce)=>!!nonce)) return;
|
|
8723
|
+
let environmentList = Object.values(environments);
|
|
8724
|
+
applyToCompiler(compiler, (compiler, index)=>{
|
|
8725
|
+
let nonce = nonces[index], environment = environmentList.find((item)=>item.index === index);
|
|
8726
|
+
if (!Object.keys((null == environment ? void 0 : environment.htmlPaths) ?? {}).length || !nonce) return;
|
|
8727
|
+
let injectCode = createVirtualModule(`__webpack_nonce__ = "${nonce}";`);
|
|
8728
|
+
new compiler.webpack.EntryPlugin(compiler.context, injectCode, {
|
|
8729
|
+
name: void 0
|
|
8730
|
+
}).apply(compiler);
|
|
8635
8731
|
});
|
|
8636
|
-
}
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
return (environment)=>{
|
|
8647
|
-
let environment1, environment2, environment3;
|
|
8648
|
-
return {
|
|
8649
|
-
context: publicContext,
|
|
8650
|
-
expose,
|
|
8651
|
-
logger: index_js_namespaceObject.logger,
|
|
8652
|
-
transform: (environment1 = environment, (descriptor, handler)=>{
|
|
8653
|
-
let id = `rsbuild-transform-${transformId++}`;
|
|
8654
|
-
transformer[id] = handler, hooks.modifyBundlerChain.tapEnvironment({
|
|
8655
|
-
environment: environment1,
|
|
8656
|
-
handler: (chain, { target, environment })=>{
|
|
8657
|
-
if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environment.name)) return;
|
|
8658
|
-
let rule = chain.module.rule(id);
|
|
8659
|
-
descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer), descriptor.issuer && rule.issuer(descriptor.issuer), descriptor.with && rule.with(descriptor.with), descriptor.mimetype && rule.mimetype(descriptor.mimetype), descriptor.order && 'default' !== descriptor.order ? rule.enforce(descriptor.order) : descriptor.enforce && rule.enforce(descriptor.enforce);
|
|
8660
|
-
let loaderName = descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs', loaderPath = (0, external_node_path_namespaceObject.join)(LOADER_PATH, loaderName);
|
|
8661
|
-
rule.use(id).loader(loaderPath).options({
|
|
8662
|
-
id,
|
|
8663
|
-
getEnvironment: ()=>environment
|
|
8664
|
-
});
|
|
8732
|
+
}), api.modifyHTMLTags({
|
|
8733
|
+
order: 'post',
|
|
8734
|
+
handler: ({ headTags, bodyTags }, { environment })=>{
|
|
8735
|
+
let { config } = environment, { nonce } = config.security, allTags = [
|
|
8736
|
+
...headTags,
|
|
8737
|
+
...bodyTags
|
|
8738
|
+
];
|
|
8739
|
+
if (nonce) for (let tag of allTags){
|
|
8740
|
+
var _tag_attrs, _tag_attrs1;
|
|
8741
|
+
("script" === tag.tag || 'style' === tag.tag || 'link' === tag.tag && (null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.rel) === 'preload' && (null == (_tag_attrs1 = tag.attrs) ? void 0 : _tag_attrs1.as) === "script") && (tag.attrs ??= {}, tag.attrs.nonce = nonce);
|
|
8665
8742
|
}
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
}),
|
|
8676
|
-
resolve: (environment3 = environment, (handler)=>{
|
|
8677
|
-
resolveFns.push({
|
|
8678
|
-
environment: environment3,
|
|
8679
|
-
handler
|
|
8680
|
-
});
|
|
8681
|
-
}),
|
|
8682
|
-
getRsbuildConfig,
|
|
8683
|
-
getNormalizedConfig,
|
|
8684
|
-
isPluginExists: pluginManager.isPluginExists,
|
|
8685
|
-
onExit,
|
|
8686
|
-
onAfterBuild: hooks.onAfterBuild.tap,
|
|
8687
|
-
onCloseBuild: hooks.onCloseBuild.tap,
|
|
8688
|
-
onBeforeBuild: hooks.onBeforeBuild.tap,
|
|
8689
|
-
onCloseDevServer: hooks.onCloseDevServer.tap,
|
|
8690
|
-
onDevCompileDone: hooks.onDevCompileDone.tap,
|
|
8691
|
-
onAfterCreateCompiler: hooks.onAfterCreateCompiler.tap,
|
|
8692
|
-
onAfterStartDevServer: hooks.onAfterStartDevServer.tap,
|
|
8693
|
-
onBeforeCreateCompiler: hooks.onBeforeCreateCompiler.tap,
|
|
8694
|
-
onBeforeStartDevServer: hooks.onBeforeStartDevServer.tap,
|
|
8695
|
-
onAfterStartProdServer: hooks.onAfterStartProdServer.tap,
|
|
8696
|
-
onBeforeStartProdServer: hooks.onBeforeStartProdServer.tap,
|
|
8697
|
-
modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap,
|
|
8698
|
-
modifyHTML: (handler)=>{
|
|
8699
|
-
hooks.modifyHTML.tapEnvironment({
|
|
8700
|
-
environment,
|
|
8701
|
-
handler
|
|
8702
|
-
});
|
|
8703
|
-
},
|
|
8704
|
-
modifyHTMLTags: (handler)=>{
|
|
8705
|
-
hooks.modifyHTMLTags.tapEnvironment({
|
|
8706
|
-
environment,
|
|
8707
|
-
handler
|
|
8708
|
-
});
|
|
8709
|
-
},
|
|
8710
|
-
modifyBundlerChain: (handler)=>{
|
|
8711
|
-
hooks.modifyBundlerChain.tapEnvironment({
|
|
8712
|
-
environment,
|
|
8713
|
-
handler
|
|
8714
|
-
});
|
|
8715
|
-
},
|
|
8716
|
-
modifyRspackConfig: (handler)=>{
|
|
8717
|
-
hooks.modifyRspackConfig.tapEnvironment({
|
|
8718
|
-
environment,
|
|
8719
|
-
handler
|
|
8720
|
-
});
|
|
8721
|
-
},
|
|
8722
|
-
modifyWebpackChain: (handler)=>{
|
|
8723
|
-
hooks.modifyWebpackChain.tapEnvironment({
|
|
8724
|
-
environment,
|
|
8725
|
-
handler
|
|
8726
|
-
});
|
|
8727
|
-
},
|
|
8728
|
-
modifyWebpackConfig: (handler)=>{
|
|
8729
|
-
hooks.modifyWebpackConfig.tapEnvironment({
|
|
8730
|
-
environment,
|
|
8731
|
-
handler
|
|
8732
|
-
});
|
|
8733
|
-
},
|
|
8734
|
-
modifyEnvironmentConfig: (handler)=>{
|
|
8735
|
-
hooks.modifyEnvironmentConfig.tapEnvironment({
|
|
8736
|
-
environment,
|
|
8737
|
-
handler
|
|
8738
|
-
});
|
|
8739
|
-
},
|
|
8740
|
-
onAfterEnvironmentCompile: (handler)=>{
|
|
8741
|
-
hooks.onAfterEnvironmentCompile.tapEnvironment({
|
|
8742
|
-
environment,
|
|
8743
|
-
handler
|
|
8744
|
-
});
|
|
8745
|
-
},
|
|
8746
|
-
onBeforeEnvironmentCompile: (handler)=>{
|
|
8747
|
-
hooks.onBeforeEnvironmentCompile.tapEnvironment({
|
|
8748
|
-
environment,
|
|
8749
|
-
handler
|
|
8750
|
-
});
|
|
8751
|
-
}
|
|
8752
|
-
};
|
|
8753
|
-
};
|
|
8754
|
-
}({
|
|
8755
|
-
context,
|
|
8756
|
-
pluginManager
|
|
8757
|
-
});
|
|
8758
|
-
context.getPluginAPI = getPluginAPI;
|
|
8759
|
-
let globalPluginAPI = getPluginAPI();
|
|
8760
|
-
index_js_namespaceObject.logger.debug('add default plugins'), await applyDefaultPlugins(pluginManager, context), index_js_namespaceObject.logger.debug('add default plugins done');
|
|
8743
|
+
return {
|
|
8744
|
+
headTags,
|
|
8745
|
+
bodyTags
|
|
8746
|
+
};
|
|
8747
|
+
}
|
|
8748
|
+
});
|
|
8749
|
+
}
|
|
8750
|
+
}
|
|
8751
|
+
]), index_js_namespaceObject.logger.debug('add default plugins done');
|
|
8761
8752
|
let provider = config.provider || rspackProvider, providerInstance = await provider({
|
|
8762
|
-
context,
|
|
8763
|
-
pluginManager,
|
|
8753
|
+
context: context2,
|
|
8754
|
+
pluginManager: pluginManager1,
|
|
8764
8755
|
rsbuildOptions: resolvedOptions,
|
|
8765
8756
|
helpers: provider_helpers_namespaceObject
|
|
8766
8757
|
}), preview = async (options = {})=>{
|
|
8767
|
-
|
|
8758
|
+
context2.action = 'preview', process.env.NODE_ENV || setNodeEnv('production');
|
|
8768
8759
|
let config = await initRsbuildConfig({
|
|
8769
|
-
context,
|
|
8770
|
-
pluginManager
|
|
8771
|
-
}), { distPath } =
|
|
8760
|
+
context: context2,
|
|
8761
|
+
pluginManager: pluginManager1
|
|
8762
|
+
}), { distPath } = context2, { checkDistDir = !0 } = options;
|
|
8772
8763
|
if (checkDistDir) {
|
|
8773
8764
|
if (!(0, external_node_fs_namespaceObject.existsSync)(distPath)) throw Error(`${picocolors_index_js_default().dim('[rsbuild:preview]')} The output directory ${picocolors_index_js_default().yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
8774
8765
|
if (function(path) {
|
|
@@ -8776,23 +8767,23 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8776
8767
|
return 0 === files.length || 1 === files.length && '.git' === files[0];
|
|
8777
8768
|
}(distPath)) throw Error(`${picocolors_index_js_default().dim('[rsbuild:preview]')} The output directory ${picocolors_index_js_default().yellow(distPath)} is empty, please build the project before previewing.`);
|
|
8778
8769
|
}
|
|
8779
|
-
return startProdServer(
|
|
8770
|
+
return startProdServer(context2, config, options);
|
|
8780
8771
|
}, build = async (...args)=>{
|
|
8781
|
-
|
|
8772
|
+
context2.action = 'build', process.env.NODE_ENV || setNodeEnv('production');
|
|
8782
8773
|
let buildInstance = await providerInstance.build(...args);
|
|
8783
8774
|
return {
|
|
8784
8775
|
...buildInstance,
|
|
8785
8776
|
close: async ()=>{
|
|
8786
|
-
await
|
|
8777
|
+
await context2.hooks.onCloseBuild.callBatch(), await buildInstance.close();
|
|
8787
8778
|
}
|
|
8788
8779
|
};
|
|
8789
8780
|
}, rsbuild = {
|
|
8790
8781
|
build,
|
|
8791
8782
|
preview,
|
|
8792
|
-
startDevServer: (...args)=>(
|
|
8793
|
-
createCompiler: (...args)=>(
|
|
8794
|
-
createDevServer: (...args)=>(
|
|
8795
|
-
...pick(
|
|
8783
|
+
startDevServer: (...args)=>(context2.action = 'dev', process.env.NODE_ENV || setNodeEnv('development'), providerInstance.startDevServer(...args)),
|
|
8784
|
+
createCompiler: (...args)=>(context2.action || (context2.action = 'development' === (process.env.NODE_ENV || '') ? 'dev' : 'build'), providerInstance.createCompiler(...args)),
|
|
8785
|
+
createDevServer: (...args)=>(context2.action = 'dev', process.env.NODE_ENV || setNodeEnv('development'), providerInstance.createDevServer(...args)),
|
|
8786
|
+
...pick(pluginManager1, [
|
|
8796
8787
|
'addPlugins',
|
|
8797
8788
|
'getPlugins',
|
|
8798
8789
|
'removePlugins',
|
|
@@ -8832,7 +8823,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8832
8823
|
rsbuild.addPlugins(plugins);
|
|
8833
8824
|
}
|
|
8834
8825
|
return config.environments && await Promise.all(Object.entries(config.environments).map(async ([name, environmentConfig])=>{
|
|
8835
|
-
if (!environmentConfig.plugins ||
|
|
8826
|
+
if (!environmentConfig.plugins || context2.specifiedEnvironments && !context2.specifiedEnvironments.includes(name)) return;
|
|
8836
8827
|
let plugins = await getFlattenedPlugins(environmentConfig.plugins);
|
|
8837
8828
|
rsbuild.addPlugins(plugins, {
|
|
8838
8829
|
environment: name
|
|
@@ -9016,7 +9007,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
9016
9007
|
let applyServerOptions = (command)=>{
|
|
9017
9008
|
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');
|
|
9018
9009
|
};
|
|
9019
|
-
|
|
9010
|
+
function runCLI() {
|
|
9020
9011
|
if (!process.env.NODE_ENV) {
|
|
9021
9012
|
let command = process.argv[2];
|
|
9022
9013
|
process.env.NODE_ENV = [
|
|
@@ -9035,11 +9026,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
9035
9026
|
].includes(level) && (index_js_namespaceObject.logger.level = level);
|
|
9036
9027
|
}
|
|
9037
9028
|
let { npm_execpath } = process.env;
|
|
9038
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && index_js_namespaceObject.logger.log(), index_js_namespaceObject.logger.greet(` Rsbuild v1.4.
|
|
9029
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && index_js_namespaceObject.logger.log(), index_js_namespaceObject.logger.greet(` Rsbuild v1.4.15\n`);
|
|
9039
9030
|
try {
|
|
9040
9031
|
!function() {
|
|
9041
9032
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
9042
|
-
cli.help(), cli.version("1.4.
|
|
9033
|
+
cli.help(), cli.version("1.4.15"), 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`', {
|
|
9043
9034
|
default: 'jiti'
|
|
9044
9035
|
}).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('--log-level <level>', 'specify the log level, can be `info`, `warn`, `error` or `silent`').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--environment <name>', 'specify the name of environment to build', {
|
|
9045
9036
|
type: [
|
|
@@ -9097,7 +9088,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
9097
9088
|
index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), index_js_namespaceObject.logger.error(err);
|
|
9098
9089
|
}
|
|
9099
9090
|
}
|
|
9100
|
-
let src_version = "1.4.
|
|
9091
|
+
let src_version = "1.4.15";
|
|
9101
9092
|
})(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, exports.defaultAllowedOrigins = __webpack_exports__.defaultAllowedOrigins, exports.defineConfig = __webpack_exports__.defineConfig, exports.ensureAssetPrefix = __webpack_exports__.ensureAssetPrefix, exports.loadConfig = __webpack_exports__.loadConfig, exports.loadEnv = __webpack_exports__.loadEnv, exports.logger = __webpack_exports__.logger, exports.mergeRsbuildConfig = __webpack_exports__.mergeRsbuildConfig, exports.rspack = __webpack_exports__.rspack, exports.runCLI = __webpack_exports__.runCLI, exports.version = __webpack_exports__.version, __webpack_exports__)-1 === [
|
|
9102
9093
|
"PLUGIN_CSS_NAME",
|
|
9103
9094
|
"PLUGIN_SWC_NAME",
|