Skip to content

Function: prefixRegex() ​

  • Exported from: rolldown/filter
  • Type: (str: string, flags?: string) => RegExp

Constructs a RegExp that matches a value that has the specified prefix.

This is useful for plugin hook filters.

Parameters ​

str ​

string

the string to match.

flags? ​

string

flags for the RegExp.

Returns ​

RegExp

Example ​

ts
import { prefixRegex } from '@rolldown/pluginutils';
const plugin = {
  name: 'plugin',
  resolveId: {
    filter: { id: prefixRegex('foo') },
    handler(id) {} // will only be called for IDs starting with `foo`
  }
}

Was this page helpful?