From 1c452b55818d499d88b99d6804f34e4d4cc757f7 Mon Sep 17 00:00:00 2001 From: SoonIter Date: Fri, 4 Jul 2025 15:34:19 +0800 Subject: [PATCH 1/3] feat(rsbuild)!: enable persistent cache defaultly via `performance.buildCache` --- packages/core/src/node/initRsbuild.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/node/initRsbuild.ts b/packages/core/src/node/initRsbuild.ts index f577c6951..3f94cad0f 100644 --- a/packages/core/src/node/initRsbuild.ts +++ b/packages/core/src/node/initRsbuild.ts @@ -229,6 +229,7 @@ async function createInternalBuildConfig( }, }, performance: { + buildCache: true, chunkSplit: { override: { cacheGroups: { From e96ac4ef3a86763eb83f04ef347caefdbbea3432 Mon Sep 17 00:00:00 2001 From: SoonIter Date: Mon, 7 Jul 2025 17:31:18 +0800 Subject: [PATCH 2/3] chore: add buildDependencies --- packages/cli/src/config/loadConfigFile.ts | 9 ++++++--- packages/cli/src/index.ts | 11 ++++++++--- packages/core/src/node/PluginDriver.ts | 8 +++++++- packages/core/src/node/build.ts | 5 +++-- packages/core/src/node/dev.ts | 5 +++-- packages/core/src/node/initRsbuild.ts | 4 +++- packages/core/src/node/route/RouteService.test.ts | 2 +- packages/core/src/node/serve.ts | 5 +++-- 8 files changed, 34 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/config/loadConfigFile.ts b/packages/cli/src/config/loadConfigFile.ts index 266df4ad3..a342f79db 100644 --- a/packages/cli/src/config/loadConfigFile.ts +++ b/packages/cli/src/config/loadConfigFile.ts @@ -15,7 +15,7 @@ const findConfig = (basePath: string): string | undefined => { export async function loadConfigFile( customConfigFile?: string, -): Promise { +): Promise<{ config: UserConfig; configFilePath: string }> { const baseDir = process.cwd(); let configFilePath = ''; if (customConfigFile) { @@ -29,7 +29,7 @@ export async function loadConfigFile( } if (!configFilePath) { logger.info(`No config file found in ${baseDir}`); - return {}; + return { config: {}, configFilePath: '' }; } const { loadConfig } = await import('@rsbuild/core'); @@ -38,7 +38,10 @@ export async function loadConfigFile( path: configFilePath, }); - return content as UserConfig; + return { + config: content as UserConfig, + configFilePath, + }; } export function resolveDocRoot( diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 8139254d7..b986eaa2d 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -40,7 +40,9 @@ cli let devServer: Awaited>; const startDevServer = async () => { const { port, host } = options || {}; - const config = await loadConfigFile(options?.config); + const { config, configFilePath } = await loadConfigFile( + options?.config, + ); config.root = resolveDocRoot(cwd, root, config.root); @@ -50,6 +52,7 @@ cli appDirectory: cwd, docDirectory, config, + configFilePath, extraBuilderConfig: { server: { port, host } }, }); @@ -104,7 +107,7 @@ cli cli.command('build [root]').action(async (root, options) => { setNodeEnv('production'); const cwd = process.cwd(); - const config = await loadConfigFile(options.config); + const { config, configFilePath } = await loadConfigFile(options.config); config.root = resolveDocRoot(cwd, root, config.root); const docDirectory = config.root; @@ -113,6 +116,7 @@ cli.command('build [root]').action(async (root, options) => { await build({ docDirectory, config, + configFilePath, }); } catch (err) { logger.error(err); @@ -133,7 +137,7 @@ cli setNodeEnv('production'); const cwd = process.cwd(); const { port, host } = options || {}; - const config = await loadConfigFile(options?.config); + const { config, configFilePath } = await loadConfigFile(options?.config); config.root = resolveDocRoot(cwd, root, config.root); @@ -141,6 +145,7 @@ cli config, host, port, + configFilePath, }); }, ); diff --git a/packages/core/src/node/PluginDriver.ts b/packages/core/src/node/PluginDriver.ts index ac68bc523..9ab4c788c 100644 --- a/packages/core/src/node/PluginDriver.ts +++ b/packages/core/src/node/PluginDriver.ts @@ -20,17 +20,23 @@ type RspressPluginHookKeys = export class PluginDriver { #config: UserConfig; + #configFilePath: string; #plugins: RspressPlugin[]; #isProd: boolean; - constructor(config: UserConfig, isProd: boolean) { + constructor(config: UserConfig, configFilePath: string, isProd: boolean) { this.#config = config; + this.#configFilePath = configFilePath; this.#isProd = isProd; this.#plugins = []; } + getConfigFilePath() { + return this.#configFilePath; + } + // The init function is used to initialize the doc plugins and will execute before the build process. async init() { // Clear RspressPlugins first, for the watch mode diff --git a/packages/core/src/node/build.ts b/packages/core/src/node/build.ts index 33ecdbae3..48a29c491 100644 --- a/packages/core/src/node/build.ts +++ b/packages/core/src/node/build.ts @@ -10,6 +10,7 @@ import { checkLanguageParity } from './utils/checkLanguageParity'; interface BuildOptions { docDirectory: string; config: UserConfig; + configFilePath: string; } export async function bundle( @@ -42,8 +43,8 @@ function emptyDir(path: string): Promise { } export async function build(options: BuildOptions) { - const { docDirectory, config } = options; - const pluginDriver = new PluginDriver(config, true); + const { docDirectory, config, configFilePath } = options; + const pluginDriver = new PluginDriver(config, configFilePath, true); await pluginDriver.init(); const modifiedConfig = await pluginDriver.modifyConfig(); diff --git a/packages/core/src/node/dev.ts b/packages/core/src/node/dev.ts index f7adf4ec2..b50064a1e 100644 --- a/packages/core/src/node/dev.ts +++ b/packages/core/src/node/dev.ts @@ -13,13 +13,14 @@ interface DevOptions { appDirectory: string; docDirectory: string; config: UserConfig; + configFilePath: string; extraBuilderConfig?: RsbuildConfig; } export async function dev(options: DevOptions): Promise { - const { docDirectory, config, extraBuilderConfig } = options; + const { docDirectory, config, extraBuilderConfig, configFilePath } = options; const isProd = false; - const pluginDriver = new PluginDriver(config, isProd); + const pluginDriver = new PluginDriver(config, configFilePath, isProd); await pluginDriver.init(); const modifiedConfig = await pluginDriver.modifyConfig(); diff --git a/packages/core/src/node/initRsbuild.ts b/packages/core/src/node/initRsbuild.ts index 3f94cad0f..8b5b014f5 100644 --- a/packages/core/src/node/initRsbuild.ts +++ b/packages/core/src/node/initRsbuild.ts @@ -229,7 +229,9 @@ async function createInternalBuildConfig( }, }, performance: { - buildCache: true, + buildCache: { + buildDependencies: [pluginDriver.getConfigFilePath()], + }, chunkSplit: { override: { cacheGroups: { diff --git a/packages/core/src/node/route/RouteService.test.ts b/packages/core/src/node/route/RouteService.test.ts index d129073bc..639ded2b3 100644 --- a/packages/core/src/node/route/RouteService.test.ts +++ b/packages/core/src/node/route/RouteService.test.ts @@ -12,7 +12,7 @@ async function initRouteService( ) { const routeService = await RouteService.create({ config, - pluginDriver: new PluginDriver(config, false), + pluginDriver: new PluginDriver(config, '', false), runtimeTempDir: '.rsbuild', scanDir: fixtureDir, }); diff --git a/packages/core/src/node/serve.ts b/packages/core/src/node/serve.ts index a58dfac6f..503c1e777 100644 --- a/packages/core/src/node/serve.ts +++ b/packages/core/src/node/serve.ts @@ -5,6 +5,7 @@ import { initRsbuild } from './initRsbuild'; interface ServeOptions { config: UserConfig; + configFilePath: string; port?: number; host?: string; } @@ -13,7 +14,7 @@ interface ServeOptions { export async function serve( options: ServeOptions, ): Promise> { - const { config, port: userPort, host: userHost } = options; + const { config, port: userPort, host: userHost, configFilePath } = options; const envPort = process.env.PORT; const envHost = process.env.HOST; const { builderConfig } = config; @@ -30,7 +31,7 @@ export async function serve( }, }); - const pluginDriver = new PluginDriver(config, true); + const pluginDriver = new PluginDriver(config, configFilePath, true); await pluginDriver.init(); const modifiedConfig = await pluginDriver.modifyConfig(); From 2c0dab5f98e2d24930f0521ae262a8c5a73f6162 Mon Sep 17 00:00:00 2001 From: SoonIter Date: Mon, 7 Jul 2025 17:40:54 +0800 Subject: [PATCH 3/3] chore: update --- .../cli/tests/config/config-basic.test.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/cli/tests/config/config-basic.test.ts b/packages/cli/tests/config/config-basic.test.ts index f0c5b863a..2bce29556 100644 --- a/packages/cli/tests/config/config-basic.test.ts +++ b/packages/cli/tests/config/config-basic.test.ts @@ -8,7 +8,7 @@ const TEST_TITLE = 'my-title'; describe('Should load config file', () => { test('Load config.cjs', async () => { const fixtureDir = path.join(__dirname, 'cjs'); - const config = await loadConfigFile( + const { config } = await loadConfigFile( path.join(fixtureDir, 'rspress.config.cjs'), ); @@ -20,7 +20,7 @@ describe('Should load config file', () => { test('Load config.mjs', async () => { const fixtureDir = path.join(__dirname, 'esm'); - const config = await loadConfigFile( + const { config } = await loadConfigFile( path.join(fixtureDir, 'rspress.config.mjs'), ); @@ -33,7 +33,7 @@ describe('Should load config file', () => { test('Load config.js/config.ts in cjs project', async () => { const fixtureDir = path.join(__dirname, 'cjs'); - let config = await loadConfigFile( + const { config } = await loadConfigFile( path.join(fixtureDir, 'rspress.config.js'), ); @@ -42,8 +42,10 @@ describe('Should load config file', () => { title: TEST_TITLE, }); - config = await loadConfigFile(path.join(fixtureDir, 'rspress.config.ts')); - expect(config).toMatchObject({ + const { config: config2 } = await loadConfigFile( + path.join(fixtureDir, 'rspress.config.ts'), + ); + expect(config2).toMatchObject({ root: normalizePath(fixtureDir), title: TEST_TITLE, }); @@ -51,7 +53,7 @@ describe('Should load config file', () => { test('Load config.js/config.ts in esm project', async () => { const fixtureDir = path.join(__dirname, 'esm'); - let config = await loadConfigFile( + const { config } = await loadConfigFile( path.join(fixtureDir, 'rspress.config.js'), ); @@ -61,7 +63,9 @@ describe('Should load config file', () => { }; expect(config).toMatchObject(expectConfig); - config = await loadConfigFile(path.join(fixtureDir, 'rspress.config.ts')); - expect(config).toMatchObject(expectConfig); + const { config: config2 } = await loadConfigFile( + path.join(fixtureDir, 'rspress.config.ts'), + ); + expect(config2).toMatchObject(expectConfig); }); });