Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ describe("with lazy compilation", function () {
const configs = [
{
entry: "./esm/a.js",
context
context,
experiments: {
lazyCompilation: false
}
},
{
entry: "./esm/b.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ export type Experiments = {
cache?: ExperimentCacheOptions;
/**
* Enable lazy compilation.
* @default false
* @default true
*/
lazyCompilation?: boolean | LazyCompilationOptions;
/**
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/cases/css/import-empty-css-file/index.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
5 changes: 4 additions & 1 deletion tests/e2e/cases/hooks/asset-emitted/index.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/cases/html/cross-origin-loading/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
});
1 change: 1 addition & 0 deletions tests/e2e/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ const test = base

export type { RspackOptions };
export { test, expect };
export { waitForHmr } from './waitForHmr'
14 changes: 14 additions & 0 deletions tests/e2e/fixtures/waitForHmr.ts
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion website/docs/en/config/experiments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
## experiments.lazyCompilation

- **Type:** `boolean | LazyCompilationOptions`
- **Default:** `false`
- **Default:** `{ imports: true, entries: false }`

```ts
type LazyCompilationOptions =
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/config/experiments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default {
## experiments.lazyCompilation

- **类型:** `boolean | LazyCompilationOptions`
- **默认值:** `false`
- **默认值:** `{ imports: true, entries: false }`

```ts
type LazyCompilationOptions =
Expand Down
Loading