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 18:40:45 GMT
On Fri, Dec 9, 2011 at 4:31 AM, Patrick Mueller <> wrote:
> At this point I'm fine with using AMD as our module implementation, and
> something the size of almond as our deployment runtime, for folks who want
> to do a "build".  I'm not sure what we do about an AMD runtime that needs
> to load modules dynamically though.  Do we ship one of these with Cordova?
>  Which one?  Is it replaceable?  If we ship RequireJS, can I replace it
> with curl or pinf?

I believe where most AMD loaders differ is some "advanced"
configuration settings, and they each might have a different global
name to enter the loader. From what I have heard, switching from
requirejs to curl is switching out the script name, calling curl()
instead of require() at the global level (or just alias curl). As long
as the project is using the basic config of baseUrl and paths (enough
for most projects) it should be doable.

So, some adjustments, but they should be "top-level" adjustments and
not module reauthoring.

One case that might require touching your module code is the loading
of plain script files. curl uses a loader plugin for that while
requirejs does not, unless you need a few plain scripts loaded in

> Also not clear regarding not-quite-standardized stuff in AMD, like configs
> and plugins. Do all the AMD runtimes support these?  Where is it spec'd?

The config values are not officially specified, although we could
probably start with baseUrl and paths which do seem generally

AMD's define, its use of require, and the loader API are all specified here:

There is a set of compatibility tests too. The loader API's runtime
API is well specified, but we are still discussing the build-time API.

So there is some variability involved, but mostly on the
tooling/top-level loader level, but not for individual module

> So, there's actually a workflow which supports authoring your modules in
> CommonJS.  Your guidance of "make sure you convert to AMD before you bring
> it into your phonegap project" seems to imply that you can't.  Not only can
> you use CommonJS modules, you can author your own CommonJS modules in your
> project, if you're willing to live with the constraint of a build.  Of
> course, you are free to author your module in AMD format as well.

Sorry, it was bad wording on my part. It could be rephrased as "make
sure your module code is a plain browser script or transformed to AMD
before running it". Whether the transform is done via on-the-fly
builds or part of "install time" either should be supported.


View raw message