在gulp/browserify捆绑包上运行多个转换

SYU*_*U88 8 node.js browserify reactjs gulp

我有一个React组件,我一直导出到一个包文件.我已经成功地使用babelify对其进行了改造,但是,我现在想在它上面运行envify.我似乎无法弄清楚如何使用browserify运行多个转换.我认为它一定是可能的,但是我不知道我的语法是否稍微偏离,或者我是否需要编写自定义转换,或者我是否应该在package.json中指定转换.这是我的gulp文件中的代码:

 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/'));
};
Run Code Online (Sandbox Code Playgroud)

ahz*_*ahz 3

你尝试过连锁吗?正确的解决方法在评论里

 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/'));
};
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!当我使用 `browserify({ 'entries': ['./client/components/TVScheduleTab/render.js'], 'transform': [[babelify], ['envify', {'global': true, NODE_ENV: '生产'}]] }` (2认同)