posts:jam: Discuss the user-facing JavaScript packager
authorW. Trevor King <wking@tremily.us>
Fri, 20 Sep 2013 18:38:43 +0000 (11:38 -0700)
committerW. Trevor King <wking@tremily.us>
Thu, 12 Dec 2013 18:20:33 +0000 (10:20 -0800)
posts/Jam.mdwn [new file with mode: 0644]

diff --git a/posts/Jam.mdwn b/posts/Jam.mdwn
new file mode 100644 (file)
index 0000000..d1533fb
--- /dev/null
@@ -0,0 +1,59 @@
+[Jam][] is a package manager for front-end [JavaScript][].  While you
+want to use [[npm|Node]] for server-side stuff, Jam is the tool to use
+for JavaScript that you'll be sending to your users.  Following the
+[docs][] (with my already-configured [[`~/.local` prefix|Node]]):
+
+    $ npm install -g jamjs
+
+Integrating with Django is a bit tricky, especially since Jam doesn't
+manage the CSS, images, … that are often associated with JavaScript
+libraries.  If you need that, you probably want to look at [[Bower]]
+instead.
+
+Write a setup `package.json` defining your project's dependencies:
+
+    {
+      "name": "myproject",
+      "version": "0.0.1",
+      "description": "An example project"
+      "dependencies": {
+        // NPM dependencies go here…
+        "async": "0.1.22"
+      },
+      "jam": {
+        "packageDir": "apps/my-app/static/js/",
+        "baseUrl": "apps/beehive_common",
+        "dependencies": {
+          // Jam dependencies go here…
+          "jquery": "1.7.1",
+          "underscore": null
+        }
+      }
+    }
+
+Install your dependencies with:
+
+    $ jam install
+
+Upgrade with:
+
+    $ jam upgrade
+
+Compile just the bits you use into a single require-able replacement.
+
+    $ jam compile apps/my-app/static/js/require.js
+
+This last bit is really cool, and where a less JavaScript-oriented
+tool like [[Bower]] falls short.  [Jam is using][jam-compile] the
+[RequireJS optimizer][optimizer] under the hood for the task, so if
+you don't use Jam you can always run the optimizer directly.
+
+[[!tag tags/programming]]
+[[!tag tags/tools]]
+[[!tag tags/web]]
+
+[Jam]: http://jamjs.org
+[JavaScript]: http://en.wikipedia.org/wiki/JavaScript
+[docs]: http://jamjs.org/docs
+[jam-compile]: https://github.com/caolan/jam/blob/master/lib/commands/compile.js#L8
+[optimizer]: http://requirejs.org/docs/optimization.html