.flowconfig
每個 Flow 專案都包含一個 .flowconfig 檔案。您可以透過修改 .flowconfig 來設定 Flow。新的專案或開始使用 Flow 的專案可以透過執行 flow init 來產生一個預設的 .flowconfig。
.flowconfig 格式
.flowconfig 使用一種自訂格式,與 INI 檔案有點類似。
.flowconfig 包含不同的區段
註解
以零個或多個空白開頭,接著是 # 或 ; 或 💩 的行都會被忽略。例如
# This is a comment
# This is a comment
; This is a comment
; This is a comment
💩 This is a comment
💩 This is a comment
將 .flowconfig 放在哪裡
.flowconfig 的位置很重要。Flow 將包含 .flowconfig 的目錄視為專案根目錄。預設情況下,Flow 會包含專案根目錄下的所有原始碼。[include] 區段中的路徑相對於專案根目錄。一些其他設定也允許您透過巨集 <PROJECT_ROOT> 參照專案根目錄。
大多數人會將 .flowconfig 放在專案的根目錄中(即在 package.json 旁邊)。有些人會將所有程式碼放在 src/ 目錄中,因此會將 .flowconfig 放在 src/.flowconfig 中。
範例
假設您有以下目錄結構,其中 .flowconfig 在 mydir 中
otherdir
└── src
├── othercode.js
mydir
├── .flowconfig
├── build
│ ├── first.js
│ └── shim.js
├── lib
│ └── flow
├── node_modules
│ └── es6-shim
└── src
├── first.js
└── shim.js
以下是您可以如何使用 .flowconfig 指令的範例。
[include]
../otherdir/src
[ignore]
.*/build/.*
[libs]
./lib
現在 flow 會在檢查中包含 .flowconfig 路徑之外的目錄,忽略 build 目錄,並使用 lib 中的宣告。