@rolldown/pluginutils

中文文档
1.0.1发布于 2026/05/13MITES Module零依赖构建来源已验证近 30 天下载 7.3亿

Plugin utilities for Rolldown

原始使用文档
文档目录11 节
  1. Install
  2. Usage
  3. Regex helpers
  4. exactRegex
  5. prefixRegex
  6. makeIdFiltersToMatchWithQuery
  7. Composable filters
  8. Builders
  9. interpreter
  10. filterVitePlugins
  11. License

@rolldown/pluginutils npm

Plugin utilities for Rolldown.

Includes regex helpers for plugin hook filters, composable filter expressions, and a helper for filtering out Vite-serve-only plugins.

Install

pnpm add -D @rolldown/pluginutils

Usage

import { exactRegex, prefixRegex, makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils'

All filter helpers are also exposed via the /filter subpath:

import { and, or, id, include } from '@rolldown/pluginutils/filter'

Regex helpers

exactRegex

  • Type: (str: string, flags?: string) => RegExp

Constructs a RegExp that matches the exact string specified. Useful as a plugin hook filter.

import { exactRegex } from '@rolldown/pluginutils'

const plugin = {
  name: 'plugin',
  resolveId: {
    filter: { id: exactRegex('foo') },
    handler(id) {}, // only called for `foo`
  },
}

prefixRegex

  • Type: (str: string, flags?: string) => RegExp

Constructs a RegExp that matches values starting with the specified prefix.

import { prefixRegex } from '@rolldown/pluginutils'

const plugin = {
  name: 'plugin',
  resolveId: {
    filter: { id: prefixRegex('foo') },
    handler(id) {}, // called for IDs starting with `foo`
  },
}

makeIdFiltersToMatchWithQuery

  • Type: (input: string | RegExp | (string | RegExp)[]) => string | RegExp | (string | RegExp)[]

Converts an id filter so that it also matches ids that include a query string.

import { makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils'

const plugin = {
  name: 'plugin',
  transform: {
    filter: { id: makeIdFiltersToMatchWithQuery(['**/*.js', /\.ts$/]) },
    // Matches:
    //   foo.js, foo.js?foo, foo.txt?foo.js,
    //   foo.ts, foo.ts?foo, foo.txt?foo.ts
    handler(code, id) {},
  },
}

Composable filters

Composable filter expressions for use cases where a simple id/include/exclude is not enough. For example, when a plugin needs to combine id, moduleType, code, and query conditions.

import { and, code, id, include, interpreter, moduleType, or } from '@rolldown/pluginutils'

const expr = include(and(or(id(/\.tsx?$/), id(/\.jsx?$/)), moduleType('tsx'), code(/import React/)))

interpreter(expr, sourceCode, sourceId, 'tsx') // boolean

Builders

BuilderDescription
and(...exprs)All operands must match.
or(...exprs)At least one operand must match.
not(expr)Negates the operand.
id(pattern, params?)Match the module id. pattern is string or RegExp. params.cleanUrl strips the query/hash before matching.
importerId(pattern, params?)Match the importer's id. Same shape as id.
moduleType(type)Match Rolldown's module type ('js', 'jsx', 'ts', 'tsx', 'json', 'text', 'base64', 'dataurl', 'binary', 'empty', or a custom string).
code(pattern)Match the module source. string matches with includes; RegExp with test.
query(key, pattern)Match a single query parameter. pattern is boolean (key presence/truthiness), string (exact value), or RegExp (value pattern).
queries(obj)Shorthand for and(...) over multiple query entries.
include(expr)Top-level wrapper marking expr as an inclusion rule.
exclude(expr)Top-level wrapper marking expr as an exclusion rule.

interpreter

  • Type: (exprs, code?, id?, moduleType?, importerId?) => boolean

Evaluates one or more top-level expressions against the given inputs. Returns true when at least one include matches and no exclude matches; when no include is present, defaults to true unless an exclude matches.

The argument required by each expression must be provided. For example, evaluating an id(...) expression without passing id will throw.

filterVitePlugins

  • Type: <T>(plugins: T | T[] | null | undefined | false) => T[]

Removes Vite plugins that target the dev server (apply: 'serve') from a (possibly nested) plugin array. Plugins whose apply is a function are invoked with a command: 'build' context to decide. Useful when reusing a Vite plugin array inside a Rolldown config.

import { defineConfig } from 'rolldown'
import { filterVitePlugins } from '@rolldown/pluginutils'
import viteReact from '@vitejs/plugin-react'

export default defineConfig({
  plugins: filterVitePlugins([
    viteReact(),
    {
      name: 'dev-only',
      apply: 'serve', // filtered out
      // ...
    },
  ]),
})

License

MIT

版本与发布记录

@rolldown/pluginutils 共发布 124 个版本,首次发布于 2025/05/09;过去 12 个月发布了 33 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.1latest2026/05/135 个月前
1.0.02026/05/076 个月前
1.0.0-rc.182026/04/296 个月前
1.0.0-rc.172026/04/226 个月前
1.0.0-rc.162026/04/166 个月前
1.0.0-rc.152026/04/096 个月前

其他发布通道:nightly → 1.0.0-beta.13-commit.024b632,canary → 1.0.0-beta.31-commit.832324a。

关于 @rolldown/pluginutils 的常见问题

@rolldown/pluginutils 是什么?

Plugin utilities for Rolldown

如何安装 @rolldown/pluginutils?

在项目目录运行 npm install @rolldown/pluginutils,或使用 pnpm add / yarn add / bun add。

@rolldown/pluginutils 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/rolldown__pluginutils 是否存在。

@rolldown/pluginutils 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@rolldown/pluginutils 可以商用吗?

@rolldown/pluginutils 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@rolldown/pluginutils 的下载量有多少?

根据 npm 官方下载统计,@rolldown/pluginutils 在 2026/10/07 – 2026/11/05 这 30 天内被下载 729,816,617 次,日均约 24,327,221 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@rolldown/pluginutils 还在维护吗?

最新版本 1.0.1 发布于 2026/05/13(5 个月前);至今共发布 124 个版本,其中过去 12 个月发布了 33 个;首次发布于 2025/05/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。