From e28f459923d60b4489efa235a97ac6d6826cc210 Mon Sep 17 00:00:00 2001 From: Hai Date: Tue, 8 Sep 2026 18:03:07 +0800 Subject: [PATCH] docs: correct plugin option defaults, signatures and removed CLI flags --- src/content/configuration/module.mdx | 2 +- src/content/plugins/NoEmitOnErrorsPlugin.mdx | 2 +- src/content/plugins/banner-plugin.mdx | 2 +- .../plugins/context-replacement-plugin.mdx | 2 +- src/content/plugins/define-plugin.mdx | 2 +- src/content/plugins/dll-plugin.mdx | 10 +- src/content/plugins/environment-plugin.mdx | 3 + .../eval-source-map-dev-tool-plugin.mdx | 14 +-- .../plugins/hashed-module-ids-plugin.mdx | 6 +- .../plugins/hot-module-replacement-plugin.mdx | 6 +- src/content/plugins/index.mdx | 2 +- src/content/plugins/internal-plugins.mdx | 64 +++++------ .../plugins/limit-chunk-count-plugin.mdx | 8 -- .../plugins/merge-duplicate-chunks-plugin.mdx | 4 +- src/content/plugins/min-chunk-size-plugin.mdx | 8 -- .../plugins/module-concatenation-plugin.mdx | 5 +- .../plugins/module-federation-plugin.mdx | 5 +- .../normal-module-replacement-plugin.mdx | 2 +- src/content/plugins/progress-plugin.mdx | 62 +++++++---- .../plugins/source-map-dev-tool-plugin.mdx | 2 +- src/content/plugins/split-chunks-plugin.mdx | 105 +++++++++++------- src/content/plugins/virtual-url-plugin.mdx | 4 +- 22 files changed, 172 insertions(+), 148 deletions(-) diff --git a/src/content/configuration/module.mdx b/src/content/configuration/module.mdx index 3aaeb8913317..ed1b576c7486 100644 --- a/src/content/configuration/module.mdx +++ b/src/content/configuration/module.mdx @@ -1982,7 +1982,7 @@ export default { `string` -Specify the layer in which the module should be placed in. A group of modules could be united in one layer which could then be used in [split chunks](/plugins/split-chunks-plugin/#splitchunkslayer), [stats](/configuration/stats/#statsgroupmodulesbylayer) or [entry options](/configuration/entry-context/#entry-descriptor). +Specify the layer in which the module should be placed in. A group of modules could be united in one layer which could then be used in [split chunks](/plugins/split-chunks-plugin/#splitchunkscachegroupscachegrouplayer), [stats](/configuration/stats/#statsgroupmodulesbylayer) or [entry options](/configuration/entry-context/#entry-descriptor). **webpack.config.js** diff --git a/src/content/plugins/NoEmitOnErrorsPlugin.mdx b/src/content/plugins/NoEmitOnErrorsPlugin.mdx index 3f771ac81cf9..cad219ae8edb 100644 --- a/src/content/plugins/NoEmitOnErrorsPlugin.mdx +++ b/src/content/plugins/NoEmitOnErrorsPlugin.mdx @@ -8,7 +8,7 @@ contributors: - snitin315 --- -The `NoEmitOnErrorsPlugin` allows you to avoid emitting assets when there are any errors. Enabled by default, you can disable using [`optimization.emitOnErrors`](/configuration/optimization/#optimizationemitonerrors) +The `NoEmitOnErrorsPlugin` allows you to avoid emitting assets when there are any errors. It is enabled by default in `production` mode, where [`optimization.emitOnErrors`](/configuration/optimization/#optimizationemitonerrors) defaults to `false`; use that option to enable or disable it. **webpack.config.js** diff --git a/src/content/plugins/banner-plugin.mdx b/src/content/plugins/banner-plugin.mdx index 64f4ba65c905..d2fa80bf5834 100644 --- a/src/content/plugins/banner-plugin.mdx +++ b/src/content/plugins/banner-plugin.mdx @@ -69,6 +69,6 @@ import webpack from "webpack"; new webpack.BannerPlugin({ banner: - "fullhash:[fullhash], chunkhash:[chunkhash], name:[name], filebase:[filebase], query:[query], file:[file]", + "fullhash:[fullhash], chunkhash:[chunkhash], name:[name], base:[base], query:[query], file:[file]", }); ``` diff --git a/src/content/plugins/context-replacement-plugin.mdx b/src/content/plugins/context-replacement-plugin.mdx index 3a6a9821744b..9706c896bbad 100644 --- a/src/content/plugins/context-replacement-plugin.mdx +++ b/src/content/plugins/context-replacement-plugin.mdx @@ -29,7 +29,7 @@ new webpack.ContextReplacementPlugin( ) ``` -If the resource (directory) matches `resourceRegExp`, the plugin replaces the default resource, recursive flag or generated regular expression with `newContentResource`, `newContentRecursive` or `newContextRegExp` respectively. If `newContentResource` is relative, it is resolved relative to the previous resource. +If the resource (directory) matches `resourceRegExp`, the plugin replaces the default resource, recursive flag or generated regular expression with `newContentResource`, `newContentRecursive` or `newContentRegExp` respectively. If `newContentResource` is relative, it is resolved relative to the previous resource. Here's a small example to restrict module usage: diff --git a/src/content/plugins/define-plugin.mdx b/src/content/plugins/define-plugin.mdx index 6e2765b34b17..c3590988cfe3 100644 --- a/src/content/plugins/define-plugin.mdx +++ b/src/content/plugins/define-plugin.mdx @@ -108,7 +108,7 @@ It is possible to define variables with values that rely on files and will be re There're two arguments for `webpack.DefinePlugin.runtimeValue` function: -- The first argument is a `function(module, key, version)` that should return the value to be assigned to the definition. +- The first argument is a `function({ module, key, version })` that should return the value to be assigned to the definition. - The second argument could either be an array of file paths to watch for or a `true` to flag the module as uncacheable. Since 5.26.0, it can also take an object argument with the following properties: - `fileDependencies?: string[]` A list of files the function depends on. - `contextDependencies?: string[]` A list of directories the function depends on. diff --git a/src/content/plugins/dll-plugin.mdx b/src/content/plugins/dll-plugin.mdx index c03ab55dc458..6e34e47bed1d 100644 --- a/src/content/plugins/dll-plugin.mdx +++ b/src/content/plugins/dll-plugin.mdx @@ -127,11 +127,11 @@ T> Multiple `DllPlugins` and multiple `DllReferencePlugins`. ### Source -- [DllPlugin source](https://github.com/webpack/webpack/blob/main/lib/DllPlugin.js) -- [DllReferencePlugin source](https://github.com/webpack/webpack/blob/main/lib/DllReferencePlugin.js) -- [DllEntryPlugin source](https://github.com/webpack/webpack/blob/main/lib/DllEntryPlugin.js) -- [DllModuleFactory source](https://github.com/webpack/webpack/blob/main/lib/DllModuleFactory.js) -- [ManifestPlugin source](https://github.com/webpack/webpack/blob/main/lib/LibManifestPlugin.js) +- [DllPlugin source](https://github.com/webpack/webpack/blob/main/lib/dll/DllPlugin.js) +- [DllReferencePlugin source](https://github.com/webpack/webpack/blob/main/lib/dll/DllReferencePlugin.js) +- [DllEntryPlugin source](https://github.com/webpack/webpack/blob/main/lib/dll/DllEntryPlugin.js) +- [DllModuleFactory source](https://github.com/webpack/webpack/blob/main/lib/dll/DllModuleFactory.js) +- [ManifestPlugin source](https://github.com/webpack/webpack/blob/main/lib/dll/LibManifestPlugin.js) ### Tests diff --git a/src/content/plugins/environment-plugin.mdx b/src/content/plugins/environment-plugin.mdx index e3aa128bb054..382763484246 100644 --- a/src/content/plugins/environment-plugin.mdx +++ b/src/content/plugins/environment-plugin.mdx @@ -25,6 +25,9 @@ This is equivalent to the following `DefinePlugin` application: new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV), "process.env.DEBUG": JSON.stringify(process.env.DEBUG), + // since webpack 5.103.0 + "import.meta.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV), + "import.meta.env.DEBUG": JSON.stringify(process.env.DEBUG), }); ``` diff --git a/src/content/plugins/eval-source-map-dev-tool-plugin.mdx b/src/content/plugins/eval-source-map-dev-tool-plugin.mdx index c16469412fee..bd29f54d5a3c 100644 --- a/src/content/plugins/eval-source-map-dev-tool-plugin.mdx +++ b/src/content/plugins/eval-source-map-dev-tool-plugin.mdx @@ -23,28 +23,20 @@ This plugin enables more fine grained control of source map generation. It is al new webpack.EvalSourceMapDevToolPlugin(options); ``` -This plugin wraps every module in an `eval()` call with its source map appended as a data URL, so no `.map` files are emitted. It accepts the same options object as the [`SourceMapDevToolPlugin`](/plugins/source-map-dev-tool-plugin/), but the options that describe a separate source map file — `filename`, `fileContext` and `publicPath` — have nothing to name here and are ignored. +This plugin wraps every module in an `eval()` call with its source map appended as a data URL, so no `.map` files are emitted. It accepts the same options object as the [`SourceMapDevToolPlugin`](/plugins/source-map-dev-tool-plugin/), but the options that describe a separate source map file — `filename`, `fileContext` and `publicPath` — have nothing to name here and are ignored, as is a function-valued `append`. ## Options The following options are supported: -- `test` (`string` `RegExp` `function (module) => boolean` `[string, RegExp, function (module) => boolean]`): Generate source maps for modules whose path matches the given value. It matches the module's own path, not the name of the chunk it ends up in, so it cannot be used to exclude a whole entry point or bundle. +- `test` (`string` `RegExp` `function (module) => boolean` `[string, RegExp, function (module) => boolean]`): Generate source maps for modules whose path matches the given value. There is no default: all modules get source maps unless `test`, `include` or `exclude` restrict them. It matches the module's own path, not the name of the chunk it ends up in, so it cannot be used to exclude a whole entry point or bundle. - `include` (`string` `RegExp` `function (module) => boolean` `[string, RegExp, function (module) => boolean]`): Include source maps for module paths that match the given value. - `exclude` (`string` `RegExp` `function (module) => boolean` `[string, RegExp, function (module) => boolean]`): Exclude modules that match the given value from source map generation. -- `append` (`string|function`): Appends the given value to the original asset. Usually the `#sourceMappingURL` comment. `[url]` is replaced with a URL to the source map file. - - Starting from version 5.84.0, webpack allows the `append` option to be a function that accepts path data and an asset info object as arguments, and returns a string. - - ```ts - (pathData: PathData, assetInfo?: AssetInfo) => string; - ``` - +- `append` (`string`): Appends the given value to the original asset. Usually the `#sourceMappingURL` comment. `[url]` is replaced with a URL to the source map file. - `ignoreList` (`string` `RegExp` `function (source) => boolean` `[string, RegExp, function (source) => boolean]`): Decide whether to ignore source files that match the specified value in source maps. - `module` (`boolean`): Indicates whether loaders should generate source maps (defaults to `true`). - `moduleFilenameTemplate` (`string`): See [`output.devtoolModuleFilenameTemplate`](/configuration/output/#outputdevtoolmodulefilenametemplate). - `columns` (`boolean`): Indicates whether column mappings should be used (defaults to `true`). -- `protocol` (`string`): Allows user to override default protocol (`webpack-internal://`) - `namespace` (`string`): Namespace prefix to allow multiple webpack roots in the devtools. See [`output.devtoolNamespace`](/configuration/output/#outputdevtoolnamespace). - `noSources = false` (`boolean`): Prevents the source file content from being included in the source map. - `sourceRoot` (`string`): Provide a custom value for the `sourceRoot` property in source maps. diff --git a/src/content/plugins/hashed-module-ids-plugin.mdx b/src/content/plugins/hashed-module-ids-plugin.mdx index 9fcf5923d269..f923d68b6dfc 100644 --- a/src/content/plugins/hashed-module-ids-plugin.mdx +++ b/src/content/plugins/hashed-module-ids-plugin.mdx @@ -24,9 +24,9 @@ This plugin supports the following options: - `hashFunction`: The hashing algorithm to use, defaults to `'md4'`. All functions from Node.JS' [`crypto.createHash`](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options) are supported. - `hashDigest`: The encoding to use when generating the hash, defaults to `'base64'`. All encodings from Node.JS' [`hash.digest`](https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding) are supported. - + - In addition to standard Node.js encodings, webpack also supports custom digest algorithms: `'base64url'`, `'base62'`, `'base58'`, `'base52'`, `'base49'`, `'base36'`, `'base32'`, and `'base25'`. These are useful for generating shorter or URL-safe hash values. + In addition to standard Node.js encodings, this plugin also supports `'base64url'`, which is useful for generating URL-safe hash values. The custom bases (`'base26'`, `'base32'`, `'base36'`, `'base49'`, `'base52'`, `'base58'`, `'base62'`) are only available for [`output.hashDigest`](/configuration/output/#outputhashdigest). - `hashDigestLength`: The prefix length of the hash digest to use, defaults to `4`. Note that some generated ids might be longer than specified here, to avoid module id collisions. @@ -49,7 +49,7 @@ new webpack.ids.HashedModuleIdsPlugin({ }); ``` -**Using URL-safe encoding (5.104.0+):** +**Using URL-safe encoding (5.102.1+):** ```js import path from "node:path"; diff --git a/src/content/plugins/hot-module-replacement-plugin.mdx b/src/content/plugins/hot-module-replacement-plugin.mdx index 8f12ed1d52eb..1998fef874f2 100644 --- a/src/content/plugins/hot-module-replacement-plugin.mdx +++ b/src/content/plugins/hot-module-replacement-plugin.mdx @@ -20,10 +20,8 @@ W> HMR should **never** be used in production. ## Basic Usage -Enabling HMR is straightforward and in most cases no options are necessary. +Enabling HMR is straightforward; the plugin takes no options. ```js -new webpack.HotModuleReplacementPlugin({ - // Options... -}); +new webpack.HotModuleReplacementPlugin(); ``` diff --git a/src/content/plugins/index.mdx b/src/content/plugins/index.mdx index c49d4e4b279e..76a90bff8d18 100644 --- a/src/content/plugins/index.mdx +++ b/src/content/plugins/index.mdx @@ -33,7 +33,7 @@ T> CSS and HTML are built in (experimental), so neither needs a plugin here. The | [`EnvironmentPlugin`](/plugins/environment-plugin) | Shorthand for using the [`DefinePlugin`](/plugins/define-plugin) on `process.env` keys | | [`HotModuleReplacementPlugin`](/plugins/hot-module-replacement-plugin) | Enable Hot Module Replacement (HMR) | | [`IgnorePlugin`](/plugins/ignore-plugin) | Exclude certain modules from bundles | -| [`LimitChunkCountPlugin`](/plugins/limit-chunk-count-plugin) | Set min/max limits for chunking to better control chunking | +| [`LimitChunkCountPlugin`](/plugins/limit-chunk-count-plugin) | Limit the maximum number of chunks by merging them | | [`MergeDuplicateChunksPlugin`](/plugins/merge-duplicate-chunks-plugin) | Merge chunks that contain the same modules | | [`MinChunkSizePlugin`](/plugins/min-chunk-size-plugin) | Keep chunk size above the specified limit | | [`NoEmitOnErrorsPlugin`](/configuration/optimization/#optimizationemitonerrors) | Skip the emitting phase when there are compilation errors | diff --git a/src/content/plugins/internal-plugins.mdx b/src/content/plugins/internal-plugins.mdx index 4ced73996071..e7245ba85ba6 100644 --- a/src/content/plugins/internal-plugins.mdx +++ b/src/content/plugins/internal-plugins.mdx @@ -75,17 +75,17 @@ Prefetches `request` and dependencies to enable a more parallel compilation. It ### JsonpTemplatePlugin -`JsonpTemplatePlugin(options)` +`web/JsonpTemplatePlugin()` Chunks are wrapped into JSONP-calls. A loading algorithm is included in entry chunks. It loads chunks by adding a `