结合gulp-inject和gulp-coffee

时间:2014-08-18 16:08:09

标签: gulp gulp-inject

我想编译我的咖啡文件并使用gulp stream将它们注入我的index.html。

这就是我的尝试:

gulp.task('scripts', function() {
  return gulp.src(paths.coffee.source)
    .pipe(coffee())
    .pipe(inject(paths.index.source))
    .pipe(gulp.dest(paths.coffee.destination));
});

这是错误:

[17:57:39] 'scripts' errored after 2.19 ms passing target file as a string is deprecated! Pass a vinyl file stream (i.e. use `gulp.src`)!

显然我正在做的事情已被弃用。是否可以在一个流中执行此操作?

1 个答案:

答案 0 :(得分:2)

你应该提供注入乙烯基文件流,确切地说错误是什么,即(如文档:https://github.com/klei/gulp-inject#injecting-files-relative-to-target-files中所示):

var inject = require('gulp-inject');

gulp.src('./src/**/*.html')
  .pipe(inject(gulp.src('./src/**/*.js', {read: false}), {relative: true}))
  .pipe('./src');

或在您的代码中,您应该更改

inject(paths.index.source) 

inject(gulp.src(paths.index.source, {read: false}), {relative: true}))