gulp-remove-code
A Gulp plugin to remove sections of code from files based on conditions
Install
npm install --save-dev gulp-remove-code
Usage
var removeCode = require('gulp-remove-code');
gulp.src('./src/*.js')
.pipe(removeCode({ noDevFeatures: true }))
.pipe(gulp.dest('./dist/'))
gulp.src('./src/*.js')
.pipe(removeCode({ noDevFeatures: true, commentStart: '/*', commentEnd: '*/' }))
.pipe(gulp.dest('./dist/'))
gulp.src('./src/*.coffee')
.pipe(removeCode({ noDevFeatures: true }))
.pipe(gulp.dest('./dist/'))
Examples
Remove code from HTML files
<div>
<!--removeIf(production)-->
<div class="sandbox-banner">Running in sandbox environment</div>
<!--endRemoveIf(production)-->
<span>Removing code is ready.</span>
</div>
var removeCode = require('gulp-remove-code');
gulp.src('./src/file.html')
.pipe(removeCode({ production: true }))
.pipe(gulp.dest('./dist'))
The plugin will remove the code inside the comments, as well as the comments.
Remove code JavaScript files
var value = JSON.stringify({key: 'value'});
//removeIf(production)
value = JSON.stringify({key: 'value'}, null, 2);
//endRemoveIf(production)
var removeCode = require('gulp-remove-code');
gulp.src('./src/file.js')
.pipe(removeCode({ production: true }))
.pipe(gulp.dest('./dist'))
The plugin will remove the code inside the comments, as well as the comments.
API
removeCode([options])
options
Type: Object
A key value pair map to specify what code should be removed. The truthy values will remove the code.
options.commentStart
Type: String
Default: Detected from file extension. Use // as fallback.
Configure how the start comment is defined.
options.commentEnd
Type: String
Default: Detected from file extension. Use empty as fallback.
Configure how the start comment is defined.
License
MIT © Cristian Trifan