napa (with a hint of Browserify)
Over the last couple of weeks I’ve been diving deep into the world of Browserify. It felt a little bit strange to use it in the beginning but now I’ve really fallen in love with the CommonJS way of handling dependencies. One thing that’s kind of a bummer though is that far from everything is available on npm1. Thankfully I discovered a nice little tool called napa.
napa is a “helper for installing repos without a package.json
with npm”. It
basically does a git clone
on a repository2 directly into the
node_modules
folder. A basic setup in a package.json
file looks like this:
And if we want to clone more than just a single repository, we can do this:
Using code from the master branch is not always a good idea but luckily we can also specify what tag, branch or commit we want to use:
You might be thinking “this is neat, but can’t I just use Bower”? Absolutely, but one thing that I like about this approach is that your dependencies stays in one place. There’s also a lot of code out there that’s not registered on either npm or in Bower’s registry.
Also, instead of having to do something like this to require a dependency:
We can now do this:
Much better!