Skip to content

Commit 3222983

Browse files
committed
blog: enhance Plugin Validation section with detailed explanation and examples
1 parent 643994d commit 3222983

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/content/blog/2026-03-22-webpack-5-106.mdx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ Explore what's new in this release:
1919

2020
## Plugin Validation with `compiler.hooks.validate`
2121

22-
Webpack adds a new top level `validate` option to enable or disable schema validation for webpack configuration, plugin options, and loader options. When validation is disabled, webpack skips these checks, which can reduce overhead in some scenarios, but it also removes important guardrails. Invalid options may only fail later or lead to unexpected behavior.
22+
Webpack adds a new top-level `validate` option and a `compiler.hooks.validate` hook that standardize how schema validation works across webpack configuration, plugins, and loaders.
2323

24-
This change also introduces an internal API so plugins can register validation through `compiler.hooks.validate` and run it with `compiler.validate(...)`, allowing validation behavior to be consistently controlled by the single `validate` flag.
24+
Until now, there was no unified way for plugins to integrate schema validation into the webpack build lifecycle. Each plugin handled validation on its own. The new `compiler.hooks.validate` hook gives plugin authors a standard API to register their validation logic, and `compiler.validate(...)` to run it. This means all validation (from webpack's core config to every plugin that adopts the hook) is controlled by a single `validate` flag and follows the same patterns:
2525

26-
**Defaults**
26+
```js
27+
module.exports = {
28+
// Disable schema validation (webpack config, plugins, and loaders)
29+
validate: false,
30+
};
31+
```
2732

28-
The default value of `validate` depends on the build mode and whether `experiments.futureDefaults` is enabled:
33+
The default value depends on the build mode:
2934

3035
| Mode | `experiments.futureDefaults` | Default `validate` |
3136
| ----------- | :--------------------------: | :----------------: |
@@ -34,18 +39,7 @@ The default value of `validate` depends on the build mode and whether `experimen
3439
| production | `false` | `true` |
3540
| production | `true` | `false` |
3641

37-
**Config example**
38-
39-
```js
40-
module.exports = {
41-
// Disable schema validation (webpack config, plugins, and loaders)
42-
validate: false,
43-
44-
// ...rest of config
45-
};
46-
```
47-
48-
**Plugin authoring example (respecting `validate: false`)**
42+
For plugin authors, integrating validation is straightforward. Register a tap on `compiler.hooks.validate`, and webpack takes care of the rest — including skipping validation entirely when the user sets `validate: false`:
4943

5044
```js
5145
class MyPlugin {
@@ -70,6 +64,10 @@ class MyPlugin {
7064
module.exports = MyPlugin;
7165
```
7266

67+
When `validate` is `true` and something is wrong, webpack throws a clear error at compile time.
68+
69+
When `validate` is `false`, that check is skipped entirely. The build may still fail later with a less obvious error, so use this option with care.
70+
7371
## CSS Modules with Runtime Style Injection
7472

7573
Webpack now supports `exportType: "style"` for CSS Modules (when `experiments.css: true` is enabled), which allows CSS to be injected into the DOM as a `<style>` (`HTMLStyleElement`) directly from the webpack runtime. This covers the typical use case of `style-loader`, so it is no longer necessary to use `style-loader` to inject styles when using this mode.

0 commit comments

Comments
 (0)