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

前端之家收集整理的这篇文章主要介绍了为什么Wiredep在我的gulp任务中错误地使用“dest.on不是函数”?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在Gulp任务中使用 Wiredep在我的index.html文件中注入Bower依赖项.以下任务(没有Wiredep)运行正常.
  1. gulp.task('build',['copy','assets'],function(){
  2.  
  3. return gulp.src('app/index.html')
  4. .pipe(inject(gulp.src(['dist/assets/js/*.js','dist/assets/css/*.css'],{read: false}),{relative: true}))
  5. .pipe(gulp.dest('dist'));
  6. });

现在我尝试添加Wiredep:

  1. var wiredep = require('wiredep');
  2.  
  3. gulp.task('build',function(){
  4.  
  5. return gulp.src('app/index.html')
  6. .pipe(wiredep())
  7. .pipe(inject(gulp.src(['dist/assets/js/*.js',{relative: true}))
  8. .pipe(gulp.dest('dist'));
  9. });

结果如下:

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

我直接尝试了using Wiredep from the command line,运行正常.
我使用Node v4.2.2在Windows上运行.

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

  1. gulp.task('build',function(){
  2. wiredep({src:'dist/index.html'});
  3.  
  4. return gulp.src('dist/index.html')
  5. .pipe(inject(gulp.src(['dist/assets/js/*.js',{relative: true}))
  6. .pipe(gulp.dest('dist'));
  7. });

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

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

解决方法

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

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

猜你在找的JavaScript相关文章