为什么Wiredep在我的gulp任务中错误地使用"dest.on不是函数"?

Apo*_*psa 5 bower gulp wiredep

我试图在Gulp任务中使用Wiredep在我的index.html文件中注入Bower依赖项.以下任务(没有Wiredep)运行正常.

gulp.task('build', ['copy', 'assets'], function(){

    return gulp.src('app/index.html')
    .pipe(inject(gulp.src(['dist/assets/js/*.js', 'dist/assets/css/*.css'], {read: false}), {relative: true}))
    .pipe(gulp.dest('dist'));
});
Run Code Online (Sandbox Code Playgroud)

现在我尝试添加Wiredep:

var wiredep = require('wiredep');

gulp.task('build', ['copy', 'assets'], function(){

    return gulp.src('app/index.html')
    .pipe(wiredep())
    .pipe(inject(gulp.src(['dist/assets/js/*.js', 'dist/assets/css/*.css'], {read: false}), {relative: true}))
    .pipe(gulp.dest('dist'));
});
Run Code Online (Sandbox Code Playgroud)

结果如下:

[09:45:11] TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (C:\GIT\myApp\myApp-front\node_module
s\gulp-debug\node_modules\through2\node_modules\readable-stream\lib\_stream_read
able.js:533:8)
    at Gulp.<anonymous> (C:\GIT\myApp\myApp-front\gulpfile.js:38:6)
    at module.exports (C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\
orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\GIT\myApp\myApp-front\node_modules\gulp\n
ode_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\GIT\myApp\myApp-front\node_modules\gulp\n
ode_modules\orchestrator\index.js:214:10)
    at C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestrator\ind
ex.js:279:18
    at finish (C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestr
ator\lib\runTask.js:21:8)
    at C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestrator\lib
\runTask.js:52:4
    at f (C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestrator\
node_modules\end-of-stream\node_modules\once\once.js:17:25)
    at DestroyableTransform.onend (C:\GIT\myApp\myApp-front\node_modules\gulp\n
ode_modules\orchestrator\node_modules\end-of-stream\index.js:31:18)
Run Code Online (Sandbox Code Playgroud)

我尝试直接从命令行使用Wiredep,它运行正常.我使用Node v4.2.2在Windows上运行.

编辑 如果有人遇到同样的问题,那么解决方法是将任务更改为:

gulp.task('build', ['copy', 'assets'], function(){
    wiredep({src:'dist/index.html'});

    return gulp.src('dist/index.html')
    .pipe(inject(gulp.src(['dist/assets/js/*.js', 'dist/assets/css/*.css'], {read: false}), {relative: true}))
    .pipe(gulp.dest('dist'));
});
Run Code Online (Sandbox Code Playgroud)

请注意,在注入之前将index.html复制到dist目录.

我仍然想知道为什么我不能使用流来连接依赖项.

Gre*_*g H 13

我自己也遇到了这个问题.这是因为你导入wiredep的方式.您需要执行以下操作才能将其作为gulp流的一部分进行管道传输:

var wiredep = require('wiredep').stream;
Run Code Online (Sandbox Code Playgroud)

排除该.stream部分允许您将wiredep用作gulp流之外的函数.