如何从gulp-useref看到gulp-ruby-sass任务的输出?

时间:2014-12-12 00:32:21

标签: gulp

我有一些由gulp-ruby-sass创建的CSS。生成的CSS文件在gulp-useref使用的html中引用,以获取用于连接,缩小等的资源。问题是(我认为)gulp-ruby-sass还没有将CSS文件写入磁盘和gulp-useref无法找到要在构建中包含它的文件。所以这段代码:

gulp.task("compile-css", function () {
    gulp.src(paths.css.appFiles)
        .pipe(gutil.env.debug ? sass({ debugInfo : true }) : sass())
        .pipe(gutil.env.debug ? gutil.noop() : cssmin())
        .pipe(gulp.dest(paths.css.appDistDir));
});

gulp.task("concatenateAllTheThings", ["compile-css"], function () {
    var assets = useref.assets();     // useref package does the magic 
    return gulp.src(["./index.html", "./login.html", "./reset.html", "./confirm.html"])
        .pipe(assets)
        .pipe(gulpif('*.js',ngAnnotate()))
        .pipe(gulpif('*.js', uglify()))
        .pipe(assets.restore())
        .pipe(useref())
        .pipe(gulp.dest(paths.output.destination));
});

抛出此错误:

[19:06:32] Starting 'compile-css'...
[19:06:32] Finished 'compile-css' after 13 ms
[19:06:32] Starting 'concatenateAllTheThings'...
[19:06:32] Starting Karma server...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, no such file or directory 'c....\webui\css\custom.css'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.readFileSync (fs.js:284:15)
    at DestroyableTransform.<anonymous> (C....\AppData\Roaming\npm\node_modules\gulp-useref\index.js:81:61)

    at Array.forEach (native)
    at DestroyableTransform.<anonymous> (C....g\AppData\Roaming\npm\node_modules\gulp-useref\index.js:70:35)

    at Array.forEach (native)
    at DestroyableTransform.<anonymous> (C....\AppData\Roaming\npm\node_modules\gulp-useref\index.js:46:36)

    at Array.forEach (native)
    at DestroyableTransform._transform (C....\AppData\Roaming\npm\node_modules\gulp-useref\index.js:43:15)
    at DestroyableTransform.Transform._read (C....\AppData\Roaming\npm\node_modules\gulp-useref\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)

如何从gulp-ruby-sass中获取gulp-useref以查看CSS文件?

1 个答案:

答案 0 :(得分:2)

要在任务完成时知道吞咽,您需要返回流。这样,依赖于您返回的任务的任务将等待它完成。

所以将compile-css更改为

gulp.task("compile-css", function () {
  return gulp.src ...
});