[英]package npm project written in flow
I have to publish a npm package that is written with Flow and compiled using babel . 我必须发布一个用Flow编写并使用babel编译的npm包 。
What I did was I compiled all my source files. 我所做的是我编译了所有源文件。 Then I copied compiled files from dist/ and put them into some other directory.
然后,我从dist /复制了编译的文件,并将它们放在其他目录中。 I also put package.json there and edited it and then I published the package on npm.
我还把package.json放在这里并进行了编辑,然后我在npm上发布了该包。
I can then normally install project and require it my project. 然后,我可以正常安装项目,并在我的项目中需要它。 However when I run my project, it throws error that I need to require
babel-core
and babel-polyfills
(install them as dev-dependencies). 但是,当我运行项目时,它会引发错误,我需要
babel-core
和babel-polyfills
(将它们安装为dev-dependencies)。 The problem is since my new project only requires my own package and does not use babel or something like that, so I see no point in requiring babel dependencies in my new project. 问题是因为我的新项目只需要我自己的程序包,而不使用babel或类似的东西,所以我看不出在我的新项目中需要babel依赖项没有意义。
My question is, how can I package my library that is written with Flow and compiled by babel, so that I can then use this package in other places without requiring babel. 我的问题是,如何打包用Flow编写并由babel编译的库,以便我可以在不需要babel的其他地方使用此包。
Did you add main and files into your package.json? 您是否将main和files添加到package.json中?
https://docs.npmjs.com/files/package.json#main https://docs.npmjs.com/files/package.json#main
https://docs.npmjs.com/files/package.json#files https://docs.npmjs.com/files/package.json#files
Your files should probably be 您的文件应该是
"files": [
"dist/**"
],
Also to prevent Users who install your package from needing to install the transpilers (ie babel ) add them into your devDependencies 另外,为了防止安装软件包的用户需要安装编译器(即babel ),请将其添加到devDependencies中
Directly from the https://docs.npmjs.com/files/package.json#dependencies 直接来自https://docs.npmjs.com/files/package.json#dependencies
Please do not put test harnesses or transpilers in your dependencies object.
请不要在您的依赖项对象中放置测试工具或编译器 。 See devDependencies , below.
请参阅下面的devDependencies 。
Also to add flow to your dist add https://github.com/AgentME/flow-copy-source 还要向您的dist添加流,请添加https://github.com/AgentME/flow-copy-source
flow-copy-source -v src dist
The problem was in using incorrectly defined preset In my babelrc I only had defined preset: "env"
without specifying that it needs to run on node 8 and higher, since the code used async. 问题在于使用了定义不正确的预设在我的babelrc中,我仅定义了
preset: "env"
但未指定它需要在节点8或更高版本上运行,因为代码使用了异步。 Therefore i defined preset as: 因此,我将预设定义为:
preset: ["env", {
targets: {
"node": "8.9.1"
}
}
And the asnyc functions compiles correctly. 并且asnyc函数可以正确编译。
Also, thanks to @Kenneth I used flow-copy-source to add type to my library, so it can be seen in intelisense. 另外,感谢@Kenneth,我使用flow-copy-source将类型添加到我的库中,因此可以在intelisense中看到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.