[英]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.