BarryBones41
BarryBones41

Reputation: 1481

Gulpfile that includes other gulp files

I wrote some wrapper functions for using gulp, such as buildJs, buildCss, etc, that simply wrap some things like concatenation, minification, transpiling, etc.

I have these functions and all the required node modules in the main file, gulpfile.js

Then I wrote all my build tasks (eg gulp.task('dostuff, function(){});) in two other files, buildA.js and buildB.js.

In my main gulpfile.js after I require the necessary node modules like gulp, I then thought I could require buildA.js and buildB.js and it would be as if they were just copy-pasted into the file. Obviously this doesn't work, because when I try to run a gulp task from file buildA.js, it tells me that gulp is not defined when it hits gulp.task....

I also did not import or export anything in any file.

What can I do to include my product specific gulp files in one master gulp file, and be able to call gulp.task specific to each build file, from the main gulp file, as if they were actually in the file?

Thanks

Upvotes: 0

Views: 569

Answers (1)

Derek Hao
Derek Hao

Reputation: 11

I am using the require-dir, https://www.npmjs.com/package/require-dir Assume your buildA.js and buildB.js are located in ./gulp directory, you can use this line to include them in your gulpfile: require('require-dir')('./gulp');

Upvotes: 1

Related Questions