如何发布具有自己类型的流类型库
how to publish a flow-typed library with its own types
我在 flow 中编写了一个 index.js
模块,我用 Babel 进行了编译,将其放置在 /dist
目录中并定义为 package.json 中的主文件:
{
"name": "my-lib",
"version": "0.9.0",
"description": "...",
"main": "dist/index.js",
...
}
dist
目录仅包含转译后的文件。
当我在另一个项目上使用它时,通过 npm 或 yarn (yarn add <my-local-path-to-the-module>
) 导入,我可以导入到我项目的模块中,但我丢失了原始流定义(当然,babel 删除了它们)。我如何将流程定义与转译后的文件相关联,以便准备好使用模块及其流程类型?
创建 dist 文件后,您需要从源代码创建关联声明文件。 https://flow.org/en/docs/declarations/
所以最后你的 dist 目录会有一个像
这样的文件结构
- dist
- index.js
- index.flow.js
- something.js
- something.flow.js
- dir1
file1.js
file1.flow.js
您可以使用 https://github.com/Macil/flow-copy-source or https://github.com/lessmess-dev/gen-flow-files
我在 flow 中编写了一个 index.js
模块,我用 Babel 进行了编译,将其放置在 /dist
目录中并定义为 package.json 中的主文件:
{
"name": "my-lib",
"version": "0.9.0",
"description": "...",
"main": "dist/index.js",
...
}
dist
目录仅包含转译后的文件。
当我在另一个项目上使用它时,通过 npm 或 yarn (yarn add <my-local-path-to-the-module>
) 导入,我可以导入到我项目的模块中,但我丢失了原始流定义(当然,babel 删除了它们)。我如何将流程定义与转译后的文件相关联,以便准备好使用模块及其流程类型?
创建 dist 文件后,您需要从源代码创建关联声明文件。 https://flow.org/en/docs/declarations/
所以最后你的 dist 目录会有一个像
这样的文件结构- dist
- index.js
- index.flow.js
- something.js
- something.flow.js
- dir1
file1.js
file1.flow.js
您可以使用 https://github.com/Macil/flow-copy-source or https://github.com/lessmess-dev/gen-flow-files