From 2abb3a9f4f2df16cc445f2833dbe530ca4633919 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 20 Sep 2013 11:38:43 -0700 Subject: [PATCH] posts:jam: Discuss the user-facing JavaScript packager --- posts/Jam.mdwn | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 posts/Jam.mdwn diff --git a/posts/Jam.mdwn b/posts/Jam.mdwn new file mode 100644 index 0000000..d1533fb --- /dev/null +++ b/posts/Jam.mdwn @@ -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 -- 2.26.2