jquery-backbone-hookupify

0.1.0 • Public • Published

jquery-backbone-hookupify

Small browserify transform to hook up Backbone with jQuery.

The problem

When building a module using Browserify that has dependencies on both Backbone and jQuery, you would require them just as you would any other module:

$ = require('jquery');
Backbone = require('backbone')

Unforutnately, you also have to tell Backbone in every module how to find jQuery:

Backbone.$ = $

This line gets repeated in every module that references jQuery and backbone, which in most projects is every module.

Not very DRY.

The solution

Include jquery-backbone-hookupify in your browserify transforms!

npm install --save-dev jquery-backbone-hookupify

Then pass -t jquery-backbone-hookupify to browserify

browserify -t coffeeify foo.coffee > bundle.js

Any files that require jquery and require backbone will have Backbone.$ = $ inserted immediately after you require backbone.

(note: you should include jQuery before requiring backbone!)

Works with both coffeescript and native js.

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i jquery-backbone-hookupify

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • zeevl