rollup-plugin-regexp
TypeScript icon, indicating that this package has built-in type declarations

5.0.1 • Public • Published

version license

🔎 rollup-plugin-regexp

Modify rollup output with find / replace dynamically.

Usage

pnpm add rollup-plugin-regexp -D

Explicit single using find, replace keys

import regexpPlugin from 'rollup-plugin-regexp'

export default {
  plugins: [
    regexpPlugin({
      find: String | RegExp,
      replace: String | Function,
    }),
  ],
}

Terse multiple using key, value

import regexpPlugin from 'rollup-plugin-regexp'

export default {
  plugins: [
    regexpPlugin({
      'find this text': 'replace with this here',
      'process.env.PORT': 5000,
    }),
  ],
}

find: String|RegExp

Supply a string or RegExp to find what you are looking for

replace: String|Function

Supply a string to directly replace what you've found, or a function to dynamically modify your findings

Example using String for both find and replace

regexpPlugin({
  find: 'eval',
  replace: 'lava',
})

Example using RegExp for find and a Function for replace

regexpPlugin({
  find: /svg\((.*?)\)/,
  replace: (match, path) => JSON.stringify(fs.readFileSync(path, 'utf8')),
})

Package Sidebar

Install

npm i rollup-plugin-regexp

Weekly Downloads

105

Version

5.0.1

License

MIT

Unpacked Size

9.66 kB

Total Files

7

Last publish

Collaborators

  • kingyue