For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /configure/app/dev/lazy-compilation.md.

dev.lazyCompilation

  • Type:
type LazyCompilationOptions =
  | boolean
  | {
      /**
       * Enable lazy compilation for entries.
       */
      entries?: boolean;
      /**
       * Enable lazy compilation for dynamic imports.
       */
      imports?: boolean;
      /**
       * Specify which imported modules should be lazily compiled.
       */
      test?: RegExp | ((m: Module) => boolean);
      /**
       * The path to a custom runtime code that overrides the default lazy compilation client.
       */
      client?: string;
      /**
       * Tells the client the server URL that needs to be requested.
       */
      serverUrl?: string;
    };
  • Default: depends on how the application renders:
    • Pure CSR and streaming SSR applications: { imports: true, entries: false }, which compiles dynamic imports on demand;
    • Applications using string SSR (including any entry in server.ssrByEntries using string SSR), RSC or SSG: false.

Enable lazy compilation (compilation on demand), implemented based on Rspack's lazy compilation feature.

This option only takes effect in the dev server and does not affect production build output. When enabled for streaming SSR applications, route components are still compiled eagerly so that first-screen JS/CSS injection stays correct.

An explicitly configured dev.lazyCompilation always takes precedence over the default. To disable it:

import { defineConfig } from '@modern-js/app-tools';

export default defineConfig({
  dev: {
    lazyCompilation: false,
  },
});
Info

The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to Rsbuild - dev.lazyCompilation。 In Rspack build mode,