網站搜尋

node.js - Typescript 無論如何都不會排除 tsconfig 的 'excludes' 陣列中的資料夾 (TS 3.7.2)


我已經閱讀過無數的討論串和文件,並嘗試了數十種不同的方法來讓這個運作,但它無論如何都不會忽略那個測試資料夾。

我的 TS 配置:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": ["es2018", "dom"],
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "outDir": "lib",
    "strict": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": false,
    "noImplicitAny": true,
    "moduleResolution": "node"
  },
  "include": ["src"],
  "exclude": ["**/testing/*", "testing", "**/testing/**/*"]
}

我的資料夾結構:

答案#1

結果排除像那樣的資料夾其實毫無意義,而我看到的整個資料夾結構,包括「src」資料夾等等,已經是出了問題的跡象,與我的 tsconfig 相比,它本應該只是將檔案的 JS 結果直接放在「lib」資料夾內的「src」裡面。

我的規格檔案在 SRC 中,它們依賴於 'testing' 資料夾內的資源。一旦我使用以下方式排除了規格檔案:

  "exclude": ["src/**/*.spec.ts"]

我根本不需要在 'excludes' 陣列中指定測試資料夾。現在 tsc 的結果,輸出這個資料夾/檔案結構,而對 tsconfig 沒有其他更改: