简体   繁体   English

如何将流程类型添加到弹出的create-react-app?

[英]How to add flowtype to an ejected create-react-app?

We are working on a previously ejected create-react-app and now want to add flowtype. 我们正在开发以前弹出的create-react-app ,现在想添加流程类型。

We have followed the guide at: https://flow.org/en/docs/tools/create-react-app/ 我们已按照以下指南进行操作: https : //flow.org/en/docs/tools/create-react-app/

Should that work for an ejected app? 这对弹出的应用程序有用吗?

This has unfortunately caused the webpack-dev server launched with yarn start to stop automatically reloading on file updates. 不幸的是,这导致了用yarn start的webpack-dev服务器在文件更新时停止自动重新加载。

Additionally, after adding // @flow to some files there is no output or indication of flow enforcing type checking. 此外,在将// @flow添加到某些文件后,没有输出或未指示流执行类型检查。

Will we need to manually update the webpack configs? 我们需要手动更新webpack配置吗?

Heres the package.json scripts 继承人package.json脚本

  "scripts": {
    "start": "node scripts/start.js",
    "build": "yarn build-client && yarn build-server",
    "build-client": "node scripts/build.js",
    "build-server": "./node_modules/.bin/webpack --config ./config/webpack.server.config.js",
    "test": "node scripts/test.js --env=jsdom",
  },

The output for running yarn start is: 运行yarn start的输出为:

Compiled successfully!

You can now view cra in the browser.

  Local:            http://localhost:3000/
  On Your Network:  http://192.168.1.65:3000/

Note that the development build is not optimized.
To create a production build, use yarn build.

The doc you linked tells you how to install the flow-bin and to make a configuration file but don`t tells how to launch it. 您所链接的文档告诉您如何安装流箱并制作配置文件,但不告诉您如何启动它。
Flow is separated tool that should be launch by own command (depends on how you wanna run it): 流是单独的工具,应通过自己的命令启动(取决于您要如何运行):

  1. if you want to check types check manually, you need to add npm command on the "scripts" section of your package.js : "example-comand-flow": "flow" . 如果要手动检查类型,则需要在package.js的“脚本”部分添加npm命令: "example-comand-flow": "flow" Then call it by npm run example-comand-flow and you`ll get errors directly on a terminal you running the script. 然后通过npm run example-comand-flow调用它,您将在运行脚本的终端上直接遇到错误。
  2. if you wanna have continuing type checking, you should find a manual how to configure it in your IDE. 如果您想继续进行类型检查,则应找到手册,了解如何在IDE中进行配置。 For example, in WebStorm you should go Preferences -> Languages & Frameworks -> JavaScript and set JavaScript language version to Flow and specify flow executable. 例如,在WebStorm中,您应该转到Preferences -> Languages & Frameworks -> JavaScript ,并将JavaScript language version设置为Flow并指定流可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM