How to do it…
Installing Flow depends on whether you are working with Babel (as would be the case for client-side browser code) or not (as you would do for server-side code). We will see how to deal with Node starting in Chapter 3, Developing with Node; here, we'll just consider Babel.
To start, execute the following command to get the needed Flow packages, including the Babel and ESLint ones:
npm install flow-bin babel-preset-flow eslint-plugin-flowtype --save-dev
Then, add the "flow" preset for Babel in package.json:
"babel": {
"presets": ["env", "flow"]
},
Add some lines to the ESLint configuration, also in package.json:
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
"browser": true,
"node": true
},
"parser": "babel-eslint",
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"plugins": ["flowtype"],
"rules": {
.
.
.
}
},
Add a "flow" script in package.json:
"scripts": {
"build": "babel src -d out",
"flow": "flow",
.
.
.
},
Finally, perform npm run flow init to initialize Flow, only once, to create a .flowconfig file with information that will be used by the Flow process. (See https://flow.org/en/docs/config/ for more information on this file.)