我想将根命名空间构建到外部模块的程序集中。
例如:
// File structure (every file is class or interface export)
Deferred/Deferred.ts
Deferred/Promise.ts
WebApp/ClassOne.ts
WebApp/ClassTwo.ts
我想把它装配到:
Deferred.js
WebApp.js
这两个文件都是AMD模块,所以在Deferred.js(和WebApp.js)中是这样的:
define("Deferred", [], function() {
(function(Deferred){
// Here is a definition of a module with submodules
})(var Deferred || (Deferred = {}));
return Deferred;
});
怎么做?
答案 0 :(得分:2)
创建一个文件结构,如:
// 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
每个index.ts导入并重新导出该文件夹中的所有内容。例如Deferred/index.ts
:
import deferred_file = require('./Deferred');
export var deferred = deferred_file;
import promise_file = require('./Promise');
export var promise = promise_file;
然后使用index.ts
标记编译此amd
并使用r.js缩小:http://requirejs.org/docs/optimization.html
PS:grunt-ts正在开展工作,为您创建这些index.ts
文件:https://github.com/grunt-ts/grunt-ts/pull/69如果您愿意,可以使用这些文件。