Skip to content Skip to sidebar Skip to footer

Require.js Alternative Way To Require?

New to require.js. I have this: define([ 'jquery', 'underscore', 'backbone', 'views/sidebar', 'views/dashboard', 'views/users', 'views/venues', 'vie

Solution 1:

You can use AMD sugar:

define(function(require) {

  var $ = require('jquery')
    , _ = require('underscore')
    , Backbone = require('backbone')

    // etc...

I personally prefer this because it’s closer to CommonJS syntax, but there are some browser limitations (it requires Function.prototype.toString) so make sure you pack it using r.js before production.

More examples in the docs: http://requirejs.org/docs/whyamd.html#sugar

Solution 2:

Or you can try more generic and natural solution (not only for JS) http://sourceforge.net/projects/minimerge

It supports full dependencies stack, multiple source trees and is purely java based (and you can use it for content filtering too).

Particulary you end up with:

//:include com/package/Class.js

//any code.

Solution 3:

minimerge is a plain java tool, few KB small and super fast. I use it for my html5 web projects. It also does CSS with dependencies and any text based files ;-)

Post a Comment for "Require.js Alternative Way To Require?"