【发布时间】:2018-04-04 06:56:41
【问题描述】:
我的项目中有一个 tsconfig,它指定了“amd”的模块目标,但是当我的文件编译时,我得到的输出看起来更像 CommonJS。示例:
tsconfig:
{
"compilerOptions": {
"module": "amd",
"target": "es5",
"moduleResolution": "node",
"sourceMap": false,
"newLine": "LF",
"baseUrl": ".",
"lib": ["es5", "es2015.promise", "dom"]
}
}
打字稿文件:
export function test() {
console.log('Starting Up', '<--------------');
}
编译文件:
define(["require", "exports"], function (require, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function test() {
console.log('Starting Up', '<--------------');
}
exports.test = test;
});
预期的编译文件:
define([], function () {
function test() {
console.log('Starting Up', '<--------------');
}
return { test: test };
});
让我失望的是“导出”对象。对于 AMD 模块,这应该不是必需的,只有 return 语句。有没有办法纠正这个问题?
【问题讨论】:
-
当然我的被标记为重复,即使我先问过它;)。无论如何,另一个问题中的解决方案也对我有用。
标签: javascript typescript amd