Modern JavaScript Web Development Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it…

We want to use the shorter, more concise style of Flow, but Node cannot execute code with such additives.The solution to our conundrum is easy: just remove everything related to Flow before attempting to run! There is a package, flow-remove-types, that does just that. To start, as usual, you'll have to install the needed package:

npm install flow-remove-types --save-dev

To continue, you will have to enable it by adding a new script. We were writing our code in the src/ directory, so let's send the Flow-cleaned output to the out/ directory. In that directory, we will get the version of the code that we will use in our server:

"scripts": {
"build": "flow-remove-types src/ -d out/",
"addTypes": "flow-typed install",
"update": "npm install && flow-typed install",
"flow": "flow",
.
.
.
},

To finish, we should also tell Git to ignore the out/ directory. We were already ignoring the node_modules and flow-typed directories, so let's add one more:

**/node_modules 
**/flow-typed
**/out
We are specifying **/out instead of just out/, because we are sharing a single Git repository between many projects, for the sake of the book. If, as is more common, you had a separate repository for each project, then you would simply specify out.