• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

hontas/gulp-task-loader: Organize your gulp-tasks in separate files

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

hontas/gulp-task-loader

开源软件地址(OpenSource Url):

https://github.com/hontas/gulp-task-loader

开源编程语言(OpenSource Language):

JavaScript 99.0%

开源软件介绍(OpenSource Introduction):

Gulp Task Loader

Organize your gulp-tasks in separate files

Dependency Status DevDependency Status PeerDependency Status Build Status

Not actively maintained

Because I rarely use gulp these days. Wanna take over? Tell me.

Install

npm install gulp-task-loader --save-dev

Use

  1. Create one file / task
  2. Place the task-files in a folder named 'gulp-tasks' (or whatever you like)
  3. Require this module and invoke it [with or without options]
  4. Gulp-tasks now magically exist (named after task file name)

You may create subfolders of tasks as well. Tasks in these folders will have their task name prefixed by the folder name. For example, if you have a task named coffee that compiles CoffeeScript files, you could place this task in the gulp-tasks/browser folder and it would be invoked using gulp browser:coffee. You may nest folders as deep as required, and each folder will be added to the task name.

Examples

Simple task file

// gulp-tasks/copy.js
module.exports = function() {
	return gulp.src("src/**/*")
		.pipe(gulp.dest("dist/**/*"));
};
// gulpfile.js
// Load all tasks from folder `gulp-tasks`
require('gulp-task-loader')();

// use it!
gulp.watch(someFiles, ['copy']);

With dependencies

// gulp-tasks/task-with-deps.js
module.exports = function() {
    return gulp.src("src/**/*")
        .pipe(gulp.dest("dist/**/*"));
};
module.exports.dependencies = ['copy'];

Load tasks from another folder

require('gulp-task-loader')('le-tasks-de-gulp');

Load tasks in CoffeeScript

require('coffee-script/register');
require('gulp-task-loader')({ exts: ['.coffee'] });

Load tasks in other extensions

require('gulp-task-loader')({ exts: ['.jscript'] });

Task context

Each task is called with a context object containing a reference to gulp and opts (the options object).

// gulpfile.js
var pkg  require('./package.json');
require('gulp-task-loader')({ pkg: pkg, dest: 'dist' });

// gulp-tasks/xxx.js
module.exports = function() {
    return this.gulp.src(this.opts.pkg.main)
      .pipe(this.gulp.dest(this.opts.dest));
};

Subtasks

// gulp-tasks/copy/all.js
// gulp-tasks/copy/fonts.js

// gulpfile.js
gulp.watch(allFiles, ['copy:all']);
gulp.watch(someFiles, ['copy:fonts']);

Given the files in folder copy - two tasks have been created. copy:all & copy:fonts

Options

dir

Type String Default gulp-tasks

Path to folder with gulp tasks

extensions

Type Array Default to keys of require.extensions

List of extensions to filter tasks by. Example: ['.js', '.coffee']

Test

npm test

Changelog

1.4.4

  • Bugfix for options.dir

1.4.1

  • Fixed bug that caused subtasks to break

1.4.0

  • Allow loading of infinitely nested children directories

1.3.0

  • Replaced lodash.defaults with object-assign
  • Call tasks with context. Thanks to @mamboer

1.2.1

  • Load tasks relative to project. Thanks to @archr

1.2.0

  • tasks in subfolder will be named folderName:taskName. Thanks to @evanshortiss.

1.1.0

  • added support for other sources than .js. Thanks to @blvz.

pre 1.1.0

  • the dark ages of not documenting version bumps..



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
shinate/gulp-version-number: Add version number to js/css/image in HTML发布时间:2022-06-21
下一篇:
gaspanik/gulpbase: demo.发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap