【发布时间】:2019-07-14 02:20:20
【问题描述】:
我有以下monorepo结构
root
--AppOne
----package.json
----node_modules
------styled-components
--AppTwo
----package.json
----node_modules
------styled-components
--Shared
----componentA
----package.json
----node_modules
------styled-components
我的问题是 AppOne 和 AppTwo 都在使用来自 shared 目录的 componentA,它依赖于 NPM 包,例如 styled-components
这意味着我需要在所有三个目录中都安装styled-components,这会增加捆绑包的大小,如果版本不同,可能会导致包无法正常运行。
这也意味着我从styled-components 收到以下错误:
It looks like there are several instances of 'styled-components' initialized in this application.
This may cause dynamic styles not rendering properly, errors happening during rehydration process and makes your application bigger without a good reason.
我的问题是 - 解决这种情况的最佳方法是什么?理想情况下,我只希望这个包安装在一个地方。我应该在Shared 中安装它并在AppOne 和AppTwo 中使用别名来使用该软件包吗?
非常感谢任何建议!
【问题讨论】:
标签: npm webpack node-modules webpack-4 styled-components