【问题标题】:How can i include another file in Typescript?如何在 Typescript 中包含另一个文件?
【发布时间】:2017-07-28 17:50:41
【问题描述】:

我有很多打字稿文件 a.ts,还有一个打字稿文件 b.ts。我怎样才能将 a.ts 包含在 b.ts 中?因此,当将 b.ts 编译为 javascript b.js 时,来自 a.ts 的内容会自动附加到 b.js。我知道,在LESS中我们可以在b.less中使用import "a.less',所以编译成b.css的时候,a.css的内容会自动包含在b.css中。请问typescript有类似的语法吗?

【问题讨论】:

  • TypeScript 使用模块和 ES6 风格的 import 语句 - 请参阅官方文档:typescriptlang.org/docs/handbook/modules.html
  • 你也可以使用triple-slashes,这取决于你在做什么。但这不是推荐的技术。 JavaScript(和 TypeScript)依赖于模块,而不是像提到的 UnholySheep。

标签: typescript


【解决方案1】:

打字稿有类似的语法吗?

可以使用outFile,如果a.tsb.ts 在您的compilation context 中。

但我强烈建议您使用模块:https://basarat.gitbook.io/typescript/content/docs/project/modules.html

然后使用 webpack 编译:https://basarat.gitbook.io/typescript/content/docs/quick/browser.html

【讨论】:

    猜你喜欢
    • 2017-08-07
    • 2012-01-28
    • 2010-10-06
    • 1970-01-01
    • 2010-10-31
    • 2010-11-26
    相关资源
    最近更新 更多