Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support compilation.chunkGroup[].isInitial() #7406

Merged
merged 1 commit into from
Aug 1, 2024
Merged
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
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export interface JsChunkGroup {
chunks: Array<JsChunk>
index?: number
name?: string
isInitial: boolean
}

export interface JsChunkPathData {
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_values/src/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct JsChunkGroup {
pub chunks: Vec<JsChunk>,
pub index: Option<u32>,
pub name: Option<String>,
pub is_initial: bool,
}

impl JsChunkGroup {
Expand All @@ -29,6 +30,7 @@ impl JsChunkGroup {
inner_parents: cg.parents.iter().map(|ukey| ukey.as_u32()).collect(),
inner_ukey: cg.ukey.as_u32(),
name: cg.name().map(|name| name.to_string()),
is_initial: cg.is_initial(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function plugin(compiler) {
expect(chunkGroups.length).toBe(6);
expect(chunkGroups.find(i => i.name === 'a').getFiles()).toEqual(['a.js']);
expect(chunkGroups.find(i => i.name === 'b').getFiles()).toEqual(['b.js']);
expect(chunkGroups.filter(i => i.isInitial()).length).toEqual(2);

const namedChunkGroups = compilation.namedChunkGroups;
expect(Array.from(namedChunkGroups.keys()).length).toBe(2);
Expand Down
2 changes: 2 additions & 0 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ export class ChunkGroup {
// (undocumented)
get index(): Readonly<number | undefined>;
// (undocumented)
isInitial(): boolean;
// (undocumented)
get name(): Readonly<string | undefined>;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/rspack/src/ChunkGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class ChunkGroup {
});
}

isInitial(): boolean {
return this.#inner.isInitial;
}

get chunks(): ReadonlyArray<Chunk> {
return this.#inner.chunks.map(c =>
Chunk.__from_binding(c, this.#innerCompilation)
Expand Down
11 changes: 6 additions & 5 deletions website/docs/en/types/chunk-group.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

```ts
type ChunkGroup = {
name?: Readonly<string>;
index?: Readonly<number>;
chunks: ReadonlyArray<Chunk>;
getFiles(): ReadonlyArray<string>;
getParents(): ReadonlyArray<ChunkGroup>;
name?: Readonly<string>; // name of this chunk group
index?: Readonly<number>; // creating index of chunk group
chunks: ReadonlyArray<Chunk>; // chunks in this chunk group
isInitial(): boolean; // whether this chunk group will be loaded on initial page load
getFiles(): ReadonlyArray<string>; // the files contained this chunk group
getParents(): ReadonlyArray<ChunkGroup>; // returns the parent chunk groups
};
```

Expand Down
13 changes: 7 additions & 6 deletions website/docs/en/types/entrypoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

```ts
type Entrypoint = {
name?: Readonly<string>;
index?: Readonly<number>;
chunks: ReadonlyArray<Chunk>;
getFiles(): ReadonlyArray<string>;
getParents(): ReadonlyArray<ChunkGroup>;
getRuntimeChunk(): Readonly<Chunk | null>;
name?: Readonly<string>; // name of this chunk group
index?: Readonly<number>; // creating index of chunk group
chunks: ReadonlyArray<Chunk>; // chunks in this chunk group
isInitial(): boolean; // whether this chunk group will be loaded on initial page load
getFiles(): ReadonlyArray<string>; // the files contained this chunk group
getParents(): ReadonlyArray<ChunkGroup>; // returns the parent chunk groups
getRuntimeChunk(): Readonly<Chunk | null>; // the chunk containing the webpack bootstrap code
};
```

Expand Down
1 change: 1 addition & 0 deletions website/docs/zh/types/chunk-group.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type ChunkGroup = {
name?: Readonly<string>; // 名称
index?: Readonly<number>; // 索引序
chunks: ReadonlyArray<Chunk>; // 包含的 chunk 列表
isInitial(): boolean; // 是否在页面初始加载
getFiles(): ReadonlyArray<string>; // 关联的文件列表
getParents(): ReadonlyArray<ChunkGroup>; // 父 chunk group 列表
};
Expand Down
3 changes: 2 additions & 1 deletion website/docs/zh/types/entrypoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ type Entrypoint = {
name?: Readonly<string>; // 名称
index?: Readonly<number>; // 索引序
chunks: ReadonlyArray<Chunk>; // 包含的 chunk 列表
isInitial(): boolean; // 是否在页面初始加载
getFiles(): ReadonlyArray<string>; // 关联的文件列表
getParents(): ReadonlyArray<ChunkGroup>; // 父 chunk group 列表
getRuntimeChunk(): Readonly<Chunk | null>;
getRuntimeChunk(): Readonly<Chunk | null>; // 包含 webpack 启动代码的 chunk
};
```

Expand Down
Loading