2015-11-13 16 views
6

Tôi đang cố gắng sử dụng Wiredep trong tác vụ Gulp để tiêm phụ thuộc Bower vào tệp index.html của tôi. Tác vụ sau (không có Wiredep) chạy tốt.Tại sao Wiredep bị lỗi với "dest.on không phải là một chức năng" trong nhiệm vụ gulp của tôi?

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

Bây giờ tôi cố gắng thêm Wiredep với nó:

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

mà kết quả trong:

[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) 

tôi đã cố gắng using Wiredep from the command line trực tiếp và nó chạy tốt. Tôi đang chạy trên Windows, sử dụng Node v4.2.2.

EDIT Nếu ai gặp cùng một vấn đề, sau đó thực hiện giải pháp là thay đổi nhiệm vụ:

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

Lưu ý, rằng index.html được sao chép vào thư mục TP trước khi beeing tiêm.

Tôi vẫn tự hỏi tại sao tôi không thể sử dụng luồng để nối các phụ thuộc.

Trả lời

14

Tôi chỉ tự mình gặp vấn đề này. Đó là vì cách bạn đang nhập dữ liệu. Bạn cần phải làm những điều sau đây để cho nó để được đường ống như là một phần của một dòng ngụm:

var wiredep = require('wiredep').stream; 

Loại trừ phần .stream phép bạn sử dụng wiredep như một chức năng bên ngoài của một dòng ngụm.

Các vấn đề liên quan