Skip to content

Commit

Permalink
docs: add JSDoc & splitChunks doc
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name committed Oct 10, 2024
1 parent e81bf66 commit cca6792
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
50 changes: 30 additions & 20 deletions packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ type SharedOptimizationSplitChunksCacheGroup = {
* */
chunks?: OptimizationSplitChunksChunks;

// TODO: add JSDoc
/** Sets the size types which are used when a number is used for sizes. */
defaultSizeTypes?: string[];

/**
Expand Down Expand Up @@ -613,7 +613,7 @@ export type OptimizationSplitChunksCacheGroup = {
* */
reuseExistingChunk?: boolean;

// TODO: add JSDoc
/** Allows to assign modules to a cache group by module type. */
type?: string | RegExp;

/** Sets the hint for chunk id. It will be added to chunk's filename. */
Expand All @@ -622,9 +622,14 @@ export type OptimizationSplitChunksCacheGroup = {

/** Tell Rspack how to splitting chunks. */
export type OptimizationSplitChunksOptions = {
/**
* Options for module cache group
* */
cacheGroups?: Record<string, false | OptimizationSplitChunksCacheGroup>;

// TODO: add JSDoc
/**
* Options for modules not selected by any other group.
*/
fallbackCacheGroup?: {
chunks?: OptimizationSplitChunksChunks;
minSize?: number;
Expand All @@ -634,7 +639,12 @@ export type OptimizationSplitChunksOptions = {
automaticNameDelimiter?: string;
};

// TODO: add JSDoc
/**
* Prevents exposing path info when creating names for parts splitted by maxSize.
*
* The value is `true` in production mode.
* The value is `false` in development mode.
* */
hidePathInfo?: boolean;
} & SharedOptimizationSplitChunksCacheGroup;

Expand All @@ -651,8 +661,8 @@ export type Optimization = {

/**
* Whether to minimize the bundle.
* The value is `true` when production mode.
* The value is `false` when development mode.
* The value is `true` in production mode.
* The value is `false` in development mode.
*/
minimize?: boolean;

Expand Down Expand Up @@ -696,16 +706,16 @@ export type Optimization = {
/**
* Adds an additional hash compilation pass after the assets have been processed to get the correct asset content hashes.
*
* The value is `true` when production mode.
* The value is `false` when development mode.
* The value is `true` in production mode.
* The value is `false` in development mode.
*/
realContentHash?: boolean;

/**
* Tells Rspack to recognise the sideEffects flag in package.json or rules to skip over modules which are flagged to contain no side effects when exports are not used.
*
* The value is `true` when production mode.
* The value is `false` when development mode.
* The value is `true` in production mode.
* The value is `false` in development mode.
* */
sideEffects?: "flag" | boolean;

Expand All @@ -718,32 +728,32 @@ export type Optimization = {
/**
* Tells Rspack to find segments of the module graph which can be safely concatenated into a single module.
*
* The value is `true` when production mode.
* The value is `false` when development mode.
* The value is `true` in production mode.
* The value is `false` in development mode.
*/
concatenateModules?: boolean;

/**
* Tells Rspack whether to perform a more detailed analysis of variable assignments.
*
* The value is `true` when production mode.
* The value is `false` when development mode.
* The value is `true` in production mode.
* The value is `false` in development mode.
*/
innerGraph?: boolean;

/**
* Tells Rspack to determine used exports for each module.
*
* The value is `true` when production mode.
* The value is `false` when development mode.
* The value is `true` in production mode.
* The value is `false` in development mode.
* */
usedExports?: "global" | boolean;

/**
* Allows to control export mangling.
*
* The value is `isdeterministic` when production mode.
* The value is `false` when development mode.
* The value is `isdeterministic` in production mode.
* The value is `false` in development mode.
*/
mangleExports?: "size" | "deterministic" | boolean;

Expand All @@ -756,8 +766,8 @@ export type Optimization = {
/**
* Emit assets whenever there are errors while compiling.
*
* The value is `false` when production mode.
* The value is `true` when development mode.
* The value is `false` in production mode.
* The value is `true` in development mode.
* */
emitOnErrors?: boolean;
};
Expand Down
12 changes: 12 additions & 0 deletions website/docs/en/plugins/webpack/split-chunks-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ chunk baz
chunk shared-2 (exports only value2)
```

### splitChunks.defaultSizeTypes

- **Types:** `string[]`

Sets the size types which are used when a number is used for sizes.

### splitChunks.cacheGroups

Cache groups can inherit and/or override any options from `splitChunks.*`; but `test`, `priority` and `reuseExistingChunk` can only be configured on cache group level. To disable any of the default cache groups, set them to `false`.
Expand Down Expand Up @@ -358,3 +364,9 @@ cacheGroup: {
In chunks Foo and Bar, the module B, due to the configuration of cacheGroup, will be split into a new chunk that only contains module B. This new chunk is identical in terms of the modules it contains with chunk Bar, so chunk Bar can be directly reused.

If the setting of reuseExistingChunk is set to `false`, then the module B in chunks Bar and Foo will be moved to a new chunk, and chunk Bar, since it no longer contains any modules, will be deleted as an empty chunk.

#### splitChunks.cacheGroups.\{cacheGroup\}.type

- **Types:** `string | RegExp`

Allows to assign modules to a cache group by module type.
12 changes: 12 additions & 0 deletions website/docs/zh/plugins/webpack/split-chunks-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ chunk baz
chunk shared-2 (exports only value2)
```

### splitChunks.defaultSizeTypes

- **类型:** `string[]`

用来控制在计算文件大小时应该使用哪些大小类型

### splitChunks.cacheGroups

缓存组可以继承和/或覆盖来自 `splitChunks.*` 的任何选项。但是 `test``priority``reuseExistingChunk` 只能在缓存组级别上进行配置。将它们设置为 `false` 以禁用任何默认缓存组。
Expand Down Expand Up @@ -348,3 +354,9 @@ cacheGroup: {
由于 cacheGroup 的配置,在 chunk Foo 和 chunk Bar 中的 module B 会被拆分到一个新的 chunk 中,该 chunk 只包含 module B,这个新 chunk 和 chunk Bar 包含的 module 完全一样,因此可以直接复用 chunk Bar。

如果设置 reuseExistingChunk 为 `false`,那么 chunk Bar 和 chunk Foo 中的 module B 会被移到新 chunk 中,chunk Bar 由于不包含任何 module,会作为空 chunk 被删除。

#### splitChunks.cacheGroups.\{cacheGroup\}.type

- **Types:** `string | RegExp`

允许模块根据模块类型分配给 cache group

0 comments on commit cca6792

Please sign in to comment.