Giter Club home page Giter Club logo

gulp-remove-code's Introduction

gulp-remove-code

JavaScript Style Guide npm version Build Status Build status Dependency Status

A Gulp plugin to remove sections of code from files based on conditions

Install

npm install gulp-remove-code --save-dev

Usage

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/'))

Examples

Remove code from HTML files

<div>
  <!--removeIf(production)-->
  <div class="sandbox-banner">Running in sandbox environment</div>
  <!--endRemoveIf(production)-->

  <span>Removing code is easy.</span>
</div>
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.

Remove code JavaScript files

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)
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.

Advanced usage

Starting with version 2 of this plugin, conditions can also be expressed using the ! specifier.

// 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)

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 end comment is defined.

License

MIT © Cristian Trifan

gulp-remove-code's People

Contributors

crissdev avatar codeman99 avatar timothydsmith avatar chrilith avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.