gulp-remove-code icon indicating copy to clipboard operation
gulp-remove-code copied to clipboard

Remove a single line of code with a single line comment.

Open jiangyanfu opened this issue 6 years ago • 1 comments

Remove a single line of code with a single line comment. The format of the comment is commentStart + removeSingleIf(conditions) + commentEnd Example Remove code from JavaScript files

let value = JSON.stringify({key: 'value'}); //removeSingleIf(production)
 
//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)
const removeCode = require('gulp-remove-code');
 
gulp.src('./src/file.js')
  .pipe(removeCode({ production: true }))
  .pipe(gulp.dest('./dist'))

Then, the code will change to:

//removeIf(!development)
value = JSON.stringify({key: 'value', development: false}, null, 2);
//endRemoveIf(!development)

Remove code from HTML files

<div>
    <!--removeIf(production)-->
    <div class="sandbox-banner">Running in sandbox environment</div>
    <!--endRemoveIf(production)-->
    <span>Removing single line code is easy.</span>
    <span>Removing single line code is easy.</span> <!--removeSingleIf(production)-->
</div>

Then, the code will change to:

<div>
    <span>Removing single line code is easy.</span>
</div>

jiangyanfu avatar Jul 25 '18 05:07 jiangyanfu

Hi, @jiangyanfu.

You forgot to update README.md with this changes.

brunoziie avatar Oct 17 '19 18:10 brunoziie