出于某种原因,我发现自己需要将一个依赖于其他文件中的多个其他模块的文件(主入口点)编译成一个单一的捆绑文件。它必须能够在浏览器中运行。
我必须使用 TypeScript 编译器,并且只能使用那个工具(即不是 Webpack、Babel 等)。
我目前正在使用 --outFile 选项进行编译,其中 --module 设置为System或AMD(这是 --outFile 唯一允许的选项)。
对于 System,会生成类似于以下内容的内容:
[some more modules ...]
System.register("index", [...], function (exports, context) {
[...]
});
当我尝试将其粘贴在这样的 HTML 文件中时:
<!doctype html>
<html>
<head>
<title></title>
<meta content="">
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/6.1.7/system.js"></script>
</head>
<body>
<script>
[some more modules ...]
System.register("index", [...], function (exports, context) {
[...]
});
System.import("index").then(function (m) {
new m.run();
});
</script>
</body>
</html>
我得到:
Error: Unable to resolve specifier 'index' from [...]
我在系统上做错了什么?另外,哪个更适合我的目的?AMD 还是系统?