Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/default-lazy-compilation.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const pluginReactRouter = (
async setup(api) {
const defaultOptions = {
customServer: false,
lazyCompilation: true,
serverOutput: 'module' as const,
};

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export type PluginOptions = {

/**
* Rsbuild dev-only lazy compilation behavior.
* @default false
* Pass `false` to disable.
* @default true
*/
lazyCompilation?: NonNullable<RsbuildConfig['dev']>['lazyCompilation'];

Expand Down
10 changes: 9 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading