You can use child_process.exec(...) to run gulp tasks like you from the console using the CLI API. There is Gulp.run , but this function is deprecated and will be removed by moving forward.
This snippet will run both gulp files below.
introductory two- gulp -files.js
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); } }); } });
gulpfile.js
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']);
other-thing-with-gulpfile / gulpfile.js
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']);
MLM
source share