Creating plugins
- 使用
npm install -g grunt-init
安装 grunt-init - 使用
git clone git://github.com/gruntjs/grunt-init-gruntplugin.git ~/.grunt-init/gruntplugin
(Windows 上为%USERPROFILE%\.grunt-init\gruntplugin
)安装 gruntplugin 模板。 - 在空目录中运行
grunt-init gruntplugin
。 - 运行
npm install
准备开发环境。 - 编写您的插件。
- 运行
npm publish
将 Grunt 插件发布到 npm!
注意事项
为您的任务命名
"grunt-contrib" 命名空间是为 Grunt 团队维护的任务保留的,请为您的任务选择一个适当的名称,避免使用该命名方案。
调试
Grunt 默认隐藏错误堆栈跟踪,但可以使用 --stack
选项启用它们以便更轻松地调试任务。如果您希望 Grunt 始终在错误时记录堆栈跟踪,请在您的 shell 中创建一个别名。例如,在 bash 中,您可以执行 alias grunt='grunt --stack'
。
存储任务文件
仅在项目根目录的 .grunt/[npm-module-name]/ 目录中存储数据文件,并在适当的时候清理。这不是临时暂存文件的解决方案,请使用利用操作系统级临时目录的常见 npm 模块(例如 temporary、tmp)。
避免更改当前工作目录:process.cwd()
默认情况下,当前工作目录设置为包含 Gruntfile 的目录。用户可以在其 Gruntfile 中使用 grunt.file.setBase()
更改它,但插件应注意不要更改它。
path.resolve('foo')
可用于获取相对于 Gruntfile
的文件路径 'foo' 的绝对路径。
创建您的任务
Found an error in the documentation?
File an issue.