rollup-plugin-strip-blocks
v1.0.3
Published
Rollup Strip Block ===================
Downloads
25
Maintainers
Readme
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()
]
}