[英]How to put TypeScript tsconfig in another location
我正在尝试创建一个存储库,该存储库在我们本地托管的 github 实例中包含我们公司的通用 linting 规则。 这样,我们就有了一套可以轻松共享的通用规则。 我们的 typescript 定义和 PrettierJs 规则也有配置。
文件结构如下:
/lint-common
/config
.eslintrc.js
.pretterrc
tsconfig.json
package.json
当安装在另一个项目中时,它看起来像这样:
/node_modules
/lint-common
/config
.eslintrc.js
.pretterrc
tsconfig.json
package.json
package.json <-- Consuming package for the project that lint-common has been installed into
从我安装了lint-common
的消费项目中,我在 package.json 中有如下脚本:
"scripts": {
"lint": "eslint -c /node_modules/lint-common/config/.eslintrc.js --ext .js src",
"pretty": "prettier --write --config /node_modules/lint-common/config/.prettierrc src/**/*.js"
}
到目前为止,这工作正常。 但是当我尝试为TypeScript
执行此操作时,它的行为完全不同。 在我指定的src
目录中进行lint
和pretty
处理的地方,tsconfig 坚持从自己的位置处理文件。
对于 TypeScript,我尝试添加如下脚本:
"tsc": "tsc --p ../../config/tsconfig.json",
--p
是--project
选项——它允许我规定 tsconfig 文件的位置。 在 tsconfig 里面我有:
"include": ["src/**/*]
但是,我只收到以下错误:
No inputs were found in config file ...
我可以通过将其更改为来解决此问题:
"include": ["../../../src/**/*]
tsconfig 中的include
选项正在搜索相对于 tsconfig 位置的文件——而不是从我运行npm
命令的位置。
有没有办法解决这个问题? 我曾尝试使用rootDir
选项,但这似乎没有任何效果。
有没有办法解决这个问题?
该文档没有提到一种方法,而AFAIK则没有。
我认为一个可行的解决方案是包含一个 npm [安装后] 脚本,该脚本在新项目的顶层创建一个tsconfig.json
文件,该项目利用extends
属性来引用嵌套在node_modules
中的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.