Skip to content

Commit

Permalink
make sure the documentation is clearer with use of dependency options
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Harte committed Oct 5, 2015
1 parent 3b13160 commit 15ff2f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
17 changes: 10 additions & 7 deletions README.md
Expand Up @@ -12,23 +12,26 @@ var umdify = require('libumd');
var result = umdify(js, options);
```

options (all are optional by default):
> `libumd` doesn't guarantee pretty formatting. It is better to use something like [js-beautify](https://www.npmjs.com/package/js-beautify) to deal with that.
## Options

```js
{
template: 'path to template or template name', // defaults to 'umd'
amdModuleId: 'test', // optional AMD module id. defaults to anonymous (not set)
globalAlias: 'alias', // name of the global variable
deps: { // dependencies - `default` acts as a fallback for each!
'default': ['foo', 'bar'],
amd: ['foobar', 'barbar'],
cjs: ['foo', 'barbar'],
global: ['foobar', {depName: 'param'}]
deps: { // dependencies
// use default only if the module name and the variable the module will be injected with is the same
'default': ['Foo', 'Bar'],
// additionally define these if the module name differs from the variable with which it will be used
amd: ['foo', 'bar'],
cjs: ['foo', 'bar']
}
}
```

> Note! `libumd` doesn't guarantee pretty formatting. It is better to use something like [js-beautify](https://www.npmjs.com/package/js-beautify) to deal with that.
> Check out the [`demo.js`](https://github.com/bebraw/libumd/blob/master/demo.js)
## Default Templates

Expand Down
29 changes: 26 additions & 3 deletions demo.js
@@ -1,16 +1,39 @@
'use strict';
var umdify = require('./');


main();

function main() {
var result = umdify('demo();', {
deps: {
'default': ['foobar'],
'amd': ['foo', 'bar'],
// use default only if the module name and the variable the module will be injected with is the same
'default': ['Foo'],
// additionally define these if the module name differs from the variable with which it will be used
'amd': ['foo'],
'cjs': ['foo']
}
});

console.log(result);
/**
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(["foo"], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("foo"));
} else {
factory(Foo);
}
}(this, function (Foo) {
demo();
}));
*/
}

0 comments on commit 15ff2f3

Please sign in to comment.