string mutation plugin for rollup
# npm
npm install -D rollup-plugin-insert
# yarn
yarn add -D rollup-plugin-insert
import * as insert from 'rollup-plugin-insert'
All following methods has an optional last argument options
which is an object and contains key include
and exclude
.
It can be used to filter files as you like. For example you can wrapper your html template as following:
insert.transform(
(code, id) =>
`export default ${JSON.stringify(`<!--add some comments-->${code}`)}`,
{
include: '**/*.html',
},
)
Appends a string onto the contents.
insert.append('world') // Appends 'world' to the contents of every file
Prepends a string onto the contents.
insert.prepend('Hello') // Prepends 'Hello' to the contents of every file
Wraps the contents with two strings.
insert.wrap('Hello', 'World') // prepends 'hello' and appends 'world' to the contents
Calls a function with the contents of the file.
insert.transform((code, id) => code.toUpperCase())