TroopJS bundles are pre-built scripts that has all the predefined modules included.
$ (sudo) npm install -g bower $ cd $app $ bower init
To install TroopJS and its dependencies from your project dir:
$ cd $app $ bower install requirejs when poly jquery troopjs#~3.0.0
Otherwise you may download the latest release bundle and extract it in your prefered directory.
$ curl -L -O https://api.github.com/repos/troopjs/troopjs/zipball/3.0.0 $ unzip DOWNLOADED_FILE_NAME.zip
Since TroopJS makes use of AMD modules, we recommend the use of requireJS package to locate all module dependencies. The following HTML page exemplifies the configuration:
To verify that the TroopJS bundle modules are actually loaded, issue the following line on the page:
require('troopjs/version' ) // 3.0.0 - 1 (the TroopJS bundle version)
In certain scenarios it may not be ideal to use the TroopJS bundle:
Since TroopJS is highly modularized and AMD compatible, you can specify individual dependencies in your bower.json file. For example, the following config puts restraints over some browser-related troop modules while staying loose with the other core+ modules:
The config provided followed by
bower install will install the required
troopjs-* dependencies as well as all required 3rd-party libraries that an individual module relies on.
Note: You will get prompted by bower about version conflicts if peer dependency versions are not satisfied. If it happens, you can resort to the "resolutions" field to resolve version conflicts
With the same requireJS configuration above plus a small modification (git grid of the 'troopjs' package definition section), the page will load with all TroopJS modules loaded from source with module path resolved as their package location.
The laziest way to install TroopJS is to use yeoman generator which will take care of scaffolding and generating the minimal amount of code for an initial state:
$ (sudo) npm install -g yo $ npm install generator-troopjs
To generate a TroopJS application:
$ cd $app $ yo troopjs
After answering a few questions, the generator will give you the following application scaffold where you can start from:
Find an error? Let us know →