Grunt: custom task development how-to

♀尐吖头ヾ 提交于 2019-12-04 04:57:30

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 () {
  });
};

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

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

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

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");

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!