Skip to content

Conversation

jiangyanfu
Copy link

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>

…f the comment is `removeSingleIf(conditions)`
@brunoziie
Copy link

Hi, @jiangyanfu.

You forgot to update README.md with this changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants