gpt4 book ai didi

javascript - 如何在不污染 html 的情况下使用庞大的 typescript 库?

转载 作者:搜寻专家 更新时间:2023-10-30 21:31:00 25 4
gpt4 key购买 nike

This答案建议手动添加对所有使用的 .ts 文件生成的 .js 文件的引用。

我打算使用 library具有复杂的结构。我已经将顶级文件添加到我的 html 中,但它们有子引用,子引用有子引用等。

如果 app.ts

开头
/// <reference path="yendor/src/yendor/yendor.ts" />
/// <reference path="yendor/src/umbra/umbra.ts" />
/// <reference path="yendor/src/gizmo/gizmo.ts" />
/// <reference path="yendor/src/game/base.ts" />
/// <reference path="yendor/src/game/persistence.ts" />
/// <reference path="yendor/src/game/custom_events.ts" />
/// <reference path="yendor/src/game/actor.ts" />
/// <reference path="yendor/src/game/effects.ts" />
/// <reference path="yendor/src/game/item.ts" />
/// <reference path="yendor/src/game/creature.ts" />
/// <reference path="yendor/src/game/map.ts" />
/// <reference path="yendor/src/game/gui.ts" />
/// <reference path="yendor/src/game/engine.ts" />

我只能离开吗

<script src="app.js"></script>

代替

Whatever else is used by other libraies
<script src="yendor/src/yendor/yendor.js"></script>
<script src="yendor/src/umbra/umbra.js"></script>
<script src="yendor/src/gizmo/gizmo.js"></script>
<script src="yendor/src/game/base.js"></script>
<script src="yendor/src/game/persistence.js"></script>
<script src="yendor/src/game/custom_evenjs.js"></script>
<script src="yendor/src/game/actor.js"></script>
<script src="yendor/src/game/effecjs.js"></script>
<script src="yendor/src/game/item.js"></script>
<script src="yendor/src/game/creature.js"></script>
<script src="yendor/src/game/map.js"></script>
<script src="yendor/src/game/gui.js"></script>
<script src="yendor/src/game/engine.js"></script>
<script src="jquery-1.11.1.min.js"></script>
<script src="pixi.min.js"></script>
<script src="app.js"></script>

index.html 中?

我使用 visual studio 2015 来构建它。

最佳答案

您可以通过以下方式做到这一点:

  1. 使用 typescript 组织代码 modules
  2. 使用模块加载器(systemjs 等)自动加载模块

遵循这两条规则,您的 index.html 将如下所示:

<!doctype html>
<html>
<head>
<script src="lib/systemjs/dist/system-polyfills.src.js"></script>
<script src="lib/systemjs/dist/system.src.js"></script>

<script>
System.defaultJSExtensions = true;
</script>
</head>
<body>
<script>
document.addEventListener("DOMContentLoaded", function(event)
{//Entry point of the application.
System.import('app').catch(function(e)
{
console.error(e);
});
});
</script>
</body>
</html>

无需包含每个文件。

关于javascript - 如何在不污染 html 的情况下使用庞大的 typescript 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35685702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com