- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想给一个nuxt项目添加流支持(我的项目使用了webpack和babel)。我可以在某处找到工作示例吗?
如果我运行 flow check
,没有错误,但是当我运行 yarn run dev
时,我得到一个语法错误。
(我知道那里有这些 unanswered questions,我再次提出同样的问题,希望这次它能到达一些对此事有了解的人。)
谢谢
最佳答案
有很多东西需要配置。让我指导您完成这个过程。
TLDR:使用 wemake-vue-template
.它带有 nuxt
、flow
和许多其他好东西。
首先,我们需要配置babel
。这就是你的 babel
配置应该是这样的:
{
"presets": [
["vue-app", {
"useBuiltIns": true
}],
"flow"
]
}
使用 npm install --save-dev babel-preset-flow babel-preset-vue-app
安装这些礼物。
接下来,我们需要配置 eslint
来检查我们的 flow
文件。 .eslintrc
应该是这样的:
{
"root": true,
"plugins": [
"flowtype-errors"
],
"env": {
"node": true,
"browser": true
},
"rules": {
// raise flow errors
"flowtype-errors/show-errors": 2,
"flowtype-errors/show-warnings": 1,
// "flowtype-errors/enforce-min-coverage": [2, 50]
},
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 2017,
"sourceType": "module"
}
}
确保你已经安装了所有的东西。
这是最难的部分。您需要为 flow
指定配置。它可能因您的设置而异。
[ignore]
./nuxt/*
<PROJECT_ROOT>/node_modules/.*config-chain/test/broken.json
[include]
<PROJECT_ROOT>/client
<PROJECT_ROOT>/
[libs]
[lints]
all=warn
untyped-import=off
unsafe-getters-setters=off
[options]
include_warnings=true
esproposal.decorators=ignore
module.name_mapper='^~' -> '<PROJECT_ROOT>/client'
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=client
module.file_ext=.vue
module.file_ext=.js
最后一步。我们需要对每个更改启用 linting。
build: {
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
就是这样。现在您将进行有效的 flow
类型检查。
关于webpack - 如何在nuxt中添加流(flowtype)支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47768727/
我已经搜索了 flowtype 的文档,但找不到与类型推断相关的内容,例如: function add(x){ return x+10; } 使用flowtype后变成: function add
在以下示例中,由于我使用 switch 语句匹配消息类型,因此我希望流程能够识别我的错误大小写“ENUM_TYPO”。目前没有。 type Message = 'BROADCAST_MESSAGE'
我是spacemacs扇子。我想使用Facebook Flow但我不知道如何将它与 spacemacs 集成。我正在将 flow 与 nuclide 结合使用,但我需要重新学习一切才能提高工作效率。有
为了性能起见,我想忽略我的 .flowconfig [ignore] 部分中的整个 node_modules,但包括我使用的一些目录,例如“react”。 有人知道怎么做吗? 我基本上想忽略所有影响
安装在package.json上 "babel-preset-flow": "^6.23.0", "eslint-plugin-flowtype": "2.35.1", "flow-bin": "^0
想到一个简单的例子比如: class CommentAreaComponent extends React.Component { static propTypes = { id: PropT
我想确保我得到的值是一个十六进制字符串。目前我说 type Color = string; function foo(color: Color){} 但我想说 type Color = '#' + s
我不知道如何在两个文件中共享类型定义。考虑: // /file_a.js export const randomVariable: MySharedType = {thing: true}; // /
Flow 的文档说:When you create an object without any properties, you create an unsealed object type in Fl
免责声明:一般来说,我还是有点新的 Flow 和静态类型,所以我很可能忽略了这个问题的一些简单/明显的东西。 假设我有一个名为 my-library 的库.该库向其用户公开了一个模块,index.js
给定以下代码: /* @flow */ interface IDefaultSettings { Drivers?: {}, Options?: {} } const defaultSetti
我试图定义一个对象不能有某个键。 这是我的案例: alert({ items: [{ label:'Apple' }, { label:'Orange' }] }) alert({ ite
添加Flowtype是否可行现有的大型项目? 我添加了 /* @flow weak */到单个 .js文件,然后运行 flow check它突出了对全局定义库的大量函数调用,因为它不知道它们是什么
如何在流程中实现以下目标 export type Response = { err: string, data: ?Array, } | { data: Array, }; 我想表达一个类
我对flow check和flow的作用尚不完全清楚。运行flow似乎可以启动服务器,并检查所有代码。由于服务器正在运行,因此flow的后续执行速度更快。 flow check似乎也进行了完整的代码检
在 Flow 中,为什么要使用类而不是类型? type Point = {x: number; y: number}; class Point = {x: number; y: number}; 最佳
很多时候我发现自己作为 arg 传递了一个特定的 Shape 类型,但是每个键都是可选的,只有至少一个是必需的。 例如: type Shape = { +isFetching: boolean
我想知道如何避免这些大量的空检查,或者至少了解重点是什么,因为它似乎适得其反。 如果我省略空检查,Flowtype 会给我一个错误: var myEl = new MyElement() if (do
我有一个函数foo : function foo(a: string, b: string, c: number, d: boolean): Promise { return new Promis
给定默认值,如何定义config参数的类型? function (config = {}) {}; 最佳答案 function f(config: Object = {}) {} 或者,更一般而言:
我是一名优秀的程序员,十分优秀!