Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2011 09:21
Show Gist options
  • Save orlin/1151166 to your computer and use it in GitHub Desktop.
Save orlin/1151166 to your computer and use it in GitHub Desktop.
Backbone.history.start() # see - error
class exports.RootView extends Backbone.View
el: $ '#container'
template: '_.jade'
initialize: ->
_.bindAll @render
render: ->
$(@el).append jadeify @template
# console.log('root view rendered')
# a piece of browserified express app
# ...
browserify = require 'browserify'
jadeify = require 'jadeify'
bundle = browserify
require: [ 'underscore'
, 'underscore.string'
, 'backbone'
, {jquery: 'jquery-browserify'}
entry: ["#{__dirname}/app/"]
bundle.use jadeify "#{__dirname}/app/templates",
watch: true
extension: '.jade'
# ...
window._ = require "underscore"
window._.mixin require "underscore.string"
require "./" # = _.mixin(s)
window.Backbone = require "backbone"
window.jadeify = require "jadeify"
window.onload = ->
# Backbone app bootstrapping =
models: {}
collections: {}
views: {}
initialize: ->
this.views.home = new (require './views/_view').RootView()
this.router = new (require('./router').ChartraRouter)() # last (it renders upon instantiation)
# app.router.navigate 'home', true if Backbone.history.getFragment() is ''
# console.log "#" + Backbone.history.getFragment() # ok
# Backbone.history.start() # Uncaught TypeError: undefined is not a function
# {root: '/', pushState: true, silent: true}
# The document is in copletely ready state.
if window.document.readyState is 'complete'
class exports.ChartraRouter extends Backbone.Router
'': "home"
blank: "blank"
initialize: ->
this.navigate '', true # @home()
# the it
home: ->
# to illustrate Backbone.history #fail
blank: ->
Copy link

Any luck/feedback on this issue yet?

Copy link

Yes, actually. You need to first 'npm install jquery', then modify Backbone.js to 'require('jquery')' as in line 35 here:

from this repo:

Copy link

Thanks for the pointers. We solved it by patching backbone.js and then using a custom npm module and aliasing that inside browserify. Works like a charm.

Copy link

orlin commented Sep 7, 2011

I ended up loading backbone (and other libs) via ender. Browserify is still useful within the same project - just not being used to its possible max. Patching backbone.js seems like unnecessary maintenance...

Copy link

cjroebuck commented Sep 7, 2011 via email

Copy link

orlin commented Sep 7, 2011

Just keep in mind require(...) is contentious - many would like to claim it. Right now, I require Ender-ed libs first. Browserify requires next.

Copy link

You don't have to manually patch any libraries to make them browserifiable anymore.
browserify-shim takes care of that for you

Works with all libraries I have encountered so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment