Skip to content

Browserify transform to remove code from a Browserify build using conditional comments.

License

Notifications You must be signed in to change notification settings

cinema6/conditionalify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conditionalify

Browserify transform to remove code using conditional comments. Comments are evaluated using angular-expressions.

Installation

$ npm install --save-dev conditionalify

Usage

Given the Following script.js:

var data = require('data.json');

/* #if someValue === 'foo' */
var result = require('foo-parser')(data);
/* #endif */
/* #if someValue !== 'foo' */
var result = require('other-parser')(data);
/* #endif */

console.log(result);

And the Following Usage:

CLI

$ browserify script.js -o bundle.js \
  -t [ conditionalify --context [ --someValue foo ] ]

Node

var fs = require('fs');
var browserify = require('browserify');
browserify('./script.js')
    .transform('conditionalify', {
        context: {
            someValue: 'foo'
        }
    })
    .bundle()
    .pipe(fs.createWriteStream('bundle.js'));

The Following Output Would be Produced:

var data = require('data.json');

/* #if someValue === 'foo' */
var result = require('foo-parser')(data);
/* #endif */
/* #if someValue !== 'foo' */
/* #endif */

console.log(result);

Options

The following configuration options are available (and are all optional):

  • context (Object): An Object whose keys will be available as variables in the comment expressions
  • marker (String): The character to look for at the start of a comment (before if or endif)—defaults to #
  • ecmaVersion (Number): Version of ECMAScript to pass to acorn when parsing each module
  • exts (Array of Strings): A whitelist of file extensions (without the leading ".")—if a file does not have one of the extensions in the list, it will be ignored by conditionalify—defaults to ['js']

Options may be passed in via standard browserify ways:

$ browserify -t [ conditionalify --marker @ ]
browserify().transform('conditionalify', { marker: '@' });
var conditionalify = require('conditionalify');
browserify().transform(conditionalify, { marker: '@' });

About

Browserify transform to remove code from a Browserify build using conditional comments.

Resources

License

Stars

Watchers

Forks

Packages

No packages published