【发布时间】:2016-09-06 13:29:06
【问题描述】:
我有一个用 typescript 编写的项目(lib 项目),并被另一个用 typescript 编写的项目(app 项目)使用。 lib 项目编译为单个 js 文件并生成声明文件。一切都按预期工作,但生成的声明文件在顶部包含此引用-
/// <reference path="typings/index.d.ts" />
在 lib 项目中,tsconfig.json 旁边有一个 typings 目录,但它只是 lib 项目所需要的。它不应作为引用包含在声明文件中。这是我的 tsconfig
{
"compilerOptions": {
"module": "commonjs",
"experimentalDecorators": true,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"outFile": "proj-lib.js",
"sourceMap": true
},
"include": [
"./js/**/*.ts"
]
}
为什么我的声明文件包含引用?
临时解决方案
使用gulp-regex-replace 从声明文件中删除引用。
tsResult.dts
.pipe(replace({regex: /\/\/\/\s*<reference[^>]+>\s*/g, replace: ''})) // remove references in declaration file
.pipe(gulp.dest(target));
这并不理想。我希望有一个 tsc 解决方案。
【问题讨论】:
标签: typescript