首页 > 解决方案 > 创建暴露给浏览器全局的 UMD 库

问题描述

我想在浏览器中将我的代码公开为全局范围内的库。我的代码遵循这样的结构:

const SOMETHING = 'test';

interface Library {
    ...
}

export const Library = (params: Library) => {
    ...
}

在我的 TS 配置中,我设置了以下选项:

{
    "compilerOptions": {
        "target": "es6",
        "module": "umd",
        "declaration": true,
        "sourceMap": true,
        "outDir": "./dist",
        "rootDir": "./src",
        "downlevelIteration": true,
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true
    }
}

当我在做:

const Library = (params: Library) => {

然后我window.Library开始工作了,而且还被window.SOMETHING暴露了。如何配置 TypeScript,只公开window.Library?

标签: typescriptglobalumd

解决方案


推荐阅读