[英]Using Node.js with Flow in WebStorm
I am trying to setup WebStorm with Flow typing for a Node.js project. 我正在尝试使用Flow类型为Node.js项目设置WebStorm。
I have it all working fine with NPM scripts but would like to integrate with the IDE. 我使用NPM脚本可以正常工作,但想与IDE集成。
Here is the scripts portion of my package.json
: 这是我的package.json
的脚本部分:
"scripts": {
"dev":
"watch --wait=1 'flow-remove-types src/ -d lib/ --all --pretty' ./src/ & nodemon ./lib/server.js",
"start": "npm run flow:build && node ./lib/",
"lint": "eslint src/**",
"test": "npm run flow:build && jest lib",
"coverage": "jest --collectCoverageFrom=src/**.js --coverage src",
"flow": "flow",
"flow:check": "flow check ./src/",
"flow:build": "flow-remove-types ./src/ -d ./lib/ --all --pretty",
"flow:deps": "flow-typed install",
"flow:watch": "flow-watch"
},
Now if I modify the run configuration for a test and: 现在,如果我修改测试的运行配置,并且:
src
directory to lib
将src
目录更改为lib
then I can run that configuration. 然后我可以运行该配置。
I still have two problems. 我还有两个问题。
Does anyone have Node.js and flow working well together in WebStorm? 有没有人在WebStorm中有Node.js和流程一起工作?
flow-remove-types
does not generate sourcemaps, so there is absolutely no way for debugger to map the generated file in lib
to original files in src
. flow-remove-types
不生成源映射,因此调试器绝对没有办法将lib
生成的文件映射到src
原始文件。 You have to add breakpoints to the generated files located in lib
folder if you like to debug your tests 如果要调试测试,则必须向位于lib
文件夹中的生成文件添加断点
no way - configuration is generated for the file you hit the arrow in. If you like to run individual tests from gutter, hit the arrow in generated file, not in the source one 没办法 - 为你点击箭头的文件生成配置。如果你想从装订线运行单独的测试,点击生成的文件中的箭头,而不是源文件中的箭头
You can use Babel flow preset instead of flow-remove-types
: 您可以使用Babel 流预设而不是flow-remove-types
:
npm install --save-dev babel-cli babel-preset-env babel-preset-flow
.babelrc
file in your project root dir: 在项目根目录中创建一个.babelrc
文件: { "presets": ["flow"] }
And that's all you have to do - no precompiling, etc., running from gutter/debugging for source files will work out of the box 这就是你要做的一切 - 没有预编译等,从源文件的水槽/调试运行将开箱即用
You can use --sourcemaps and -pretty flags: 您可以使用--sourcemaps和-pretty标志:
flow-remove-types --pretty --sourcemaps --out-dir out/ in/
The -m or --sourcemaps flag adds sourcemaps files to your /out folder -m或--sourcemaps标志将sourcemaps文件添加到您的/ out文件夹
The -p or --pretty flag removes the empty spaces in the files of your /out folder -p或--pretty标志删除/ out文件夹文件中的空白区域
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.