Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

2 participants