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.
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
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
In your html page, first include the
geartrain.js - you can find this in the
dist folder, which can be re-built by running
Loader.load(entrypoint) to load the entry point file you want.
<script> Loader.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.
(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.