Grunt Create Plugins

reference

http://gruntjs.com/creating-plugins

Create plugins

  1. Install grunt-init with npm install -g grunt-init
  2. Install the gruntplugin template with git clone git://github.com/gruntjs/grunt-init-gruntplugin.git ~/.grunt-init/gruntplugin (%USERPROFILE%\.grunt-init\gruntplugin on Windows).
  3. Run grunt-init gruntplugin in an empty directory.
  4. Run npm install to prepare the development environment.
  5. Author your plugin. 实现你自己的 plugin
  6. Run npm publish to publish the Grunt plugin to npm!

Naming Your task

The “grunt-contrib” namespace is reserved for tasks maintained by the Grunt team, please name your task something appropriate that avoids that naming scheme.

Debuging

Grunt hides error stack traces by default, but they can be enabled for easier task debugging with the --stack option. If you want Grunt to always log stack traces on errors, create an alias in your shell. Eg, in bash, you could do alias grunt='grunt --stack'.

Storing task files

Only store data files in a .grunt/[npm-module-name]/ directory at the project’s root and clean up after yourself when appropriate. This is not a solution for temporary scratch files, use one of the common npm modules (eg temporary, tmp) that take advantage of the OS level temporary directories for that case.
只能讲数据文件存放在项目根路径的.grunt/[npm-module-name]/目录中,然后根据需要,可以自行删除。但是,这种方式不适合管理临时文件,要使用临时文件,最好使用temporary或者tmp这样的系统级别的临时文件来处理。

Current Working Directory

process.cwd()将返回当前目录,返回包含Gruntfile的目录路径,用户可以通过grunt.file.setBase()来改变当前目录,但是不建议这么做。
path.resolve('foo') can be used to get the absolute path of the filepath ‘foo’ relative to the Gruntfile

Creating your task

You might also want to know how to [create your own tasks] or take a look at the API reference.