Fork me on GitHub

Using uRequire

Simple old CLI

uRequire can be used in its simplest form via the CLI, running $ urequire .... See Installing uRequire and CLI-options.

As a simple CLI example that converts all modules to UMD, you should execute:

urequire UMD ./src -o ./build -v -w

This will convert all modules in ./src using UMD template and place them onto ./build, using verbose & watch options.

Config Files

Alternatively you can have one or more config files as input to your CLI execution:

urequire config WidgetConfig.coffee,ProjectConfig.json -d 10

This will run uRequire using values from WidgetConfig.coffee and ProjectConfig.json, the left ones having precedence over ones on the right (those on the right are similar to defaults).

A config file is ususally a node module that exports the config object. It can be a .coffee or .js node module, or a .json file as well as many other formats - see butter-require.

An example:

# myConfig.coffee
module.exports = {
  main: 'MainModule'
  path: './source/code'
  filez: ['**/*.*', '!**/draft/*.*']
  template: 'combined'
  dstPath: './build/dist/uberscore-dev.js'
  optimize: true
  debugLevel: 20
}

CLI options can also be passed, having precedence over all config files. In general uRequire config files are much more powerful and versatile than plain CLI options - see MasterDefaultsConfig.coffee

Using with grunt & grunt-urequire

You can use the grunt-urequire plugin for gruntjs, using the same configuration format as in config files. Each config object becomes a grunt target/task and you can derive one from another or simply inherit _defaults.

Using within your code

Within your tool's code, using urequire.BundleBuilder endpoint like this:

childConfig = {...}; parentConfig = {...};
urequire = require('./urequire');
bundleBuilder = new urequire.BundleBuilder([childConfig, parentConfig]);
bundleBuilder.buildBundle();  # build the given `bundle` with given `build`
bundleBuilder.watch();        # optionally watch for changes, rebuilding as needed