Package Management Options in JavaScript

Parts

As browsers and HTML have matured, our ability to create wonderful experiences has become easier and better, but our code has become more complex. To aid this complex development, we rely on packages such as JQuery, Bootstrap, etc.

But with the use of packages comes the need for package and dependency management. Ruby has RubyGems and Node.js has NPM, but we also need something for the browser. Here are a few of the more popular choices and how they approach dependency/package management.

Bower – A Package Manager for the Web

Bower is a package management system and a module loader in one. Created by Twitter, Bower runs over git and can load all types of packages from JavaScript (like JQuery) to CSS/HTML-based packages (like Bootstrap). Unfortunately, that’s as far as Bower goes. It doesn’t try to optimize the JavaScript or work with any other packages like NPM.

I find the configuration of Bower to be simple and very similar, compared to other package management systems I’ve used before. There are a large number of components available for Bower, and they’re easily discoverable. For simple projects, this seems like a really good fit that will stay out of your way and allow you to load and work with packages how you want.

Guide to Bower

RequireJS – A Javascript Module Loader

RequireJS provides both a package management system and an optimizer for loading your JavaScript files. It can be used both on the web and in other JavaScript environments like Node.

RequireJS builds on top of the Asynchronous Module Definition (AMD), allowing a simple interface to take advantage of that technology. RequireJS does not appear to provide a set of packages, but is instead just a way to load packages that you get either through NPM or Jam.

RequireJS has a great interface for loading modules and would be a great fit for a large project with lots of dependencies. Especially for areas where optimization is crucial.

Guide to RequireJS

Jam – Putting the Browser First

Jam provides a command line way to find and download packages that can then be loaded via RequireJS. Jam can also be configured with a json file, like Bower, allowing you to define packages, versions, and dependencies.

Jam really builds on RequireJS, and the two together feel like a really solid way to find, manage, and deliver packages over a variety of JavaScript platforms.

Browserify – Require Modules in the Browser

Browserify bases its interface off of the node.js require and allows you to load npm modules into the browser. Browserify is the only one of the package managers which looks at it from a testing standpoint. Although their documentation and site don’t look as polished having, a eye on TDD is a great first step. NPM is one of, if not the only, largest package system for JavaScript, so it’s likely you’d be able to find any package you’d need.

It’s great to see package management and dependency management coming to the browser. Any of the tools seems like a great choice and a great way to manage and make heavy use of JavaScript.