如何编写支持 amd 和普通浏览器的 typescript 模块

How to write typescript modules that support amd and plain browsers

我想使用 TypeScript 编写可重用的组件。所以我希望使用 AMD 模块的人或无法使用我的组件的人。

我可以使用 TypeScript 编写同时支持 AMD 要求和普通浏览器支持的模块作为后备吗?我知道在支持 AMD 和 CommonJS 的打字稿中有 UMD 支持,但我没有在他们的文档中找到一种方法来添加对普通浏览器支持的回退。

Can I use TypeScript to write modules that support both AMD require and plain browser support as a fallback? I know there is UMD support in typescript which supports both AMD and CommonJS, but I haven't found a way in their documentation a way to add a fallback to plain browser support.

这是不支持的。全局变量是个坏主意。建议将所有东西移至 npm (commonjs)