Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rollup-plugin-insert

rx-ts14.6kMIT1.3.2TypeScript support: included

string mutation plugin for Rollup

readme

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

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.3.2 (2021-03-13)

Note: Version bump only for package rollup-plugin-insert

1.3.1 (2020-04-10)

Note: Version bump only for package rollup-plugin-insert

1.3.0 (2020-01-29)

Features

  • migrate to lerna monorepo (e6e8877)

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.2.0 (2020-01-29)

1.0.0

  • Enable sourceMap support (#39 @danielgindi)
  • Support return string or MagicString after transforming
  • fix failed test cases, add more test cases
  • all test coverage indicators reach 100%
  • bump all dependencies

1.0.1

  • add more module import usages
  • fix transform usage in README
  • build on CI for testing

1.1.0

  • migrate code base to TypeScript :tada: