Reputation: 8214
I am trying to require a gulpfile (someGulpfile.js) in my own gulpfile (gulpfile.js) from where I run the gulp command. When I try to use the tasks defined in someGulpfile it throws an error on console saying Task 'default' is not in your gulpfile
even though I just did require('./someGulpfile');
in my gulpfile.js
How can I use the tasks defined in someGulpfile? What is causing this issue?
I found out that this somewhat works but it does not output every task that is run (for example it does not output, Starting sometask, Finished sometask, Starting default, ...) and if there is an error it does not show the error and where it happened but errors out in the gulp library code where it has trouble formatting the error output.
//gulpfile.js
var gulp = require('gulp');
gulp.tasks = require('./someGulpfile').tasks;
//someGulpfile.js
var gulp = require('gulp');
gulp.task('sometask', function() {});
gulp.task('default', ['sometask']);
module.exports = gulp;
Upvotes: 2
Views: 2425
Reputation: 3144
Could try something like this:
gulpfile.js
require("./gulp/tasks/build-js.js")();
require("./gulp/tasks/build-css.js")();
./gulp/tasks/build-js.js
var gulp = require("gulp");
module.exports = function() {
gulp.task("js", function() {
return gulp.src("./app/**/*.js")
.pipe();
//etc.
}
}
./gulp/tasks/build-css.js
var gulp = require("gulp");
module.exports = function() {
gulp.task("css", function() {
return gulp.src("./app/style/*.css")
.pipe();
//etc.
}
}
This will let you modularize your gulp tasks into different folders.
Upvotes: 3