.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
中的声明。