# grunt-umd

> Surrounds code with the universal module definition.

Latest version **3.0.0** (published 2017-12-04) · 0 weekly downloads

## Install

```sh
npm install grunt-umd
pnpm add grunt-umd
yarn add grunt-umd
bun add grunt-umd
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2017-12-04 |
| First published | 2013-02-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 95 |
| Author | Juho Vepsalainen |
| Maintainers | alexlawrence, bebraw, boneskull |

## Links

- npm: https://www.npmjs.com/package/grunt-umd
- Repository: https://github.com/bebraw/grunt-umd
- Issues: https://github.com/bebraw/grunt-umd/issues
- npm.io page: https://npm.io/package/grunt-umd

## Dependencies (2)

- [xtend](https://npm.io/package/xtend.md) ^4.0.1
- [libumd](https://npm.io/package/libumd.md) ^0.9.0

## Recent versions

- 3.0.0 (latest) — 2017-12-04
- 2.3.0-beta2 (beta) — 2015-02-07
- 2.4.0 — 2016-11-17
- 2.3.6 — 2016-05-25
- 2.3.5 — 2015-11-22
- 2.3.4 — 2015-10-02
- 2.3.3 — 2015-03-17
- 2.3.2 — 2015-02-24
- 2.3.1 — 2015-02-11
- 2.3.0 — 2015-02-07
- 2.3.0-beta1 — 2014-12-30
- 2.2.1 — 2014-11-24
- 2.2.0 — 2014-11-23
- 2.0.1 — 2014-09-27
- 2.0.0 — 2014-08-14
- … 9 more at https://npm.io/package/grunt-umd/versions

## README

# grunt-umd

Grunt task to surround JavaScript code with the [universal module definition](https://github.com/umdjs/umd/).

## Usage

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

Add the following line to your project's Gruntfile:

```javascript
grunt.loadNpmTasks('grunt-umd');
```

Then configure the task:

```javascript
grunt.initConfig({
  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](https://github.com/bebraw/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:

```bash
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.

## Templates

The following predefined [Handlebars](http://handlebarsjs.com/)-templates are available:

* `umd` - the default template; the template is based on [umd/returnExports.js](https://github.com/umdjs/umd/blob/master/templates/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.

## Demo

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.

## Contributors

* [Alex Lawrence](https://github.com/alexlawrence) - Project founder, previous maintainer
* [Juho Vepsäläinen](https://github.com/bebraw) - Handlerbars fixes etc., current maintainer
* [Stéphane Bachelier](https://github.com/stephanebachelier) - Code indentation option
* [Milan Adamovsky](https://github.com/adamovsky) - Enhanced configurability and Rails assets pipeline support
* [Brian J. Miller](https://github.com/brianjmiller) - Indent only non-empty lines
* [Denis](https://github.com/gamtiq) - Add default value for objectToExport and template option support
* [Boris Cherny](https://github.com/eighttrackmind) - Properly export module IDs containing dashes to browser globals
* [Paulo Gaspar](https://github.com/paulogaspar7) - Fix GitHub user name at repo and homepage URLs
* [tomyouds](https://github.com/tomyouds) - Ignore indent option for empty lines
* [Rameş Aliyev](https://github.com/ramesaliyev) - Browserify example
* [Daniel Koch](https://github.com/dak0rn) - Fixed link to UMD template
* [Louis Ameline](https://github.com/louisameline) - Made the `dest` property optional
* [@timeiscoffee](https://github.com/timeiscoffee) - Updated `libumd` version. #35

## License

MIT. See LICENSE for more info.

---
_Source: https://npm.io/package/grunt-umd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
