I am running into the following problem when trying to develop a React component library using styled-components
.
For the purpose of this example, let's assume we have two repos, app
and core
and that core
will be consumed by app
.
Currently, core
is written in TypeScript and built using tsc
.
In order to rapidly iterate, I attempted to use yarn link
to link core
into app
.
This works fine for making app
find core
... the problem I'm facing is when the compiled TypeScript code of core
attempts to require a package, say styled-components
, it attempts to find this package in the node_modules
of core
(not of app
). Since I have styled-components
as both a peerDependency and devDependency it is able to find it in core
's node_modules
, but this is not what I want to happen. I would like it to use the styled-components
of app
.
One alternative to yarn link
I have tried is by adding the dependency of core
to app
via file:/path
. This seems to work as expected, but introduces new problems. How can I have a path of my dev machine existing in the package.json
just for local development (without constantly switching it back and forth)? Also, it seems any updates made in core
require the package to be removed from app
, and have yarn's cache cleared before re-adding it.
Is there any simpler way to make this scenario work? I've just started looking at Rollup or Webpack as a solution, but not sure if that is the right direction.