diff --git a/.changeset/default-lazy-compilation.md b/.changeset/default-lazy-compilation.md new file mode 100644 index 0000000..08b0721 --- /dev/null +++ b/.changeset/default-lazy-compilation.md @@ -0,0 +1,5 @@ +--- +"rsbuild-plugin-react-router": patch +--- + +Enable guarded Rsbuild lazy compilation by default during development. Pass `lazyCompilation: false` to keep the previous eager compilation behavior. diff --git a/src/index.ts b/src/index.ts index 105a405..f157388 100644 --- a/src/index.ts +++ b/src/index.ts @@ -143,6 +143,7 @@ export const pluginReactRouter = ( async setup(api) { const defaultOptions = { customServer: false, + lazyCompilation: true, serverOutput: 'module' as const, }; @@ -767,10 +768,12 @@ export const pluginReactRouter = ( serverBundleEntries, }); - const configuredLazyCompilation = - pluginOptions.lazyCompilation === undefined - ? config.dev?.lazyCompilation - : pluginOptions.lazyCompilation; + const configuredLazyCompilation = Object.prototype.hasOwnProperty.call( + options, + 'lazyCompilation' + ) + ? pluginOptions.lazyCompilation + : (config.dev?.lazyCompilation ?? pluginOptions.lazyCompilation); const guardedLazyCompilation = guardReactRouterLazyCompilation({ lazyCompilation: configuredLazyCompilation, entryClientPath: finalEntryClientPath, diff --git a/src/types.ts b/src/types.ts index 5d2fe1c..727ad33 100644 --- a/src/types.ts +++ b/src/types.ts @@ -32,7 +32,8 @@ export type PluginOptions = { /** * Rsbuild dev-only lazy compilation behavior. - * @default false + * Pass `false` to disable. + * @default true */ lazyCompilation?: NonNullable['lazyCompilation']; diff --git a/tests/index.test.ts b/tests/index.test.ts index c8cfe4b..4e3ed92 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -31,7 +31,15 @@ describe('pluginReactRouter', () => { expect(config.dev.hmr).toBe(true); expect(config.dev.liveReload).toBe(true); expect(config.dev.writeToDisk).toBe(true); - expect(config.dev.lazyCompilation).toBeUndefined(); + expect(config.dev.lazyCompilation).toMatchObject({ + entries: true, + imports: true, + }); + expect( + config.dev.lazyCompilation.test({ + resource: `${process.cwd()}/app/entry.client.tsx`, + }) + ).toBe(false); }); it('adds the committed custom-server build entry only in development', async () => {