Skip to content
This repository has been archived by the owner. It is now read-only.
Go to file
Cannot retrieve contributors at this time
182 lines (114 sloc) 4.53 KB


The Duo Javascript API lets you easily add in custom plugins, or advanced logic for when the CLI won't suffice.

new Duo(root)

Initialize a new Duo instance with a path to the package's root directory. All other path settings will be relative to the root directory, including the build and install directories.

var duo = new Duo(__dirname);

duo.entry(file|source, [type])

Specify the entry file that Duo will traverse and transform.


You can also specify the entry by passing in a source source and file type like so:

var source = 'var a = 0;'
duo.entry(source, 'js');

This is useful when you're reading from stdin, or any case where you have the contents of the file itself already in memory.


Set Duo to development mode. This will include development dependencies in your builds and add source maps support. Defaults to false.



Tells duo to include source-maps. When value is:

  • false: (the default) no source-maps will be included
  • true: the external source-maps are generated when using Duo#write().
  • "inline": the source-maps will be generated when using Duo#write().

NOTE: when working with source-maps and Duo#run(), both true and "inline" will include a map property in the returned object. Duo#write() has logic to actually determine between inline and external source-maps.



Turn caching on or off. With caching turned on, plugin transformations will not be called unless the file changes. Defaults to true.



When you add standalone name, Duo will output a single standalone file that can be used anywhere (UMD).


This is very useful when you want to let anyone use your module, duo will add a tiny 5 line function that will check for AMD's define, CommonJS module and export the module with name, if CommonJS and AMD are not found Duo will expose the module on the global scope this['my-module'] = ....


Whether to copy assets to the build directory, instead of the default behavior of symlinking them. Defaults to false.


Specify a global variable name to attach the package's exports to on the window object.'Tip');

That will let you then access the module via:

var Tip = window.Tip;


Set the maximum concurrency Duo uses to traverse dependencies. Defaults to 50.


Set the path to the install directory, where dependencies will be installed. Defaults to ./components.


Set the path to the build directory, where assets will be copied. Defaults to ./build.


Set the GitHub authentication token so you can install dependencies from private repositories. If you do not set this token, Duo will automatically try to load the token from your ~/.netrc file.

Here's how to create a GitHub token:

duo.include(name, src)

Include a file with name and its src without requiring it. This is particularly useful for including runtimes.

duo.include('jade-runtime', ...);


Resolve a series of paths... relative to the package's root directory.

var file = duo.path('component.json');


Resolve a series of paths... relative to the package's install directory.

var folder = duo.path('my-component@1.0.0');


Resolve a series of paths... relative to the package's build directory.

var file = duo.path('some/asset.png');[fn])

Run duo traversing and transforming from entry returning the bundle.

If fn is specified will use fn as its callback but you can also run as a generator.

var src = yield;, results) {
  // results: { code, map }


Run duo traversing and transforming from entry writing to "build/".

If fn is specified duo.write(fn) will use fn as its callback but you can also run duo.write() as a generator.

yield duo.write();
duo.write(function(err) {
  // ...


Apply a plugin to duo. See the plugins documentation for more information.

You can’t perform that action at this time.