Skip to content

Commit b618619

Browse files
authored
docs(api): add Compilation.hooks.statsNormalize (#7212)
1 parent 752730c commit b618619

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/content/api/compilation-hooks.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,23 @@ compilation.hooks.statsPreset.for('my-preset').tap('MyPlugin', (options) => {
668668
```
669669

670670
This plugin ensures that for the preset `'my-preset'`, if the `all` option is undefined, it defaults to true.
671+
672+
### statsNormalize
673+
674+
`SyncHook`
675+
676+
This hook is used to transform an options object into a consistent format that can be easily used by subsequent hooks. It also ensures that missing options are set to their default values.
677+
678+
- Callback Parameters: `options` `context`
679+
680+
Here's an illustrative plugin example:
681+
682+
```js
683+
compilation.hooks.statsNormalize.tap('MyPlugin', (options) => {
684+
if (options.myOption === undefined) options.myOption = [];
685+
686+
if (!Array.isArray(options.myOption)) options.myOptions = [options.myOptions];
687+
});
688+
```
689+
690+
In this plugin, if the `myOption` is missing, it sets it to an empty array. Additionally, it ensures that `myOption` is always an array even if it was originally defined as a single value.

0 commit comments

Comments
 (0)