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

1.3.2 • Public • Published

rollup-plugin-insert

npm David Peer David

string mutation plugin for Rollup

Usage

# npm
npm install -D rollup-plugin-insert

# yarn
yarn add -D rollup-plugin-insert
// all of following is fine
import * as insert from 'rollup-plugin-insert'
import insert from 'rollup-plugin-insert'
import { append, prepend, wrap, transform } from 'rollup-plugin-insert'

const insert = require('rollup-plugin-insert')

Common Usage

All following methods have an optional last argument options which is an object and contains key include, exclude and sourceMap which is enabled by default.

It can be used to filter files as you like. For example you can wrapper your html template as following:

insert.transform(
  (magicString, code, id) =>
    `export default ${JSON.stringify(`<!--add some comments-->${code}`)}`,
  {
    include: '**/*.html',
  },
)

If you do not need sourceMap at all, just change it to be false.

Append

Appends a string onto the contents.

insert.append('world') // Appends 'world' to the contents of every file

Prepend

Prepends a string onto the contents.

insert.prepend('Hello') // Prepends 'Hello' to the contents of every file

Wrap

Wraps the contents with two strings.

insert.wrap('Hello', 'World') // prepends 'hello' and appends 'world' to the contents

Transform

Calls a function with the contents of the file.

insert.transform((magicString, code, id) => code.toUpperCase()) // should return a string or MagicString

Readme

Keywords

none

Package Sidebar

Install

npm i rollup-plugin-insert

Weekly Downloads

1,473

Version

1.3.2

License

MIT

Unpacked Size

20.1 kB

Total Files

14

Last publish

Collaborators

  • jounqin
  • i1stg