Fork me on GitHub

CLI options

The simplest was to use uRequire is its CLI, running $ urequire ....

uRequire has a command line converter that needs to be called globally:

    `npm install urequire-cli -g`

You will also need the local 'urequire' to your package: npm install urequire

$ urequire -h

  Usage: urequire [options] [command]

  Commands:

    UMD <path>             Converts all modules in <path> using 'UMD' template.
    UMDplain <path>        Converts all modules in <path> using 'UMDplain' template.
    AMD <path>             Converts all modules in <path> using 'AMD' template.
    nodejs <path>          Converts all modules in <path> using 'nodejs' template.
    combined <path>        Converts all modules in <path> using 'combined' template.
    config <configFiles...>

  Options:

    -h, --help                     output usage information
    -V, --version                  output the version number
    -B, --ver                      Print urequire-cli & urequire versions.
    -o, --dstPath <dstPath>        Output converted files onto this directory
    -f, --forceOverwriteSources    Overwrite *source* files (-o not needed & ignored)
    -v, --verbose                  Print module processing information
    -d, --debugLevel <debugLevel>  Pring debug information (0-100)
    -n, --noExports                Ignore all web `rootExports` in module definitions
    -r, --webRootMap <webRootMap>  Where to map `/` when running in node. On RequireJS its http-server's root. Can be absolute or relative to bundle. Defaults to bundle.
    -s, --scanAllow                By default, ALL require('') deps appear on []. to prevent RequireJS to scan @ runtime. With --s you can allow `require('')` scan @ runtime, for source modules that have no [] deps (eg nodejs source modules).
    -a, --allNodeRequires          Pre-require all deps on node, even if they arent mapped to parameters, just like in AMD deps []. Preserves same loading order, but a possible slower starting up. They are cached nevertheless, so you might gain speed later.
    -p, --dummyParams              Add dummy params for deps that have no corresponding param in the AMD define Array.
    -t, --template <template>      Template (AMD, UMD, nodejs), to override a `configFile` setting. Should use ONLY with `config`
    -O, --optimize                 Pass through uglify2 while saving/optimizing - currently works only for `combined` template, using r.js/almond.
    -C, --continue                 Dont bail out while processing (module processing/conversion errors)
    -w, --watch                    Watch for file changes in `bundle.path` & reprocess them. Note: new dirs are ignored
    -b, --bare                     Don't enclose AMD/UMD modules in Immediately Invoked Function Expression (safety wraper).
    -f, --filez                    NOT IMPLEMENTED (in CLI - use a config file or grunt-urequire). Process only modules/files in filters - comma seprated list/Array of Strings or Regexp's
    -j, --jsonOnly                 NOT IMPLEMENTED. Output everything on stdout using json only. Usefull if you are building build tools
    -e, --verifyExternals          NOT IMPLEMENTED. Verify external dependencies exist on file system.

  [urequire-cli] : Examples:

  $ urequire UMD path/to/amd/moduleBundle -o umd/moduleBundle
                  or
  $ urequire AMD path/to/moduleBundle -f
                  or
  $ urequire config path/to/configFile.json,anotherConfig.js,masterConfig.coffee -d 30

*Notes: Command line values have precedence over configFiles;
        Values on config files on the left have precedence over those on the right (deeply traversing).*

Module files in your bundle can conform to the *standard AMD* format:
    // standard AMD module format - unnamed or named (not recommended by AMD)
    define(['dep1', 'dep2'], function(dep1, dep2) {...});

Alternativelly modules can use the *standard nodejs/CommonJs* format:
    var dep1 = require('dep1');
    var dep2 = require('dep2');
    ...
    module.exports = {my: 'module'}

Finally, a 'relaxed' format can be used (combination of AMD+commonJs), along with asynch requires, requirejs plugins, rootExports + noConflict boilerplate, exports.bundle and much more - see the docs.
    // uRequire 'relaxed' modules format
  - define(['dep1', 'dep2'], function(dep1, dep2) {
      ...
      // nodejs-style requires, with no side effects
      dep3 = require('dep3');
      ....
      // asynchronous AMD-style requires work in nodejs
      require(['someDep', 'another/dep'], function(someDep, anotherDep){...});

      // RequireJS plugins work on web + nodejs
      myJson = require('json!ican/load/requirejs/plugins/myJson.json');
      ....
      return {my: 'module'};
    });

Notes:
  --forceOverwriteSources (-f) is useful if your sources are not `real sources`  eg. you use coffeescript :-).
    WARNING: -f ignores --dstPath

  - Your source can be coffeescript (more will follow) - .coffee files are internally translated to js.

  - configFiles can be written as a .js module, .coffee module, json and much more - see 'butter-require'
  [urequire-cli] : urequire-cli v0.7.1, uRequire v0.6.20