我有一个包含各种任务的gulp文件。第一个任务创建一个sass文件,后面的任务是使用该文件。
如果我明确地运行了两个任务(gulp sass
,确保创建了sass文件然后运行gulp template-cache
)它们就可以正常运行。
但是,当运行gulp任务连接这些任务时,任务失败,因为尚未创建文件template-cache
所需,即使sass
任务已声明已完成。
这是两个任务:
gulp.task('sass', function(){
sass(PATH.APP + '/**/*.scss', {sourcemap: true, style: 'expanded', compass: true})
.pipe(autoprefixer({browsers:['last 4 versions']}))
.pipe(sourcemaps.write())
.on('error', sass.logError)
.pipe(gulp.dest(PATH.APP))
.pipe(livereload());
});
gulp.task('template-cache', function () {
return gulp.src(PATH.APP + '/*/**/*.html')
.pipe(templateCache({ filename:'templates.js', module:'app' }))
.pipe(gulp.dest(PATH.DIST + '/scripts'));
});
这是执行构建的gulp任务:
gulp.task('default', sequence(
['sass', 'replace-config-local'],
'build',
'icons',
'revision'
,'uglify'
));
这是构建任务:
gulp.task('build', sequence('clean', ['useref', 'template-cache'], 'concat', 'delete-templates'));
我得到的错误信息是:
gulp
[16:41:37] Using gulpfile ~/backoffice/gulpfile.js
[16:41:37] Starting 'default'...
[16:41:37] Starting 'sass'...
[16:41:37] Finished 'sass' after 46 ms
[16:41:37] Starting 'replace-config-local'...
[16:41:37] Finished 'replace-config-local' after 84 ms
[16:41:37] Starting 'build'...
[16:41:37] Starting 'clean'...
[16:41:37] Finished 'clean' after 14 ms
[16:41:37] Starting 'useref'...
[16:41:38] Starting 'template-cache'...
events.js:141
throw er; // Unhandled 'error' event
^
Error: Error: File not found with singular glob: /home/ubuntu/backoffice/app/styles/main.css
at DestroyableTransform.<anonymous> (/home/ubuntu/backoffice/node_modules/gulp-useref/index.js:65:28)
at emitOne (events.js:82:20)
at DestroyableTransform.emit (events.js:169:7)
at emitOne (events.js:77:13)
at DestroyableTransform.emit (events.js:169:7)
at Glob.<anonymous> (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/index.js:40:16)
at Glob.g (events.js:260:16)
at emitOne (events.js:77:13)
at Glob.emit (events.js:169:7)
at Glob._finish (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/glob.js:172:8)
at done (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/glob.js:159:12)
at Glob._processSimple2 (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/glob.js:652:12)
at /home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/glob.js:640:10
at Glob._stat2 (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/glob.js:736:12)
at lstatcb_ (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/glob.js:728:12)
at RES (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/node_modules/inflight/inflight.js:23:14)
at f (/home/ubuntu/backoffice/node_modules/gulp-useref/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob/node_modules/once/once.js:25:25)
at FSReqWrap.oncomplete (fs.js:82:15)
答案 0 :(得分:0)
正如@MadScone在评论中所建议的,返回流解决了问题。
例如,将gulp.src(PATH.DIST + '/**')
更改为return gulp.src(PATH.DIST + '/**')
。