rollup-plugin-re
Power rollup content transform plugin.
Installation
npm install --save-dev rollup-plugin-re
Usage
import { rollup } from 'rollup'
import replace from 'rollup-plugin-re'
import commonjs from 'rollup-plugin-commonjs'
rollup({
entry: 'main.js',
plugins: [
replace({
patterns: [
{
match: /formidable(\/|\\)lib/,
test: 'if (global.GENTLY) require = GENTLY.hijack(require);',
replace: '',
}
]
}),
commonjs(),
replace({
})
]
}).then(...)
Define macro pre-processor
use defines
options to remove macro blocks
Options
{
defines: {
IS_SKIP: false,
IS_REMOVE: true,
}
}
input
console.log('!Skip!')
console.log('!Remove!')
output
console.log('!Skip!')
Replace
use replaces
options to quick replace text
Options
{
replaces: {
$version: "1.0.1"
}
}
input
console.log('$version')
output
console.log('1.0.1')
Options
{
include: 'config.js',
exclude: 'node_modules/**',
defines: {
IS_SKIP: false,
IS_REMOVE: true,
},
replaces: {
$version: "1.0.1"
},
patterns: [
{
include: [],
exclude: [],
match: /formidable(\/|\\)lib/,
test: 'if (global.GENTLY) require = GENTLY.hijack(require);',
replace: '',
},
{
text: 'exports = "content"',
},
{
file: './replace.js',
},
{
transform (code, id) {
return `'use strict';\n${code}`
}
}
]
}