1.0.12 • Published 4 years ago

rollup-plugin-scrub v1.0.12

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

rollup-plugin-scrub

Codacy Badge Build Status Coverage Status Known Vulnerabilities

Remove lines or sections of code based on custom-defined tags.

Install with NPM

npm i -D rollup-plugin-scrub

Usage example

If you have code that you want removed during the build process, place comments immediately before and after to identify the start and end points.

//!dev-code
const NOT_REQUIRED = 'Only needed during development.';
const REQUIRED = 'Always needed.';

function foo() {
  // Some code required in production build
}

//!dev-code-start
function bar() {
  // Some code only required during development
}
//!dev-code-end

Then in your Rollup config file, use the scrub plugin as follows.

// rollup.config.js
import scrub from 'rollup-plugin-scrub';

export default {
  input: './src/index.js',
  plugins: [
    scrub({
      tags: [
        // Remove the next line only
        { begin: '!dev-code' },
        // Remove all lines between beginning and end
        { begin: '!dev-code-start', end: '!dev-code-end' }
      ]
    })
  ]
};

The plugin options includes a "tags" property which should be provided with an array of tag objects.

Each tag object must have a "begin" property, and may also have an optional "end" property.

If only a "begin" tag is provided, only the line immediately following it will be removed. Otherwise, all lines between the start and end tags will be removed.

The example above will result in output code like this:

const REQUIRED = 'Always needed.';

function foo() {
  // Some code required in production build
}

Each tag should be on its own line (it doesn't matter if there's trailing white space). You can name them whatever you like, but they should only be included as // comments.

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago