在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):betsol/gulp-require-tasks开源软件地址(OpenSource Url):https://github.com/betsol/gulp-require-tasks开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-require-tasksThis convenient extension for Gulp 3 allows you to load tasks from multiple individual files in a directory hierarchy. Deprecation Notice
Features
Installation
|
Property | Default Value | Description |
---|---|---|
path | './gulp-tasks' |
Path to directory from which to load your tasks modules |
separator | : |
Task name separator, your tasks would be named, e.g. foo:bar:baz for ./tasks/foo/bar/baz.js |
passGulp | true |
Whether to pass Gulp instance as a first argument to your task function |
passCallback | true |
Whether to pass task callback function as a last argument to your task function |
gulp | require('gulp') |
You could pass your existing Gulp instance if you have one, or it will be required automatically |
Consider you have the following task module: gulp-tasks/styles/build.js
.
You could define module as a task function. Gulp instance and callback function would be passed to it, if not configured otherwise.
You could configure the library to pass additional arguments as well.
// gulp-tasks/styles/build.js:
const compass = require('compass');
module.exports = function (gulp, callback) {
return gulp.src('...')
.pipe(compass())
.pipe(gulp.dest('...'))
;
};
Also, you could define your task module as an object. This will allow you to provide additional configuration.
// gulp-tasks/styles/build.js:
const compass = require('compass');
module.exports = {
deps: ['styles:clean', 'icons:build'],
fn: function (gulp, callback) {
return gulp.src('...')
.pipe(compass())
.pipe(gulp.dest('...'))
;
}
};
You will have to define your task function as fn
parameter.
You could use deps
parameter to define your task dependencies.
Also, you could use nativeTask
instead of fn
property to make your
task function executed by Gulp directly. That way, additional arguments
will not be passed to it. This feature is useful when using,
e.g. gulp-sequence plugin or for synchronous tasks.
To make sure, that task is finished correctly you must either:
return gulp.src().pipe(gulp.dest());
return del();
or return new Promise();
callback();
WARNING: If your task function is synchronous — please read the section below!
Starting from version 1.1.0
you can place index.js
inside of the task directories.
The actual task, registered with Gulp will have the name of the directory itself,
e.g.: scripts/build/index.js
will become: scripts:build
.
The index.js
, placed in the root of tasks directory, will be registered as a default
task.
If you need to pass something to the task function from your gulpfile you can use globals.
Define your custom properties on the global
object:
// gulpfile.js
global.SOURCES_BASE_PATH = __dirname + '/src';
And then use it in your task module:
// gulp/tasks/styles/build.js
module.exports = gulp =>
gulp.src(global.SOURCES_BASE_PATH + '/styles/*.scss')
.pipe(compass())
.pipe(gulp.dest('…'))
;
If you are using synchronous tasks, i.e. tasks which execute synchronously without returning streams, promises or accepting callbacks, you will have to use one of the workarounds specified below:
1). The simplest method is to use nativeTask
functionality, here's the
example of the module with native task synchronous function:
module.exports = {
nativeTask: function () {
console.log('This is the synchronous native task without a callback!');
}
};
2). You should call a callback explicitly:
module.exports = function (gulp, callback) {
console.log('This is the synchronous native task with explicit callback!');
callback(); // Don't forget this, otherwise task will never finish!
};
However, if config.passCallback == false
you won't be able to use the second method.
These workarounds must be used due to architectural limitation of this module integration with orchestrator. Please see the issue #9: Synchronous tasks without callback don't finish for more technical details.
Please see the changelog for list of changes.
If you have found a bug or have another issue with the library — please create an issue.
If you have a question regarding the library or it's integration with your project — consider asking a question at StackOverflow and sending me a link via E-Mail. I will be glad to help.
Have any ideas or propositions? Feel free to contact me by E-Mail.
Cheers!
If you like this library consider to add star on GitHub repository.
Thank you!
The MIT License (MIT)
Copyright (c) 2016-2020 Slava Fomin II
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论