情况:
shared。npm,它似乎工作,共享和服务器使用npm。代码结构:
root/
|- client/
|- package.json
|- src/
|- ...
|- server/
|- package.json
|- src/
|- ...
|- shared/
|- package.json // we don't want to change version every change
|- src/
|- ...曾经尝试过的
- create a folder common under root and just require the files you need from your files. But you could end up with "long" require such as require("../../../../../common/file")- long require doesn't work with resolution with webpack - and isn't a nice solution- use module-alias to avoid that problem: [https://github.com/ilearnio/module-alias](https://github.com/ilearnio/module-alias)- module-alias _seems_ to be the same solution as the next one, in how it behaves.- you could make common a local module (using file:) and install it in package.json [https://docs.npmjs.com/files/package.json#local-paths](https://docs.npmjs.com/files/package.json#local-paths)- we currently do this, but we still have to reinstall the `shared` folder on a change, we currently use `yarn upgrade shared` which takes a long time and still requires us to know when we need to run it.yarn link工作,但似乎没有正确地链接post-pull钩子与husky一起运行yarn upgrade shared,但是运行每一个拉杆都太慢了,特别是因为不经常需要它目标
dev环境中自动同步它们的方法yarn upgrade shared的方法,该方法只在需要时才运行(粗略地),而不是一直运行shared的version键的任何更改的版本增量,然后跟踪它,我们可以运行yarn install并完成这项工作。发布于 2020-10-21 16:52:58
查找解决方案是,我们使用的是React本机,因此,正常的同步步骤将适用于IDE,而不是Reacti-原住民应用程序。
这里是一篇很棒的文章,描述了如何使用它--但是对于类型记录,我们将它添加到TSConfig中,而对于IDE,我们仍然需要使用file:../shared指令将它添加到包中。
https://stackoverflow.com/questions/63679026
复制相似问题