Question

I want to build root namespaces into assemblies that are external modules.
For example:

// File structure (every file is class or interface export)
Deferred/Deferred.ts
Deferred/Promise.ts
WebApp/ClassOne.ts
WebApp/ClassTwo.ts

I want assembly it to:

Deferred.js
WebApp.js

And both those files are AMD modules, so in Deferred.js (and WebApp.js) is something like:

define("Deferred", [], function() {
    (function(Deferred){
        // Here is a definition of a module with submodules
    })(var Deferred || (Deferred = {}));

    return Deferred;
});

How to do that?

Was it helpful?

Solution

Create a file structure like:

// File structure (every file is class or interface export)
Deferred/Deferred.ts
Deferred/Promise.ts
Deferred/index.ts
WebApp/ClassOne.ts
WebApp/ClassTwo.ts
WebApp/index.ts

Where each index.ts imports and re-exports all the stuff from that folder. e.g. Deferred/index.ts:

import deferred_file = require('./Deferred');
export var deferred = deferred_file;
import promise_file = require('./Promise');
export var promise = promise_file;

Then compile this index.ts with amd flag and minify using r.js : http://requirejs.org/docs/optimization.html

PS: there is work being done in grunt-ts to create these index.ts files for you : https://github.com/grunt-ts/grunt-ts/pull/69 which you can work on if you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top