diff --git a/src/content/blog/2026-04-08-webpack-5-106.mdx b/src/content/blog/2026-04-08-webpack-5-106.mdx new file mode 100644 index 000000000000..4c94088764ff --- /dev/null +++ b/src/content/blog/2026-04-08-webpack-5-106.mdx @@ -0,0 +1,320 @@ +--- +title: Webpack 5.106 +sort: 20260408 +contributors: + - bjohansebas +--- + +**Webpack 5.106 introduces plugin validation hooks, built-in runtime style injection for CSS Modules, smarter tree shaking for CommonJS destructuring, source-phase imports for WebAssembly modules, and an experimental integration with `oxc-parser` for faster JavaScript parsing.** + +Explore what's new in this release: + +- [**Plugin Validation with `compiler.hooks.validate`**](#plugin-validation-with-compilerhooksvalidate) +- [**CSS Modules with Runtime Style Injection**](#css-modules-with-runtime-style-injection) +- [**Better Tree Shaking for CommonJS Destructuring**](#better-tree-shaking-for-commonjs-destructuring) +- [**Source Phase Imports for WebAssembly (Experimental)**](#source-phase-imports-for-webassembly-experimental) +- [**Getting Started with `create-webpack-app`**](#getting-started-with-create-webpack-app) +- [**Context Support for VirtualUrlPlugin**](#context-support-for-virtualurlplugin) +- [**Experimental JavaScript Parsing with `oxc-parser`**](#experimental-javascript-parsing-with-oxc-parser) +- [**Ecosystem Updates**](#ecosystem-updates) +- [**Bug Fixes**](#bug-fixes) + +## Plugin Validation with `compiler.hooks.validate` + +Webpack adds a new top-level `validate` option and a [`compiler.hooks.validate`](/api/compiler-hooks/#validate) hook that standardize how schema validation works across webpack configuration, plugins, and loaders. + +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: + +```js +module.exports = { + // Disable schema validation (webpack config, plugins, and loaders) + validate: false, +}; +``` + +The default value depends on the build mode: + +| Mode | `experiments.futureDefaults` | Default `validate` | +| ----------- | :--------------------------: | :----------------: | +| development | `false` | `true` | +| development | `true` | `true` | +| production | `false` | `true` | +| production | `true` | `false` | + +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`: + +```js +class MyPlugin { + constructor(options = {}) { + this.options = options; + } + + apply(compiler) { + compiler.hooks.validate.tap("MyPlugin", () => { + compiler.validate( + () => require("./schema/MyPlugin.json"), + this.options, + { name: "My Plugin", baseDataPath: "options" }, + (options) => require("./schema/MyPlugin.check")(options), + ); + }); + + // ...normal plugin logic here... + } +} + +module.exports = MyPlugin; +``` + +When `validate` is `true` and something is wrong, webpack throws a clear error at compile time. + +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. + +## CSS Modules with Runtime Style Injection + +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 `