Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including rollup-plugin-strip-blocks with all npm packages installed. Try it out:

var rollupPluginStripBlocks = require("rollup-plugin-strip-blocks")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

rollup-plugin-strip-blocks v1.0.3

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()
    ]
}
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free