Typescript umd仅支持amd / cmd,但不支持global

时间:2018-12-11 06:41:33

标签: typescript

这是我的文件:

tsconfig.json

{
  "compilerOptions": {
  "module": "umd",
  "esModuleInterop": true,
  "target": "es5",
  "noImplicitAny": true,
  "moduleResolution": "node",
  "sourceMap": true,
  "outDir": "dist",
  "baseUrl": ".",
  "declaration": true
  },
  "include": [
     "src/index.ts"
  ]
}

src / index.ts

namespace someLibName {
    export const preload: Function = () => { };
}

export default someLibName

输出文件: someLibName.js

(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var someLibName;
    (function (someLibName) {
        someLibName.preload = function () { };
    })(someLibName || (someLibName = {}));
    exports.default = someLibName;
});

输出文件 someLibName.js 仅支持AMD / CMD,不能仅通过脚本标签在浏览器中加载。

如何使输出javascript文件支持所有AMD / CMD并用作全局对象?

0 个答案:

没有答案