gulp-load-all-tasks
One folder, all tasks.
Inspired by gulp-task-loader.
Getting Started
Prerequisites
Please make sure you're using gulp version 4.0 or follow this guildline to upgrade.
Use NPM.
npm install -g gulp-clinpm install --save-dev gulpjs/gulp#4.0
Use Yarn. (Installation)
yarn global add gulp-cliyarn add --dev gulpjs/gulp#4.0
Check your gulp version.
gulp -v
You might get result like this:
CLI version 1.4.0Local version 4.0.0-alpha.2
Install
By NPM:
npm install --save-dev gulp-load-all-tasks
By Yarn:
yarn add --dev gulp-load-all-tasks
Usage
- Create a folder named 'gulp-tasks' or whatever you like.
- Create a task definition file.
- Require this module and invoke it.
- All tasks are loaded.
You can also create subfolders to organize your tasks as sub-tasks. All sub-tasks will named with prefix by folder name.
For example, if the structure of your gulp-tasks
are:
.
├── build
│ ├── pug.js
│ └── sass.js
├── build.js
├── watch.js
└── deploy.js
And you'll see your tasks list:
gulp --tasks
Tasks for guipfile.js
├── build:pug
├── build:sass
├── build
├── deploy
└── watch
Examples
Task definition file
// gulp-tasks/copy.jsmodule { return gulp };
// Load all tasks from default folder 'gulp-tasks'; // Run the taskgulp
Task with dependencies
// gulp-tasks/copy.jsconst del = ; module { return gulp };moduleexportsdependencies = gulp;
Load tasks by default folder
;
gulp-load-plugins
Load module by const $ = ;$;
Load tasks by Different folder name
'my-tasks';
Load tasks in other extensions
exts: '.coffee';
Task context
Each task will binding a context object with reference to gulp
and context
.
// gulpfile.jsconst browserSync = ; browserSync; // gulp-tasks/pug.jsconst $ = ; module { const gulp = thisgulp; const browserSync = thiscontextbrowserSync; return gulp
Forward Reference Support
If you got the error:
AssertionError: Task never defined: <task>
All the tasks are loaded by gulp alphabetically, it'll cause some of your task dependencies are loaded before it defined.
You can add undertaker-forward-reference
as your gulp task registry.
const ForwardReference = ;const loadAllTasks = ; gulp; ;
Options
dir
Type: String
Default: gulp-tasks
Folder path with all task files.
extensions
Type: Array
Default: ['.js']
Task file extensions.
License
MIT © ethancfchen