JSDoc Integration for Grunt

2.4.1 · maintenance · verified Tue Apr 21

grunt-jsdoc is a Grunt plugin designed to integrate JSDoc 3 documentation generation directly into a Grunt build process. It acts as a wrapper around the JSDoc tool, allowing developers to define documentation sources and output destinations within their Gruntfile.js. The current stable version is 2.4.1. Releases are infrequent, typically occurring to update the underlying JSDoc dependency (e.g., for security patches) or address minor compatibility issues. Its key differentiator is its tight integration into the Grunt ecosystem, providing a task-runner-centric approach to documentation, as opposed to running JSDoc directly from the command line or using a different build tool.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure and run the `grunt-jsdoc` task, including how to use an external JSDoc template like `ink-docstrap`. It shows a complete `Gruntfile.js` and a basic JavaScript file with JSDoc comments for generation.

/* Gruntfile.js */
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jsdoc : {
        dist : {
            src: ['src/**/*.js', 'README.md'],
            jsdoc: './node_modules/.bin/jsdoc',
            options: {
                destination: 'doc',
                template: 'node_modules/ink-docstrap/template',
                configure: 'node_modules/ink-docstrap/template/jsdoc.conf.json',
                encoding: 'utf8'
            }
        }
    }
  });

  // Load the plugin that provides the 'jsdoc' task.
  grunt.loadNpmTasks('grunt-jsdoc');

  // Default task(s).
  grunt.registerTask('default', ['jsdoc']);

};

/* src/example.js */
/**
 * @module MyModule
 * Represents a simple example class.
 */
class MyClass {
  /**
   * Creates an instance of MyClass.
   * @param {string} name - The name of the instance.
   */
  constructor(name) {
    /** @private */
    this._name = name;
  }

  /**
   * Greets the given person.
   * @param {string} person - The person to greet.
   * @returns {string} A greeting message.
   */
  greet(person) {
    return `Hello, ${person}! My name is ${this._name}.`;
  }
}

module.exports = MyClass;

view raw JSON →