这个问题在这里已有答案:
我的项目中有一个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模块,这不是必需的,只有返回语句 . 有没有办法纠正这个?
1 回答
不幸的是 . 这是TypeScript的AMD输出的形状,它符合AMD标准 . AMD提供此功能,TypeScript使用它 .