You can split your task into 2 and make one of the tasks run after another by using Gulp's dependency resolution system.
gulp.task('task1', function () { ... });
gulp.task('task2', ['task1'], function () { ... });
Pregunta
I'm trying to do the following:
gulp.src('js/*.js')
.pipe(concat('_temp.js'))
.pipe(gulp.dest('js/'));
gulp.src('build/js/app.js')
.pipe(replace('// includes', fs.readFileSync('js/_temp.js')))
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest('build/js'));
So, I'm concatenating all .js
files in js/
. The concatenated file is named _temp.js
;
After that, I'm reading a app.js
and try to replace the // includes
string with the concatenated _temp.js
file. This doesn't work as node says the file doesn't exist. It does exist though, so I second time I run this task, it works.
This has most probably to do with asynchronisity, but I'm unable to see how I would do this differently?
Solución
You can split your task into 2 and make one of the tasks run after another by using Gulp's dependency resolution system.
gulp.task('task1', function () { ... });
gulp.task('task2', ['task1'], function () { ... });