Modules, Concatenation, and Better Solutions

Patrick Mueller pmuellr at
Tue Oct 16 05:57:18 PDT 2012

On Mon, Oct 15, 2012 at 9:45 AM, Kevin Smith <khs4473 at> wrote:

> OK, so:
>     module A { console.log("a"); export var x; }
>     console.log("$");
>     import x from A;
> Does this print:
>     $
>     a
> or
>     a
>     $

The first - "$", then "a".

At least, that's how most module systems I've played with seem to work -
CommonJS-ish ones I've written and used, and mostly AMD; there was an issue
with the AMD almond loader that it would execute a "module factory" when
the module was define()'d, not when it was first require()'d.  Can't
remember the final stand on that one.  I think most of the AMD loaders will
ensure that factories are not run until needed.

This has worked out quite well, as it means ordering of modules doesn't
matter - Browserify is a good example of this.  It means you don't HAVE to
arrange your modules in any particular order, just make sure they are all
defined before you do your first require().  MUCH, MUCH easier to build
concatenators if you don't care what the order is.

Patrick Mueller
pmuellr at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list