This template is a starting point for developing modern javascript modules and libraries. Dependency management is handled by the AMD loader RequireJS. Unit testing is implemented with the BDD framework Jasmine. Compilation is handled with r.js and almond via node, or using the javascript build tool grunt
Whichever method you use, the result is a single file with no external dependencies that runs in Node or the browser (with AMD, or as an inline script).
Kick off the requirejs optimizer by hand:
node vendor/r.js -o build.js
If your project does not require a browser environment, run Jasmine tests with node.
node test/runner-node
If your project does require a browser, start a webserver in the root directry.
servedir
...and browse to http://localhost:8000/test/runner.html
Start by installing grunt and a few required tasks:
npm install -g grunt
npm install
Then, use grunt to run your tests in a headless browser (PhantomJS), or kick off the RequireJS optimizer from any path inside the root of your project using these commands:
grunt test
grunt requirejs
To run tests, optimize and minify your library with a single command, call grunt with no arguments.
grunt
In order for the jasmine task to work properly, PhantomJS must be installed. Unfortunately, PhantomJS cannot be installed automatically via npm or grunt, so you need to install it yourself. There are a number of ways to install PhantomJS.
- PhantomJS and Mac OS X
- PhantomJS Installation (PhantomJS wiki)
Note that the phantomjs
executable needs to be in the system PATH
for grunt to see it (if you can run "phantomjs" at the command line, this task should work).
- How to set the path and environment variables in Windows
- Where does $PATH get set in OS X 10.6 Snow Leopard?
- How do I change the PATH variable in Linux
- @jrburke for the fantastic tools RequireJS/r.js & almond.
- @cowboy for all of his hard work on Grunt.
- @pivotal for the intuitive testing framework Jasmine.