incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Burke <>
Subject Re: CommonJS and AMD (and, not or)
Date Fri, 09 Dec 2011 01:55:11 GMT
On Thu, Dec 8, 2011 at 9:33 AM, Patrick Mueller <> wrote:
> I have no answers, only questions.  But I do have a preference of
> convention over configuration, and sniffer utilities are too fragile for me.

I just joined this list a little while ago (maybe 1-2 weeks). I'm the
main developer for RequireJS, an AMD loader.

I missed the other modular discussions on this list, but I did write
up some thoughts after I was asked what it might look like to use AMD
either as part of phonegap core or as part of an end developer's

That doc mentions how require.js can be used in dev, to get individual
files loaded for debugging, but then have it build down to just one
file that uses the small almond implementation of AMD.

As for file conversions, for plain JS and AMD, an almond-type loader
is fine, and for dev, requirejs can handle both of those. For CommonJS
or node modules, the guidance could just be "make sure you convert to
AMD before you bring it into your phonegap project, here is a utility
to do that".

If the developer just wants to go old school plain script tags, that
should be allowed, but not to expect to use any functionality from a
cjs/node module set.

I think AMD is a great fit for phonegap apps, even if for phonegap
core it is some commonjs variant that is built to a set of optional
AMD modules. I'm just happy to answer any other questions about using
AMD in a phonegap app -- I use it now in an experimental app that
targets iOS and Android, although the iOS work is mostly a stub at the

the "main" js file for the page shows some AMD use, in particular some
loader plugins that help avoid what would otherwise be some nested
async callbacks:

The other nice thing is the 'env' loader plugin that loads the iOS or
Android phonegap.js and the appropriate plugin JS for that platform.
It also has an env setup for desktop browser, so I can try some of the
interface without having to use a device. The end result -- I just
have one www directory that I use for Android/iOS and desktop browser


View raw message