> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt.

# CompactHashedChunkIdsPlugin


[Added in v2.2.1](https://github.com/web-infra-dev/rspack/releases/tag/v2.2.1)Rspack only

`CompactHashedChunkIdsPlugin` 会对 Chunk 内容计算 hash，并分配编码后 hash 的最短可用前缀。与 `deterministic` 相比，它生成的 id 更紧凑，在保持稳定性的同时，可以减小产物体积并提升运行时索引性能。每个字符均使用 `0-9a-z`，因此 Chunk id 可以安全用于大小写不敏感的文件系统。只有较短前缀已被使用时，才会延长 id。

:::warning 已废弃的别名
`CompatHashedChunkIdsPlugin` 可在 Rspack 2.2.0 中使用，现已废弃，并于 Rspack 2.2.1 更名为 `CompactHashedChunkIdsPlugin`。旧名称目前仅作为兼容别名保留。
:::

`optimization.chunkIds: 'compact-hashed'` 内部会使用该插件。只有在需要自定义编码后 id 的最小长度时，才需要直接使用该插件。

## 示例

```js title="rspack.config.mjs"
import rspack from '@rspack/core';

export default {
  optimization: {
    chunkIds: false,
  },
  plugins: [
    new rspack.ids.CompactHashedChunkIdsPlugin({
      minLength: 1,
    }),
  ],
};
```

## 选项

### minLength

- **类型：** `number`
- **默认值：** `1`
- **取值范围：** `1` 到 `13` 的整数

编码后 id 的最小长度。如果 hash 前缀已经被使用，Rspack 会逐个字符延长该 id。增大 `minLength` 会扩大初始 id 空间，降低前缀冲突的概率，使产物和缓存更加稳定；相应地，Chunk id 也会变长。
