Typescript AMD Target Resolving to CommonJS [dupli

2019-08-09 16:23发布

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"]
    }
}

Typescript File:

export function test() {
    console.log('Starting Up', '<--------------');
}

Compiled File:

define(["require", "exports"], function (require, exports) {
    Object.defineProperty(exports, "__esModule", { value: true });
    function test() {
        console.log('Starting Up', '<--------------');
    }
    exports.test = test;
});

Expected Compiled File:

define([], function () {
    function test() {
        console.log('Starting Up', '<--------------');
    }
    return { test: test };
});

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?

1条回答
家丑人穷心不美
2楼-- · 2019-08-09 17:09

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

查看更多
登录 后发表回答