Module naming and declarations

Jason Orendorff jason.orendorff at gmail.com
Fri May 3 16:46:56 PDT 2013


On Thu, May 2, 2013 at 9:47 AM, Andreas Rossberg <rossberg at google.com> wrote:
> I don't see how logical names can possibly make sense without at least
> a rudimentary manager that maps them. Otherwise they are just physical
> names.

Yes. A rudimentary way of mapping logical names to URLs is built into
the proposal: the default resolve behavior.

0. No effort: modules are loaded relative to the document base url,
with ".js" appended. So `import "jquery"` maps to the relative URL
"jquery.js".

1. One line of code: you can set the root URL from which all imports
are resolved. If you set `System.baseURL =
"https://example.com/scripts/"` then `import "jquery"` maps to the URL
"https://example.com/scripts/jquery.js".

2. A few lines: you can use System.ondemand() to set the URL for each
module you use. If you call
`System.ondemand({"https://example.com/jquery-1.9.1.js": "jquery"})`
then `import "jquery"` maps to the URL you specified (imports for
modules that aren't in the table will fall back on the loader's
baseURL).

3. Beyond that: write a resolve hook and locate modules however you want.

-j


More information about the es-discuss mailing list