You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.7 KiB

  1. [Grunt homepage](https://github.com/gruntjs/grunt) | [Documentation table of contents](toc.md)
  2. # Plugins
  3. This section is a work in progress. Grunt currently has preliminary plugin support, but it might be a little while before plugins work perfectly. If you have any suggestions or comments, please [file an issue](/gruntjs/grunt/issues) and we'll work it all out!
  4. ## Why create a grunt plugin?
  5. Publishing a "grunt plugin" to Npm gives you 3 possible things:
  6. 1. An easily-included-in-your-project set of tasks that get referenced in `grunt.js` when run via `grunt`.
  7. 2. A custom global binary that is like "some version of grunt, plus your specific extra stuff."
  8. 3. Either 1 or 2, depending on whether the plugin was installed globally or locally via Npm.
  9. Other than that, it's not too much more than a specific directory structure, contain some number of task files. You load a plugin locally installed via Npm via [grunt.loadNpmTasks](api.md), and you load tasks from a directory via [grunt.loadTasks](api.md).
  10. ## Plugin creation and development
  11. 1. Run `grunt init:gruntplugin` in an empty directory.
  12. 2. Run `npm install` to install grunt locally.
  13. 3. Run `./node_modules/.bin/grunt` to run the plugin-specific grunt. Just `grunt` won't work.
  14. 4. When done, run `npm publish` to publish the grunt plugin to npm!
  15. ## Two usage options
  16. ### 1. Global install, where you run `grunt-yourplugin`
  17. 1. Run `npm install -g grunt-yourplugin`. This installs the plugin globally, which contains its own internal grunt (the version specified in the plugin's package.json).
  18. 2. A new `grunt-yourplugin` binary should be globally available.
  19. 3. When run from that binary, the internal grunt runs, and provides grunt's internal tasks and helpers plus all the plugin's tasks and helpers.
  20. Notes:
  21. * When executed via the plugin binary, eg. `grunt-yourplugin`, the internally-specified grunt will be used. This allows you to "lock in" a specific version of grunt to your plugin.
  22. ### 2. Local install, where you run `grunt`
  23. 1. Grunt should already have been installed globally with `npm install -g grunt`.
  24. 2. In your project's root, next to the grunt.js gruntfile, run `npm install grunt-yourplugin`.
  25. 3. Add [grunt.loadNpmTasks('grunt-yourplugin')](api.md) into the project's grunt.js gruntfile.
  26. 2. Run `grunt` and all of the `grunt-yourplugin` tasks and helpers should be available in addition to those already provided by grunt..
  27. Notes:
  28. * Multiple plugins, eg. `grunt-yourplugin` and `grunt-anotherplugin` can be installed locally via Npm.
  29. * [grunt.loadNpmTasks('grunt-yourplugin')](api.md) should behave exactly the same as [grunt.loadTasks('./node_modules/grunt-yourplugin/tasks')](api.md) does. It's less to type though, which is awesome.
  30. ## TODOS
  31. * More docs.