Skip to content

Commit 612f230

Browse files
docs: update hook filters and pluginutils API reference
(#8482)
1 parent 689c928 commit 612f230

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

docs/apis/plugin-api/hook-filters.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ See [`HookFilter`](/reference/Interface.HookFilter) as well.
8484

8585
For more complex filtering logic, Rolldown provides composable filter expressions via the [`@rolldown/pluginutils`](https://github.com/rolldown/rolldown/tree/main/packages/pluginutils) package. These allow you to build filters using logical operators like `and`, `or`, and `not`.
8686

87+
> [!WARNING]
88+
> Composable filters are not yet supported in legacy Vite or unplugin. They can be used in Rolldown/Rolldown-Vite/Vite Beta plugins only.
89+
90+
### Example
91+
8792
```js
8893
import { and, id, include, moduleType } from '@rolldown/pluginutils';
8994

@@ -101,6 +106,17 @@ export default function myPlugin() {
101106
}
102107
```
103108

109+
### Available Filter Functions
110+
111+
- `and(...exprs)` / `or(...exprs)` / `not(expr)` — Logical composition of filter expressions.
112+
- `id(pattern, params?)` — Filter by id. A `string` pattern is matched by exact equality (not glob); a `RegExp` is tested against the id.
113+
- `importerId(pattern, params?)` — Filter by importer id. A `string` pattern is matched by exact equality; a `RegExp` is tested against the importer id. Only usable with the `resolveId` hook.
114+
- `moduleType(type)` — Filter by module type (e.g. 'js', 'tsx', or 'json').
115+
- `code(pattern)` — Filter by code content.
116+
- `query(key, pattern)` — Filter by query parameter.
117+
- `include(expr)` / `exclude(expr)` — Top-level include/exclude wrappers.
118+
- `queries(obj)` — Compose multiple query filters.
119+
104120
See the [`@rolldown/pluginutils` README](https://github.com/rolldown/rolldown/tree/main/packages/pluginutils#readme) for the full API reference.
105121

106122
## Interoperability
@@ -148,7 +164,3 @@ This approach ensures your plugin will:
148164
### `moduleType` Filter
149165

150166
The [Module Type concept](/in-depth/module-types) does not exist in Rollup / Vite 7 and below. For that reason, the `moduleType` filter is not supported by those tools and will be ignored.
151-
152-
### Composable Filters
153-
154-
Composable filters are currently only supported in Rolldown. They are not yet supported in Vite, Rolldown-Vite, or unplugin.

packages/pluginutils/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ const myPlugin = {
7070
### Composable Filters
7171

7272
- `and(...exprs)` / `or(...exprs)` / `not(expr)` — Logical composition of filter expressions.
73-
- `id(pattern, params?)` — Filter by id (string or RegExp).
73+
- `id(pattern, params?)` — Filter by id. A `string` pattern is matched by exact equality (not glob); a `RegExp` is tested against the id.
74+
- `importerId(pattern, params?)` — Filter by importer id. A `string` pattern is matched by exact equality; a `RegExp` is tested against the importer id. Only usable with the `resolveId` hook.
7475
- `moduleType(type)` — Filter by module type (e.g. 'js', 'tsx', or 'json').
7576
- `code(pattern)` — Filter by code content.
7677
- `query(key, pattern)` — Filter by query parameter.
7778
- `include(expr)` / `exclude(expr)` — Top-level include/exclude wrappers.
7879
- `queries(obj)` — Compose multiple query filters.
80+
81+
### Utilities
82+
83+
- `filterVitePlugins(plugins)` — Filters out Vite plugins with `apply: 'serve'`.

0 commit comments

Comments
 (0)