Skip to content

About

Browserify preprocess js transform

Resources

Stars

14 stars

Watchers

4 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

preprocessify

A browserify transform that applies preprocess to js files before bundling them.

Example use on the command line

browserify -t [preprocessify --contextFile ./path/to/contextFile.json] entry.js

Example use in a gulp file...

var preprocessify = require('preprocessify');

gulp.task('browserify', function() {
    return browserify('./app/scripts/main.js')
        .transform(preprocessify, {
            includeExtensions: ['.js'],
            context: {"FOO": "bar"} // This will replace "/* @echo FOO */" with "bar"
        })
        .bundle()
        .pipe(source('main.js'))
        .pipe(gulp.dest(config.dist + '/scripts/'));
});

You can use this in combination with konfig to define environment specific variables like this... In ./config/app.json...

{
    "development": {
        "bar": "development bar value"
    },
    "test": {
        "bar": "test bar value"
    },
    "production": {
        "bar": "production bar value"
    }
}

In gulp file...

var config = require('konfig')();
var preprocessify = require('preprocessify');

gulp.task('browserify', function() {
    return browserify('./app/scripts/main.js')
        .transform(preprocessify, {
            includeExtensions: ['.js'],
            context: config.app // When the environment variable NODE_ENV=test, "/* @echo bar */" gets replaced with "test bar value"
        })
        .bundle()
        .pipe(source('main.js'))
        .pipe(gulp.dest(config.dist + '/scripts/'));
});

See also: preprocess and gulp-preprocess

About

Browserify preprocess js transform

Resources

Stars

14 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages