Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple transforms on gulp/browserify bundle

I have a React component that I've been exporting to a bundle file. I've been successfully transforming it using babelify, however, I now would like to run envify on it. I can't seem to figure out how to run multiple transforms using browserify. I think it must be possible, but I can't tell if my syntax is slightly off or if I need to write a custom transform or if I should specify the transforms in my package.json. Here is the code in my gulp file:

 var bundleComponent = function(bundler, source, component) {
   //bundler is just browserify('./client/components/TVScheduleTab/render.js')

   gutil.log('Bundling ' + component)

  return bundler
  //this throws an error
    .transform(babelify, envify({
      NODE_ENV: 'production'
    }))
    .bundle()
    .on('error', function(e){
      gutil.log(e);
    })
    .pipe(source)
    .pipe(gulp.dest('output/'));
};
like image 844
syu15 Avatar asked Oct 13 '15 17:10

syu15


1 Answers

Have you tried chaining? Correct solution is in comments

 var bundleComponent = function(bundler, source, component) {
   //bundler is just browserify('./client/components/TVScheduleTab/render.js')

   gutil.log('Bundling ' + component)

  return bundler
  //this throws an error
    .transform(babelify)
    .transform(envify({
      NODE_ENV: 'production'
    }))
    .bundle()
    .on('error', function(e){
      gutil.log(e);
    })
    .pipe(source)
    .pipe(gulp.dest('output/'));
};
like image 108
ahz Avatar answered Oct 17 '22 08:10

ahz