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 conversion occurs, but in bundle.js I can still see:

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

Shouldn't that have disappeared with the envify conversion? Am I something wrong here?

I did 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 construct from the Visual Studio Task Runner Explorer .

+5
source share
1 answer

Doc says:

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

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

Have you tried to determine it before running? i.e.

 process.env.NODE_ENV = 'production'; 
+3
source

Source: https://habr.com/ru/post/1235170/


All Articles