diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index 4649af25dce8..1f065555dca4 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -44,7 +44,10 @@ Object { inlineEnum: false, layers: false, lazyBarrel: false, - lazyCompilation: false, + lazyCompilation: Object { + entries: false, + imports: true, + }, parallelCodeSplitting: false, parallelLoader: false, rspackFuture: Object { diff --git a/packages/rspack-test-tools/tests/legacy-test/MultiCompiler.test.js b/packages/rspack-test-tools/tests/legacy-test/MultiCompiler.test.js index 17881141960b..cdc7f677bcd7 100644 --- a/packages/rspack-test-tools/tests/legacy-test/MultiCompiler.test.js +++ b/packages/rspack-test-tools/tests/legacy-test/MultiCompiler.test.js @@ -46,7 +46,10 @@ describe("with lazy compilation", function () { const configs = [ { entry: "./esm/a.js", - context + context, + experiments: { + lazyCompilation: false + } }, { entry: "./esm/b.js", diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 893c674999f0..ae2dd7b2c301 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -211,7 +211,11 @@ const applyExperimentsDefaults = ( D(experiments, "futureDefaults", false); // IGNORE(experiments.lazyCompilation): In webpack, lazyCompilation is undefined by default - D(experiments, "lazyCompilation", false); + // Rsbuild configure `{lazyCompilation: { imports: true, entries: false }` works well after tests. + // So we decide to set lazyCompilation as `{ imports: true, entries: false }` firstly. + // Maybe we can change it to true in the future. + D(experiments, "lazyCompilation", { imports: true, entries: false }); + D(experiments, "asyncWebAssembly", experiments.futureDefaults); D(experiments, "css", experiments.futureDefaults ? true : undefined); D(experiments, "layers", false); diff --git a/packages/rspack/src/config/types.ts b/packages/rspack/src/config/types.ts index 144dd5ee84e3..2d6c1d6b108e 100644 --- a/packages/rspack/src/config/types.ts +++ b/packages/rspack/src/config/types.ts @@ -2642,7 +2642,7 @@ export type Experiments = { cache?: ExperimentCacheOptions; /** * Enable lazy compilation. - * @default false + * @default true */ lazyCompilation?: boolean | LazyCompilationOptions; /** diff --git a/tests/e2e/cases/css/import-empty-css-file/index.test.ts b/tests/e2e/cases/css/import-empty-css-file/index.test.ts index 95b005465389..ade800fb7fe9 100644 --- a/tests/e2e/cases/css/import-empty-css-file/index.test.ts +++ b/tests/e2e/cases/css/import-empty-css-file/index.test.ts @@ -1,7 +1,8 @@ -import { test, expect } from "@/fixtures"; +import { test, expect, waitForHmr } from "@/fixtures"; test("should not throw error for importing empty css files", async ({ page }) => { + await waitForHmr(page); expect(await page.textContent("#root")).toBe("ok"); }); diff --git a/tests/e2e/cases/hooks/asset-emitted/index.test.ts b/tests/e2e/cases/hooks/asset-emitted/index.test.ts index ef3385cde06f..2a7fa60373f5 100644 --- a/tests/e2e/cases/hooks/asset-emitted/index.test.ts +++ b/tests/e2e/cases/hooks/asset-emitted/index.test.ts @@ -1,13 +1,15 @@ -import { test, expect } from "@/fixtures"; +import { test, expect, waitForHmr } from "@/fixtures"; test("asset emitted hook should only emit modified assets", async ({ page, fileAction, rspack }) => { + const assets = (rspack.compiler as any).assets; // reset assets assets.length = 0; + await waitForHmr(page); expect(await page.textContent("#root")).toBe("__ROOT_TEXT____FOO_VALUE__"); // update js file @@ -47,6 +49,7 @@ test("asset emitted should not emit removed assets", async ({ const assets = (rspack.compiler as any).assets; // reset assets assets.length = 0; + await waitForHmr(page); expect(await page.textContent("#root")).toBe("__ROOT_TEXT____FOO_VALUE__"); // update js file fileAction.updateFile("src/index.js", () => { diff --git a/tests/e2e/cases/html/cross-origin-loading/index.test.ts b/tests/e2e/cases/html/cross-origin-loading/index.test.ts index cc41ab06b9d1..877d2e58635d 100644 --- a/tests/e2e/cases/html/cross-origin-loading/index.test.ts +++ b/tests/e2e/cases/html/cross-origin-loading/index.test.ts @@ -15,7 +15,7 @@ test("should set crossOrigin to anonymous for script tag correctly", async ({ expect(srcPaths).toEqual([ "main.js", - "https://cdn.example.com/src_foo_js.js" + "https://cdn.example.com/src_foo_js_lazy-compilation-proxy.js" ]); expect(crossOrigins).toEqual([null, "anonymous"]); }); diff --git a/tests/e2e/fixtures/index.ts b/tests/e2e/fixtures/index.ts index cebf3d7e1f06..f60cd47ee4f3 100644 --- a/tests/e2e/fixtures/index.ts +++ b/tests/e2e/fixtures/index.ts @@ -10,3 +10,4 @@ const test = base export type { RspackOptions }; export { test, expect }; +export { waitForHmr } from './waitForHmr' diff --git a/tests/e2e/fixtures/waitForHmr.ts b/tests/e2e/fixtures/waitForHmr.ts new file mode 100644 index 000000000000..ae3da2266eae --- /dev/null +++ b/tests/e2e/fixtures/waitForHmr.ts @@ -0,0 +1,14 @@ +import { Page } from "@playwright/test"; + +/** + * we enable lazy compilation by default, so we need to wait for the page to load + * + * This function waits for the HMR (Hot Module Replacement) response to ensure that the page is updated correctly. + * It waits for a response that includes "hot-update" in the URL, with a timeout of 5000 milliseconds, + * and then waits for an additional 500 milliseconds to ensure the page has time to reflect the changes. + * @param page + */ +export async function waitForHmr(page: Page) { + await page.waitForResponse(response => response.url().includes("hot-update"), { timeout: 5000 }); + await page.waitForTimeout(500); +} \ No newline at end of file diff --git a/website/docs/en/config/experiments.mdx b/website/docs/en/config/experiments.mdx index 6ccd46413970..d48e567583ba 100644 --- a/website/docs/en/config/experiments.mdx +++ b/website/docs/en/config/experiments.mdx @@ -105,7 +105,7 @@ export default { ## experiments.lazyCompilation - **Type:** `boolean | LazyCompilationOptions` -- **Default:** `false` +- **Default:** `{ imports: true, entries: false }` ```ts type LazyCompilationOptions = diff --git a/website/docs/zh/config/experiments.mdx b/website/docs/zh/config/experiments.mdx index e4077f055a83..a35245c74a70 100644 --- a/website/docs/zh/config/experiments.mdx +++ b/website/docs/zh/config/experiments.mdx @@ -106,7 +106,7 @@ export default { ## experiments.lazyCompilation - **类型:** `boolean | LazyCompilationOptions` -- **默认值:** `false` +- **默认值:** `{ imports: true, entries: false }` ```ts type LazyCompilationOptions =