Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 95 lines (66 sloc) 4.654 kB
e71dcca @samleb Add a README.markdown file
samleb authored
1 modulr
2 ======
3
4 Description
5 -----------
6
c048210 @tobie Expand README.
authored
7 `modulr` is a [CommonJS module implementation](http://commonjs.org/specs/modules/1.0.html)
bed3408 @tobie Fix README file.
authored
8 in Ruby for client-side JavaScript. It accepts a singular file as input (the _program_) on
9 which is does static analysis to recursively resolve its dependencies.
c048210 @tobie Expand README.
authored
10
460eb96 @tobie Add lazy-eval option.
authored
11 The program, its dependencies and a small, namespaced JavaScript library are
91d658a @tobie Improve README file.
authored
12 concatenated into a single `js` file with optional minification through the [YUI Compressor](http://developer.yahoo.com/yui/compressor/). This improves load times by
460eb96 @tobie Add lazy-eval option.
authored
13 [minimizing HTTP requests](http://developer.yahoo.com/performance/rules.html#num_http).
14 Further load time performance improvements are made possible by the built-in
15 [lazy evaluation](http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-series-reducing.html)
16 option. Modules are delivered as JavaScript strings--instead of functions--and are
17 evaluated only when required.
c048210 @tobie Expand README.
authored
18
e8aeab2 @tobie Minor corrections to README file.
authored
19 The bundled JavaScript library provides each module with the necessary `require`
91d658a @tobie Improve README file.
authored
20 function and `exports` and `module` free variables. In its full version, the bundled
21 library also provided support for the [`require.ensure`](http://wiki.commonjs.org/wiki/Modules/Async/A) (async module requires) and [`require.define`](http://wiki.commonjs.org/wiki/Modules/Transport/D) (module transport) methods.
22
23 `modulr` can also be used as a build tool for JavaScript code that will be executed in a regular JS environment. In this case, the global variable defined by the `--global-export` option is assigned the `exports` of the main CommonJS module and asynchronous module requires are not supported.
24
25 Finally, `modulr` allows you to create handy [dependency graphs](http://modulrjs.org/spec_dependency_graph.html).
c048210 @tobie Expand README.
authored
26
bed3408 @tobie Fix README file.
authored
27 * [Github repository](http://github.com/codespeaks/modulr)
28 * [Specification](http://wiki.commonjs.org/wiki/Modules/1.0)
29
30 Install
31 -------
32
33 $ [sudo] gem install modulr
34
35 Usage
36 -----
37
256a688 @samleb Add command line usage to README
samleb authored
38 `modulr` is available as a Ruby library or as a command-line utility (`modulrize`).
39
40 To process a JavaScript source file, just run:
41
42 $ modulrize filename.js > output.js
43
71bc880 @tobie Allow simultaneous exporting and dependency resolving of numerous mod…
authored
44 You can also simultaneously process multiples files like so:
45
46 $ modulrize filename.js other_filename.js > output.js
47
91d658a @tobie Improve README file.
authored
48 Options are as follows:
49
50 -o, --output=FILE Write the output to FILE. Defaults to stdout.
51 -r, --root=DIR Set DIR as root directory. Defaults to the directory containing FILE.
52 --lazy-eval [MODULES] Enable lazy evaluation of all JS modules or of those specified by MODULES.
53 MODULES accepts a comma-separated list of identifiers.
54 --minify Minify output using YUI Compressor.
71bc880 @tobie Allow simultaneous exporting and dependency resolving of numerous mod…
authored
55 --global-export[=GLOBAL_VAR] If GLOBAL_VAR is specified and only one module is being processed, exports it to the GLOBAL_VAR global variable.
56 If GLOBAL_VAR is specified and multiple modules are being processed, exports each one of them as a property of GLOBAL_VAR.
57 If GLOBAL_VAR isn't specified, exports the module to global variables corresponding to their identifier.
f2fe0f3 @tobie Add a main_module option.
authored
58 --main-module=MAIN_MODULE Set the identifier of the main module (available through `require.main`).
71bc880 @tobie Allow simultaneous exporting and dependency resolving of numerous mod…
authored
59 --sync Load all dependencies synchronously.
91d658a @tobie Improve README file.
authored
60 --dependency-graph[=OUTPUT] Create a dependency graph of the module.
61 -h, --help Show this message.
62
63 Minification options (these are forwarded to YUI Compressor without the "minify-" prefix):
256a688 @samleb Add command line usage to README
samleb authored
64
91d658a @tobie Improve README file.
authored
65 --minify-disable-optimizations Disable all micro optimizations.
71bc880 @tobie Allow simultaneous exporting and dependency resolving of numerous mod…
authored
66 --minify-nomunge Minify only, do not obfuscate.
67 --minify-verbose Display informational messages and warnings.
68 --minify-line-break COLUMN Insert a line break after the specified column number.
69 --minify-preserve-semi Preserve all semicolons.
70
c048210 @tobie Expand README.
authored
71
e71dcca @samleb Add a README.markdown file
samleb authored
72 Specs
73 -----
74
c048210 @tobie Expand README.
authored
75 To run the specs, first clone the Git repository then grab the CommonJS
76 specs, included as a Git submodule, by running:
e71dcca @samleb Add a README.markdown file
samleb authored
77
78 $ git clone git://github.com/codespeaks/modulr.git
79 $ cd modulr
80 $ git submodule init
81 $ git submodule update
82
83 [Mozilla's SpiderMonkey](http://www.mozilla.org/js/spidermonkey/) is required
84 and the `js` command line executable must be available on the load path (try `which js`).
85
c048210 @tobie Expand README.
authored
86 You can run all the specs by issuing:
e71dcca @samleb Add a README.markdown file
samleb authored
87
88 $ rake spec
89
c048210 @tobie Expand README.
authored
90 Alternatively, a list of comma-separated specs can be specified through the `SPECS`
91 environment variable (see `vendor/commonjs/tests/modules/1.0`) for a comprehensive
e71dcca @samleb Add a README.markdown file
samleb authored
92 list of available specs).
93
c048210 @tobie Expand README.
authored
94 $ rake spec SPECS=absolute,transitive
Something went wrong with that request. Please try again.