Skip to content

Instantly share code, notes, and snippets.

@athap
Last active December 10, 2015 09:48
Show Gist options
  • Save athap/4416584 to your computer and use it in GitHub Desktop.
Save athap/4416584 to your computer and use it in GitHub Desktop.
Content of application.js for adding Require.js to Backbone.js application
-----------------------------------------------
application.js
-----------------------------------------------
require [
'backbone',
'path/to/router/with/index/handler'],
(Backbone, IndexRouter) ->
$ ->
Main = new IndexRouter()
Backbone.history.start()
-----------------------------------------------
requirejs.yml
-----------------------------------------------
modules:
- name: 'application'
shim: {
'backbone': {
# These script dependencies should be loaded before loading
# backbone.js
deps: ['underscore', 'jquery'],
# Once loaded, use the global 'Backbone' as the
# module value.
exports: 'Backbone'
}
}
------------------------------------------------
MainRouter.js
------------------------------------------------
define [
'backbone'],
(Backbone, $) ->
class IndexRouter extends Backbone.Router
routes:
'': 'index'
index: () ->
alert("wooo..It works")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment