Search code examples
reactjsgulpbrowserify

Setting NODE_ENV via envify not working


I have the following gulp task in my gulpfile.js:

    gulp.task('build-scripts', function () {
    var b = browserify({ debug: false });
    b.transform(reactify);
    b.transform(envify({
        _: 'purge',
        NODE_ENV: 'production'
    }));

    b.add('./src/scripts/index.js');

    return b.bundle()
    .pipe(source('./www/scripts/dist/bundle.js'))
    .pipe(buffer())
    .pipe(uglify())
    .pipe(gulp.dest('.'))

});

The task completes with status 0 and the React transform happens, but in bundle.js I still see:

if (process.env.NODE_ENV !== 'production') {

Wasn't this supposed to go away with the envify transform? Am I doing something wrong here?

I have done some digging, but all the solutions I can find are os x / linux specific (I'm on a windows machine).

EDIT: I am running the gulp build from within visual studio's Task Runner Explorer.


Solution

  • The doc says:

    By default, environment variables that are not defined will be left untouched.

    https://github.com/hughsk/envify#purging-processenv

    Have you tried defining it before running that? i.e.

    process.env.NODE_ENV = 'production';