node.js - 在 gulp/browserify 包上运行多个转换

标签 node.js reactjs gulp browserify

我有一个已导出到捆绑文件的 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/'));
};

最佳答案

您尝试过链接吗? 正确的解决方案在评论中

 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/'));
};

关于node.js - 在 gulp/browserify 包上运行多个转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33108525/

相关文章:

javascript - 在 jsx 对象中插入 html 标签以进行映射

javascript - 从 cmd 运行 gulp 可以,但在 WebStorm 中不行

node.js - 如何在es2015中导入rethinkdbdash

node.js - 无法启用react-simple-chatbot NPM模块中的输入字段

javascript - NodeJS 和 ExpressJS - Javascript 文件加载,但 CSS 文件不加载

regex - 使用 MongoDB 和 Mongoose 在多个字段中搜索子字符串

javascript - 函数未定义,Bookshelf.js 模型函数未被识别为函数

javascript - 更新组件状态后 useEffect 未触发

javascript - React中array.map和onchange的使用

node.js - 引用错误: sass is not defined