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