mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / Jam.mdwn
1 [Jam][] is a package manager for front-end [JavaScript][].  While you
2 want to use [[npm|Node]] for server-side stuff, Jam is the tool to use
3 for JavaScript that you'll be sending to your users.  Following the
4 [docs][] (with my already-configured [[`~/.local` prefix|Node]]):
5
6     $ npm install -g jamjs
7
8 Integrating with Django is a bit tricky, especially since Jam doesn't
9 manage the CSS, images, … that are often associated with JavaScript
10 libraries.  If you need that, you probably want to look at [[Bower]]
11 instead.
12
13 Write a setup `package.json` defining your project's dependencies:
14
15     {
16       "name": "myproject",
17       "version": "0.0.1",
18       "description": "An example project"
19       "dependencies": {
20         // NPM dependencies go here…
21         "async": "0.1.22"
22       },
23       "jam": {
24         "packageDir": "apps/my-app/static/js/",
25         "baseUrl": "apps/beehive_common",
26         "dependencies": {
27           // Jam dependencies go here…
28           "jquery": "1.7.1",
29           "underscore": null
30         }
31       }
32     }
33
34 Install your dependencies with:
35
36     $ jam install
37
38 Upgrade with:
39
40     $ jam upgrade
41
42 Compile just the bits you use into a single require-able replacement.
43
44     $ jam compile apps/my-app/static/js/require.js
45
46 This last bit is really cool, and where a less JavaScript-oriented
47 tool like [[Bower]] falls short.  [Jam is using][jam-compile] the
48 [RequireJS optimizer][optimizer] under the hood for the task, so if
49 you don't use Jam you can always run the optimizer directly.
50
51 [[!tag tags/programming]]
52 [[!tag tags/tools]]
53 [[!tag tags/web]]
54
55 [Jam]: http://jamjs.org
56 [JavaScript]: http://en.wikipedia.org/wiki/JavaScript
57 [docs]: http://jamjs.org/docs
58 [jam-compile]: https://github.com/caolan/jam/blob/master/lib/commands/compile.js#L8
59 [optimizer]: http://requirejs.org/docs/optimization.html