Modify rollup output with find / replace dynamically
npm install rollup-plugin-regexprollup-plugin-regexpbash
pnpm add rollup-plugin-regexp -D
`
Explicit single using find, replace keys
`js
import regexpPlugin from 'rollup-plugin-regexp'
export default {
plugins: [
regexpPlugin({
find: String | RegExp,
replace: String | Function,
}),
],
}
`
Terse multiple using key, value
`js
import regexpPlugin from 'rollup-plugin-regexp'
export default {
plugins: [
regexpPlugin({
'find this text': 'replace with this here',
'process.env.PORT': 5000,
}),
],
}
`
$3
Supply a string or RegExp to find what you are looking for
$3
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
`js
regexpPlugin({
find: 'eval',
replace: 'lava',
})
`
#### Example using RegExp for find and a Function for replace
`js
regexpPlugin({
find: /svg\((.*?)\)/,
replace: (match, path) => JSON.stringify(fs.readFileSync(path, 'utf8')),
})
``