You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/blog/2026-03-22-webpack-5-106.mdx
+14-16Lines changed: 14 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,13 +19,18 @@ Explore what's new in this release:
19
19
20
20
## Plugin Validation with `compiler.hooks.validate`
21
21
22
-
Webpack adds a new toplevel `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.
23
23
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:
25
25
26
-
**Defaults**
26
+
```js
27
+
module.exports= {
28
+
// Disable schema validation (webpack config, plugins, and loaders)
29
+
validate:false,
30
+
};
31
+
```
27
32
28
-
The default value of `validate`depends on the build mode and whether `experiments.futureDefaults` is enabled:
@@ -34,18 +39,7 @@ The default value of `validate` depends on the build mode and whether `experimen
34
39
| production |`false`|`true`|
35
40
| production |`true`|`false`|
36
41
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`:
49
43
50
44
```js
51
45
classMyPlugin {
@@ -70,6 +64,10 @@ class MyPlugin {
70
64
module.exports= MyPlugin;
71
65
```
72
66
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
+
73
71
## CSS Modules with Runtime Style Injection
74
72
75
73
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