我一直在尝试将我的 TypeScript“应用程序”捆绑到一个 javascript 文件中。
我没有使用任何捆绑器,而是 TSC(使用 TypeScript 2.2)。除了我自己的 ts 文件之外,我的应用程序还使用了 immutablejs 等外部模块。
我阅读了所有可能的线程、文档,但找不到仅使用 TSC 将外部模块(来自 node_modules )捆绑到我编译/转译的 javascript 文件的方法。
在下面,您可以找到我的最新代码/配置示例以及我的尝试结果。
配置文件
{
"compilerOptions": {
"target": "es5",
"module": "system",
"removeComments": true,
"sourceMap": true,
"allowJs": true
}
}
Run Code Online (Sandbox Code Playgroud)
app.ts - 注意:./something.ts 已成功绑定。
/// <reference path="../node_modules/immutable/dist/immutable.d.ts" />
import * as something from "./something";
import * as Immutable from "immutable";
console.log( something.test );
const map1 = Immutable.Map( { a: 1, b: '2', c: 'cu' });
console.log( map1.get( 'a') )
Run Code Online (Sandbox Code Playgroud)
1#:使用 tsc-bundle ( https://www.npmjs.com/package/typescript-bundle ) …