【发布时间】:2015-06-02 22:44:11
【问题描述】:
我正在构建一个打字稿库,我想通过以下方式进行:
- 一个
class(interface) / 开发源中的文件 - 由于整个库“属于一起”,所以都可以放在 1 个命名空间下
- 在构建时,我希望能够创建单个输出
js和d.ts文件,仅使用相关的导出/定义。
我尝试做的方式如下:
我使用/// <reference path="..." /> 语法来引用其他文件
Foo.ts
class Foo {
// stuff
}
Bar.ts
/// <reference path="Foo" />
class Bar extends Foo {
// just an example for referencing another compilation unit
}
创建一个tsconfig.json 文件,该文件使用out 选项,因此所有内容都连接到一个文件中:
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"out": "src-gen/app.js"
/* other options ... */
}
}
最后添加一个文件,它导出所有的东西,我希望能够从其他文件中导入,像这样:
Exports.ts
/// <reference path="Bar" />
export {Bar} // don't want to expose Foo, since its not relevant for users of the lib.
但export {Bar} 行给出以下编译错误:
导入别名'Bar'的循环定义。导入栏
我不知道这个错误是什么意思,因为Bar 不会在任何地方导入,只能使用/// <reference> 语法引用。
最后我的全部目标是,有一个文件,js 文件作为输出,如下所示:
/* compiled js source of Foo */
/* compiled js source of Bar */
exports = {
Bar
}
我的问题是:
- 这是一种有效的做事方式吗?
- 如果是,
export {Bar}有什么问题? - 如果没有,您将如何实现,我想做什么?
提前感谢您提供任何帮助/建议!
【问题讨论】:
标签: build typescript