Javascript 如何将源流输出到目标目录?
我正在从正在工作但不推荐的gulp browserify模块转移到普通browserify模块。我的源代码树如下所示:Javascript 如何将源流输出到目标目录?,javascript,gulp,browserify,Javascript,Gulp,Browserify,我正在从正在工作但不推荐的gulp browserify模块转移到普通browserify模块。我的源代码树如下所示: projectdir public js src dist 我的吞咽任务如下所示: var source = require('vinyl-source-stream'); gulp.task('js', ['clean'], function() { // Browserify/bundle the JS. bundle
projectdir
public
js
src
dist
我的吞咽任务如下所示:
var source = require('vinyl-source-stream');
gulp.task('js', ['clean'], function() {
// Browserify/bundle the JS.
bundler.bundle()
// log errors if they happen
.on('error', function(err) {
return notify().write(err);
})
.pipe(source('./public/js/src/index.js'))
.pipe(gulp.dest('./public/js/dist'));
});
但是,这会写入public/js/dist/public/js/src/
这显然很糟糕。然而,changin大口大口地说:
.pipe(gulp.dest('./public/js/dist'));
在我的项目目录外写入!即:
~/Documents/dist/public/js/src/index.js
我看过很多使用gulp.src的gulp文档,但我没有使用gulp.src,我使用的是乙烯基源流
如何将乙烯基源流输出到public/js/dist?最终我自己解决了这个问题:
var bundler = watchify(browserify({
basedir: "./public/js/src"
}));
// Browserify our code
gulp.task('js', ['clean'], function() {
// Browserify/bundle the JS.
return bundler.bundle()
// log errors if they happen
.on('error', function(err) {
return notify().write(err);
})
.pipe(source('index.js'))
.pipe(gulp.dest('public/js/dist'));
});
需要了解的主要内容是source使用了browserify的basedir,而gulp.dest则没有