npm install geartrain
|14||downloads in the last month|
|Version||0.0.7 last updated a year ago|
|Keywords||dependency_management, loader, concatenate, build, tools|
What's in it
In Require.js fashion, Geartrain comes packed with a compiler and an async loader. The compiler takes as argument an entry point .js file, resolves all its dependencies and spits out a concatenated source file with everything your app needs. The async loader is a .js file that you include in your web page. You specify the entry point .js file you want to load using
Loader.load('entryPoint.js'), and it will asynchronously resolve and load all the dependencies for you.
otherfile.js, use the require directive (in comments)
//= require otherfile
otherfile.js is then looked for in the same directory as the current file. You can use slashes
/ to walk subdirectories. The require directive syntax is the same as the one used in Sprockets.
Integration with Bower
If you want to use Bower to install packages for you, first install Bower. When installing, instead of using
bower install jquery, use
geartrain install jquery
Here is what the
install command does: first it uses Bower to install the package; then it writes the dependency map gotten from
bower list --map to the file
components.json - this is what both the compiler and loader use to resolve dependencies that are provided by Bower. Now you can use a require directive to include jquery
//= require jquery
Using the Compiler
The compiler takes an entry point as parameter, let's say if
main.js is the entry point, you would do
geartrain build main
This will appends all dependencies of main.js in the correct order and output the resulting bundled .js file to
The Configuration File
You use a
geartrain.json to configure the behavior of Geartrain. When you run the
geartrain command, it will trying to look for it at the current directory. You can also specify its location via the
geartrain build main -c mygeartrain.json
Available configuration options
componentsParentDir- the parent directory of the
componentsdirectory generated by Bower. The directory should specified as a relative path from the location of the configuration file
srcDir- the base directory for your project's
.jsfiles. The directory should specified as a relative path from the location of the configuration file
To see all command line options do
Using the Async Loader
In your html page, first include the
geartrain.js - you can find this in the
dist folder, which can be re-built by running
Geartrain.load(entrypoint) to load the entry point file you want.
<script> Geartrain.load('main.js'); </script>
It will asynchronously load all its dependencies. Note: you must serve the files over HTTP, local files won't work.
Geartrain is in Proof of Concept (POC) phase at the moment. Probably shouldn't use it for production just yet.
- Loader does not work when the page is run from the local file system. The loader uses Ajax to retrieve the contents of the .js files, which is subject to the same-origin policy.
(The MIT License)
Copyright (c) 2012 Toby Ho <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.