Surrounds code with the universal module definition.

npm install grunt-umd
6 downloads in the last day
56 downloads in the last week
349 downloads in the last month


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


Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-umd

Add the following line to your project's grunt.js gruntfile:


Then configure the task:

    umd: {
        all: {
            src: 'path/to/input.js',
            dest: 'path/to/output.js', // optional, if missing the src will be used
            template: 'path/to/template.hbs', // optional; a template from templates subdir can be specified by name (e.g. 'umd');
                // if missing the templates/umd.hbs file will be used
            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
            indent: '  ', // optional, indent source code
            deps: { // optional
                'default': ['foo', 'bar'],
                amd: ['foobar', 'barbar'],
                cjs: ['foo', 'barbar'],
                global: ['foobar', 'bar']

And finally use it:

grunt umd:all


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.


Examine Gruntfile.js, install dependencies (npm install) and execute grunt. You should see some /output.

npm loves you