I need to run another gulp file before the 'default' task in current gulp file. Is there any gulp plugin for this situation.
You can use child_process.exec(...)
to run the both gulp tasks like you would from the console using the CLI API. There is Gulp.run
but that function is deprecated and will be removed moving forward.
This snippet will run both gulp files below in succession.
To run: node run-two-gulp-files.js
./gulpfile.js
depends on ./other-thing-with-gulpfile/gulpfile.js
var exec = require('child_process').exec;
// Run the dependency gulp file first
exec('gulp --gulpfile ./other-thing-with-gulpfile/gulpfile.js', function(error, stdout, stderr) {
console.log('other-thing-with-gulpfile/gulpfile.js:');
console.log(stdout);
if(error) {
console.log(error, stderr);
}
else {
// Run the main gulp file after the other one finished
exec('gulp --gulpfile ./gulpfile.js', function(error, stdout, stderr) {
console.log('gulpfile.js:');
console.log(stdout);
if(error) {
console.log(error, stderr);
}
});
}
});
var gulp = require('gulp');
var replace = require('gulp-replace');
gulp.task('file1-txt', function() {
return gulp.src('file1.txt')
.pipe(replace(/foo/g, 'bar'))
.pipe(gulp.dest('dest'));
});
gulp.task('default', ['file1-txt']);
var gulp = require('gulp');
var replace = require('gulp-replace');
gulp.task('file2-txt', function() {
return gulp.src('file2.txt')
.pipe(replace(/baz/g, 'qux'))
.pipe(gulp.dest('../dest'));
});
gulp.task('default', ['file2-txt']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With