Remove sections of code from files based on conditions
npm install @herdwatch/gulp-remove-code




> A Gulp plugin to remove sections of code from files based on conditions
``sh`
npm install gulp-remove-code --save-dev
`js
const 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/'))
`
` Removing code is easy.html`
`js
const 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.
`js
let value = JSON.stringify({key: 'value'});
//removeIf(production)
value = JSON.stringify({key: 'value', production: true}, null, 2);
//endRemoveIf(production)
//removeIf(!development)
value = JSON.stringify({key: 'value', development: false}, null, 2);
//endRemoveIf(!development)
`
`js
const 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.
Starting with version 2 of this plugin, conditions can also be expressed using the ! specifier.
`js
// Remove code using ! (negated) conditions
//----------- gulpfile.js -----------
//
const removeCode = require('gulp-remove-code');
gulp.src('./src/file.js')
.pipe(removeCode({ production: false }))
.pipe(gulp.dest('./dist'))
//----------- app-file.js -----------
//
//removeIf(!production)
value = JSON.stringify({key: 'value', production: false}, null, 2);
//endRemoveIf(!production)
`
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 end comment is defined.
MIT © Cristian Trifan