conditionalify
Browserify transform to remove code using conditional comments. Comments are evaluated using angular-expressions
.
Installation
$ npm install --save-dev conditionalify
Usage
script.js
:
Given the Following var data = ; /* #if someValue === 'foo' */var result = data;/* #endif *//* #if someValue !== 'foo' */var result = data;/* #endif */ console;
And the Following Usage:
CLI
$ browserify script.js -o bundle.js \ -t [ conditionalify --context [ --someValue foo ] ]
Node
var fs = ;var browserify = ; ;
The Following Output Would be Produced:
var data = ; /* #if someValue === 'foo' */var result = data;/* #endif *//* #if someValue !== 'foo' *//* #endif */ console;
Options
The following configuration options are available (and are all optional):
- context (
Object
): AnObject
whose keys will be available as variables in the comment expressions - marker (
String
): The character to look for at the start of a comment (beforeif
orendif
)—defaults to#
- ecmaVersion (
Number
): Version of ECMAScript to pass toacorn
when parsing each module - exts (
Array
ofString
s): 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 @ ]
;
var conditionalify = ;;