rollup-plugin-strip-blocks

1.0.3 • Public • Published

Rollup Strip Block

Rollup plugin to strip blocks of code marked by special comment tags. Useful for removing code that you don't want in your production bundle (e.g. verbose console warnings, etc).

Install:

$ npm install --save-dev rollup-plugin-strip-blocks

or

$ yarn add -D rollup-plugin-strip-blocks

Example:

In your client js source files:

 
var makeFoo(bar, baz) {
    // The following code will be stripped with our plugin
    /* develblock:start */
    if (bar instanceof Bar !== true) {
        throw new Error('makeFoo: bar param is required and must be instance of Bar');
    }
    /* develblock:end */
 
    // This code would remain
    return new Foo(bar, baz);
}
 

In your rollup config, specify the plugin:

// rollup.config.js
import babel from 'rollup-plugin-babel'
import stripblocks from 'rollup-plugin-strip-blocks'
 
export default {
    entry: 'src/main.js',
    dest: 'dist/app.js',
    format: 'iife',
    plugins: [
        stripblocks(),
        babel()
    ]
}

If you want to use custom comment tags to mark the start and end of the block to strip from your code, you can add options for "start" and "end" like this:

// rollup.config.js
import babel from 'rollup-plugin-babel'
import stripblocks from 'rollup-plugin-strip-blocks'
 
export default {
    entry: 'src/main.js',
    dest: 'dist/app.js',
    format: 'iife',
    plugins: [
        stripblocks({
            start: 'DEV-START',
            end: 'DEV-END'
        }),
        babel()
    ]
}

Package Sidebar

Install

npm i rollup-plugin-strip-blocks

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

13.8 kB

Total Files

4

Last publish

Collaborators

  • david_bindloss