Surrounds code with the universal module definition (MIT)
Clone or download
Latest commit 3b53e53 Dec 4, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo made the property optional when using a globbing pattern May 25, 2016
tasks indent May 25, 2016
.gitignore Add preliminary support for globbing Dec 30, 2014
.jshintrc Add .jshintrc Jun 3, 2014 chore: Add a change log Dec 4, 2017
LICENSE Add licensing information to README Jun 3, 2014 Improve formatting Nov 17, 2016
package-lock.json 3.0.0 Dec 4, 2017
package.json 3.0.0 Dec 4, 2017


Grunt task to surround JavaScript code with the universal module definition.


Install this Grunt plugin next to your project's Gruntfile with: npm install grunt-umd

Add the following line to your project's Gruntfile:


Then configure the task:

  umd: {
    all: {
      options: {
        src: 'path/to/input.js',
        dest: 'path/to/output.js', // optional, if missing the src will be used

        // optional, a template from templates subdir
        // can be specified by name (e.g. 'umd'); if missing, the templates/umd.hbs
        // file will be used from [libumd](
        template: 'path/to/template.hbs',

        objectToExport: 'library', // optional, internal object that will be exported
        amdModuleId: 'id', // optional, if missing the AMD module will be anonymous
        globalAlias: 'alias', // optional, changes the name of the global variable

        deps: { // optional, `default` is used as a fallback for rest!
          'default': ['foo', 'bar'],
          amd: ['foobar', 'barbar'],
          cjs: ['foo', 'barbar'],
          global: ['foobar', {depName: 'param'}]

And finally use it:

grunt umd:all

Note! If you want to indent the output, consider using some other plugin for that. The output grunt-umd gives is functional but not entirely aesthetic.


The following predefined Handlebars-templates are available:

  • umd - the default template; the template is based on umd/returnExports.js
  • unit - the template that can be helpful to wrap standalone CommonJS/Node modules; it is slightly modified version of umd template; if objectToExport option is not specified then module.exports value will be used by default

The template that should be applied can be specified by template option (e.g. 'umd' or 'unit'). You can create and use your own template (see predefined templates for examples). The path to the template file should be set relative to Gruntfile.


  1. Install dependencies - npm install
  2. Go to demo - cd demo
  3. Go to some demo directory - cd <demo directory>
  4. Execute demo - grunt

You should see some /output after this. Study Gruntfile.js to understand how it generates.



MIT. See LICENSE for more info.