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

maxov/gulp-grunt: Run grunt tasks from gulp

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

开源软件名称(OpenSource Name):

maxov/gulp-grunt

开源软件地址(OpenSource Url):

https://github.com/maxov/gulp-grunt

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-grunt

Run grunt tasks from gulp

NPM version travis build dependencies

What if your favorite grunt plugin isn't available for gulp yet? Don't fret, there is nothing to worry about! Why don't you just hook in your grunt configuration?

This plugin is a bit different from most other gulp plugins. You cannot use it inline, because it does not create a stream. Rather, use it at the top of your gulpfile, calling it with your gulp as an argument. This classifies gulp-grunt as gulpfriendly, not a gulpplugin.

Example usage

var gulp = require('gulp');
require('gulp-grunt')(gulp); // add all the gruntfile tasks to gulp

// continue defining tasks...
gulp.task('do-this', function() {
  ...
});

// run them like any other task
gulp.task('default', [
  // run complete grunt tasks
  'grunt-minify',
  'grunt-test',
  // or run specific targets
  'grunt-sass:dist',
  'grunt-browserify:dev'
]);

Note that all the grunt tasks that were added begin with the prefix 'grunt-'. This is for usability, so that your grunt tasks do not clash with your gulp tasks. Also note that require('gulp-grunt')(gulp) does not have to be at the top of your file. It could very well be at the bottom, except that then it could possibly overwrite some of your gulp tasks.

To run specific targets, use the regular grunt syntax [task]:[target], as in the example above. (To learn more about Grunt targets, check out the Grunt documentation.)

Functions

gulp-grunt()

Takes (gulp, options)

Configuration is done with the function call:

require('gulp-grunt')(gulp, {
  base: ...,
  prefix: ...
});

This function appends all the grunt tasks it has found to your gulp object as normal gulp tasks.

gulp

Your gulp object that you imported with the code:

var gulp = require('gulp');

Pass it in and gulp-grunt will add all the tasks.

options

options is the configuration object you pass in.

options.base

This tells grunt where to look for your gruntfile. Set it to some absolute path. This may require you to use path.join for relative paths:

require('gulp-grunt')(gulp, {
  base: require('path').join(__dirname, 'yourrelativepathhere')
});

options.prefix

This tells gulp-grunt how to prefix your tasks. For instance, if in the gruntfile you define the tasks 'minify' and 'compile', and if you pass gulp-grunt this configuration:

require('gulp-grunt')(gulp, {
  prefix: 'theknightswhosay-'
})

The grunt tasks can be called from gulp, except they would have the prefix, so 'theknightswhosay-minify' and 'theknightswhosay-compile'.

You can simply pass in an empty string('') if you wish to have no prefix.

options.verbose

If this option is enabled(true), then gulp-grunt will tell you when it starts running a Grunt task or stops it. This option is mainly for debugging.

options.force

If this option set to true, grunt task will never fail, but just give you a warning instead.

default options

{
  base: null, // this is just the directory that your Gulpfile is in
  prefix: 'grunt-',
  verbose: false,
  force: true
}

gulp-grunt.tasks()

Takes (options)

This just returns all the grunt tasks found, along with their associated functions. Calling is essentially the same as with the main function:

var gulp_grunt = require('gulp-grunt')
var tasks = gulp_grunt.tasks({
  base: ...,
  prefix: ...
});

Output is something like:

{
  'grunt-test': [Function],
  'grunt-minify': [Function]
  // etc...
}

options

This object is the exact same as for gulp-grunt() above. This tells gulp-grunt what prefix to use and what base to search for, among other things.


Have fun grunting and gulping! :D




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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