咕噜:自定义任务怎么发展到 [英] Grunt: custom task development how-to

查看:126
本文介绍了咕噜:自定义任务怎么发展到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现自定义咕噜任务,我完全失去了对开发流程。

I need to implement a custom Grunt task and I'm absolutely lost about the development workflow.


  1. 如何开发一个自定义任务,我可模拟在开发过程中使用NPM加载它?

  2. 有分发自定义任务,而不是使用任何其他方式 NPM ?我的意思是,我可以分发定义了整个定制咕噜任务,并在 Gruntfile.js 直接?
  3. 导入JavaScript文件
  1. How do I develop a custom task and I simulate loading it using npm during development?
  2. Is there any other way of distributing custom tasks instead of using npm? I mean, can I distribute a JavaScript file defining the whole custom Grunt task and import it in the Gruntfile.js directly?

由于整个任务将是在一个非常早期的发展阶段,在 NPM 出版它的可能的努力是不是一个好主意。

Since the whole task would be in a very early development stage, maybe the effort of publishing it in npm isn't a good idea.

先谢谢了。

推荐答案

自定义咕噜任务基本上都是节点模块,可以发布到故宫注册表。看看现有的,以及如何将它们在这里建的文档:

custom grunt tasks are basically node-modules which you can publish to the npm registry. take a look at existing ones, and the documentation how to build them here:

http://gruntjs.com/api/grunt.task

基本上你只是做这样的事情:

basically you just do something like this:

module.exports = function (grunt) {

  // or use grunt.registerMultiTask
  grunt.registerTask('your-taskname', 'your task description', function () {
  });
};

要很容易让你,你应该使用咕噜-INIT 用的咕噜-INIT-gruntplugin 基本上完成所有设置为您服务!

to make it easy for you, you should use grunt-init with the grunt-init-gruntplugin which basically sets everything up for you!

如果你不想你的模块发布到NPM,您可以在您的项目从一个Gi​​t仓库安装(例如使用github上):

if you dont want to publish your module to npm, you can install it in in your project from a git repository (for example using github):

$ npm install git+https://github.com/your-user/your-repository --save

在--save选项自动保存它作为依赖,项目的package.json。

the --save option saves it automatically as a dependency into projects package.json.

如果你只是想在你的任务你的项目一个js文件,把在你选择的目录(我用咕噜任务在这里),并将其包含在你的gruntfile这样的:

if you just want to include a single js file in your project with your task, put that in a directory of your choice (i use grunt-tasks here), and include it in your gruntfile like that:

grunt.loadTasks("./grunt-tasks");

这将尝试包括在那个目录中的咕噜每个任务的js文件。

that will try to include every js-file in that directory as grunt tasks.

这篇关于咕噜:自定义任务怎么发展到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆