Create non-anonymous AMD Modules

Topics: General
Oct 18, 2012 at 2:39 PM

Is there a way to create non-anonymous AMD Modules in Typescript. When I define a module like this:

export module Bootstrapper {
  export function run() {
    var i = 0;
  }
}

the generated code is:

define(["require", "exports"], function(require, exports) {
  (function (Bootstrapper) {
    function run() {
        var i = 0;
    }
    Bootstrapper.run = run;
  })(exports.Bootstrapper || (exports.Bootstrapper = {}));
})

How can I define a non-anomymous module like this:

define('bootstrapper', ["require", "exports"], function(require, exports) {
  (function (Bootstrapper) {
    function run() {
        var i = 0;
    }
    Bootstrapper.run = run;
  })(exports.Bootstrapper || (exports.Bootstrapper = {}));
})

Thanks in advance

Coordinator
Oct 18, 2012 at 7:00 PM

This is not currently possible, but is something that has come up previously.  I'll move this over to the issue tracker as a request.

Out of curiosity though - why do you want to name the module?  AMD compatible loaders can resolve module names from the file path, and tools like r.js can be used to collapse into single files which use explicit names if needed.

Note also that you most likely don't need the extra layer of module here - you probably want to just define the following inside bootstrapper.ts:

export function run() {
    var i = 0;
}
Coordinator
Oct 18, 2012 at 7:01 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 19, 2012 at 2:01 PM

Thanks

Oct 24, 2012 at 8:58 AM

We use ASP.NET MVC 4 Web Optimization to bundle all (or at least most) JavaScript files into one when running productive. But as far as I understood requirejs only allows one anonymous module per file, meaning anonymous modules and bundling (out of requirejs) is not possible.