Flow 中文全攻略
1.0.0
Search
⌃K

.flowconfig

flow 設定檔
任何一個 Flow 專案一定會有一個 .flowconfig 檔案,可以透過編輯 .flowconfig 檔案來對這個專案 Flow 專案進行設置。 新專案可以透過 flow init 指令產生預設空白的 .flowconfig 檔。 ( 參考 初始化專案 章節 )

.flowconfig 格式

.flowconfig 採用了類似 INI 檔案的格式,照官方的說法:
We are not proud of our custom format and plan to support a better format in the future. GitHub issue #153 tracks this.
他們似乎不是很滿意這種設定格式,未來是有在規劃改為 JSON 或是其他的設定格式的。我們就靜觀其變吧!
但是不管未來如何,現階段我們還是要瞭解如何設定它才行。
.flowcofing 由 8 個部分組成: ( 官網目前是寫 7 個,可是我怎麼算都是 8 個,已經有提 issue 了,再等候結果囉 )
  • [declarations]
  • [include]
  • [ignore]
  • [untyped]
  • [libs]
  • [lints]
  • [options]
  • [version]

註解

在 .flowconfig 中是有註解的,以下三種符號以後的都會被當成註解:#;💩
像是這樣:
# 這是註解、註解、註解
# 這是註解、註解、註解
; 這是註解、註解、註解
; 這是註解、註解、註解
💩 這是註解、註解、註解
💩 這是註解、註解、註解
不要懷疑~ 💩 真的是註解符號!

.flowconfig 要放在哪

.flowconfig 檔放的位置是很重要的。通常 .flowconfig 會放在專案的根目錄下。預設情況下 Flow 專案的所有內容都會專案根目錄之下,因此 .flowconfig 設定檔的 [include] 部分也是由專案根目錄為出發的。 當然,也可以透過 [include] 指定路徑從專案根目錄以外的目錄引入檔案。
大多數的專案都會將 .flowconfig 放在專案的根目錄下 ( 也就是跟 package.json 同一層 )。也會有些人放在 src/ 目錄下,也就是 src/.flowconfig

範例

假設我們有一個 Flow 專案在 mydir 內,那想必 .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 專案包含了 otherdir 資料夾內的檔案,以及不會檢查 build 資料夾內的檔案,還有將 lib 資料夾內的檔案作為定義檔 ( declarations ) 使用。