diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6c8b525aa..eb545ec22 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,19 @@
# rollup changelog
+## 4.38.0
+
+_2025-03-29_
+
+### Features
+
+- Support `.filter` option in `resolveId`, `load` and `transform` hooks (#5882)
+
+### Pull Requests
+
+- [#5882](https://github.com/rollup/rollup/pull/5882): Add support for hook filters (@sapphi-red)
+- [#5894](https://github.com/rollup/rollup/pull/5894): fix(deps): lock file maintenance minor/patch updates (@renovate[bot])
+- [#5895](https://github.com/rollup/rollup/pull/5895): chore(deps): update dependency eslint-plugin-unicorn to v58 (@renovate[bot])
+
## 4.37.0
_2025-03-23_
diff --git a/browser/LICENSE.md b/browser/LICENSE.md
index b589d68c9..c95d54d64 100644
--- a/browser/LICENSE.md
+++ b/browser/LICENSE.md
@@ -134,3 +134,32 @@ Repository: https://github.com/rich-harris/magic-string
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+---------------------------------------
+
+## picomatch
+License: MIT
+By: Jon Schlinkert
+Repository: micromatch/picomatch
+
+> The MIT License (MIT)
+>
+> Copyright (c) 2017-present, Jon Schlinkert.
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+> THE SOFTWARE.
diff --git a/browser/package.json b/browser/package.json
index 3997cf712..20516d24c 100644
--- a/browser/package.json
+++ b/browser/package.json
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
- "version": "4.37.0",
+ "version": "4.38.0",
"description": "Next-generation ES module bundler browser build",
"main": "dist/rollup.browser.js",
"module": "dist/es/rollup.browser.js",
diff --git a/docs/plugin-development/index.md b/docs/plugin-development/index.md
index 3b3ad38e8..3d9669db6 100644
--- a/docs/plugin-development/index.md
+++ b/docs/plugin-development/index.md
@@ -93,7 +93,7 @@ export default ({
- `sequential`:如果有多个插件实现此钩子,则所有这些钩子将按指定的插件顺序运行。如果钩子是 `async`,则此类后续钩子将等待当前钩子解决后再运行。
- `parallel`:如果有多个插件实现此钩子,则所有这些钩子将按指定的插件顺序运行。如果钩子是 `async`,则此类后续钩子将并行运行,而不是等待当前钩子。
-除了函数之外,钩子也可以是对象。在这种情况下,实际的钩子函数(或 `banner/footer/intro/outro` 的值)必须指定为 `handler`。这允许你提供更多的可选属性,以改变钩子的执行:
+除了函数之外,钩子也可以是对象。在这种情况下,实际的钩子函数(或 `banner/footer/intro/outro` 的值)必须指定为 `handler`。这允许你提供更多的可选属性,以改变或跳过钩子的执行:
- `order: "pre" | "post" | null`
如果有多个插件实现此钩子,则可以先运行此插件(`"pre"`),最后运行此插件(`"post"`),或在用户指定的位置运行(没有值或 `null`)。
@@ -145,6 +145,42 @@ export default ({
}
```
+- `filter`
仅当指定的过滤器返回真值时,才运行此插件钩子。这个属性只对 `resolveId`,`load`,`transform` 可用。`code` 过滤器只对 `transform` 钩子可用。`id` 过滤器,除了 `resolveId` 钩子,支持 [picomatch 模式](https://github.com/micromatch/picomatch#globbing-features)。
+
+ ```ts
+ type StringOrRegExp = string | RegExp;
+ type StringFilter =
+ | MaybeArray
+ | {
+ include?: MaybeArray;
+ exclude?: MaybeArray;
+ };
+
+ interface HookFilter {
+ id?: StringFilter;
+ code?: StringFilter;
+ }
+ ```
+
+ ```js twoslash
+ /** @returns {import('rollup').Plugin} */
+ // ---cut---
+ export default function jsxAdditionalTransform() {
+ return {
+ name: 'jsxAdditionalTransform',
+ transform: {
+ filter: {
+ id: '*.jsx',
+ code: ' here
+ }
+ }
+ };
+ }
+ ```
+
构建钩子在构建阶段运行,该阶段由 `rollup.rollup(inputOptions)` 触发。它们主要涉及在 Rollup 处理输入文件之前定位、提供和转换输入文件。构建阶段的第一个钩子是 [`options`](#options),最后一个钩子始终是 [`buildEnd`](#buildend)。如果有构建错误,则在此之后将调用 [`closeBundle`](#closebundle)。