gpt4 book ai didi

javascript - 如何将 vinyl-source-stream 输出到我的目标目录?

转载 作者:行者123 更新时间:2023-11-29 18:10:06 25 4
gpt4 key购买 nike

我正在从(有效但已弃用的)gulp-browserify 转移到普通的 browserify 模块。我的源代码树如下所示:

projectdir
public
js
src
dist

我的 gulp 任务如下所示:

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/

这显然是不好的。但是,将 gulp.dest 更改为:

.pipe(gulp.dest('./public/js/dist'));

写在我的项目目录之外!即:

 ~/Documents/dist/public/js/src/index.js

我看过很多使用 gulp.src 的 gulp 文档,但我没有使用 gulp.src,我使用的是 vinyl-source-stream

如何将 vinyl-source-stream 输出到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 没有。

关于javascript - 如何将 vinyl-source-stream 输出到我的目标目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28170705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com