I use Gulp to collect front-matter (via the gulp-front-matter plugin), and then, after aggregating it, I save it to another file. Among other data, I save a bunch of CSS. Here is what I have for my compileCSS task:
var collected = []; gulp.src('./client/**/*.html') .pipe(frontMatter({ property: 'meta', remove: true })) .pipe(through.obj(function(file, enc, callback) { var css = file.meta; collected.push(css); })) .pipe(gulp.dest('./build/templates')) .on('end', function() { var cssPath = ['build', 'assets', 'css', 'compiled.css']; fs.writeFileSync(cssPath.join(path.sep), cssPath); })
;
The task works as expected (note that this is a simplified version). Everything works as expected, and I get a compiled.css file with all the leading edge CSS. However, I found the need to use the prefix not only in my regular css file, but also in this new compiled.css file. So I created a prefix task:
gulp.task('prefix', ['compileCSS', 'copy'], function() { gulp.src('./build/assets/css/*.css') .pipe(autoprefixer({ browsers: ['last 3 versions'] })) .pipe(gulp.dest('build')) ; });
Now the problem is that the on('end' function is executed at the end of ALL tasks, and not just in the compileCSS task.
My question is, is there a way to introduce an end-type task for each task? Or is there a way to use threads in some way (since the last task is not an actual thread and does not use it, I don’t see how).
source share