.flowconfig
每个 Flow 项目都包含一个 .flowconfig
文件。你可以通过修改 .flowconfig
来配置 Flow。新项目或者开始使用 Flow 的项目可以通过运行 flow init
生成默认的 .flowconfig
。
¥Every Flow project contains a .flowconfig
file. You can configure Flow by
modifying .flowconfig
. New projects or projects that are starting to use Flow
can generate a default .flowconfig
by running flow init
.
.flowconfig
格式
¥.flowconfig
format
.flowconfig
使用类似于 INI 文件的自定义格式。
¥The .flowconfig
uses a custom format that vaguely resembles INI files.
.flowconfig
由不同的部分组成:
¥The .flowconfig
consists of different sections:
注释
¥Comments
以零个或多个空格开头,后跟 #
或 ;
或 💩
的行将被忽略。例如:
¥Lines beginning with zero or more spaces followed by an #
or ;
or 💩
are
ignored. For example:
# 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
放在哪里
¥Where to put the .flowconfig
.flowconfig
的位置很重要。Flow 将包含 .flowconfig
的目录视为项目根目录。默认情况下,Flow 包含项目根目录下的所有源代码。[包括]部分 中的路径是相对于项目根目录的。其他一些配置还允许你通过宏 <PROJECT_ROOT>
引用项目根目录。
¥The location of the .flowconfig
is significant. Flow treats the directory that
contains the .flowconfig
as the project root. By default Flow includes all
the source code under the project root. The paths in the
[include] section are relative to the project root. Some other
configuration also lets you reference the project root via the macro
<PROJECT_ROOT>
.
大多数人将 .flowconfig
放在项目的根目录中(即 package.json
旁边)。有些人将所有代码放在 src/
目录中,因此将 .flowconfig
放在 src/.flowconfig
目录中。
¥Most people put the .flowconfig
in the root of their project (i.e. next to the
package.json
). Some people put all their code in a src/
directory and
therefore put the .flowconfig
at src/.flowconfig
.
示例
¥Example
假设你有以下目录结构,其中 .flowconfig
位于 mydir
中:
¥Say you have the following directory structure, with your .flowconfig
in
mydir
:
otherdir
└── src
├── othercode.js
mydir
├── .flowconfig
├── build
│ ├── first.js
│ └── shim.js
├── lib
│ └── flow
├── node_modules
│ └── es6-shim
└── src
├── first.js
└── shim.js
以下是如何使用 .flowconfig
指令的示例。
¥Here is an example of how you could use the .flowconfig
directives.
[include]
../otherdir/src
[ignore]
.*/build/.*
[libs]
./lib
现在 flow
将在其检查中包含 .flowconfig
路径之外的目录,忽略 build
目录并使用 lib
中的声明。
¥Now flow
will include a directory outside the .flowconfig
path in its
check, ignore the build
directory and use the declarations in lib
.