Typescript AMD目标解析为CommonJS [英] Typescript AMD Target Resolving to CommonJS

查看:275
本文介绍了Typescript AMD目标解析为CommonJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个tsconfig,它指定模块目标为"amd",但是当我的文件编译时,我得到的输出看起来更像CommonJS.示例:

I have a tsconfig in my project that specifies a module target of 'amd' but when my file compiles I am getting an output that looks more like CommonJS. Example:

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语句.有办法纠正这个问题吗?

It's the 'export' object that's throwing me off. This should not be necessary for an AMD module, only a return statement. Is there a way to correct this?

推荐答案

不幸的是没有.这就是TypeScript的AMD输出的形状,并且符合AMD的要求. AMD提供了此功能,TypeScript使用了它.

Unfortunately not. That is the shape of TypeScript's AMD output and it is AMD compliant. AMD offers this facility and TypeScript uses it.

这篇关于Typescript AMD目标解析为CommonJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆