I have a common (or not so coomon) scenario for yarn workspaces
and didn't find the right guide for me online.
yarn workspaces look like that:
- monorepo
- packages
- client
- admin
- theme
- lib
client
and admin
project and this is classic "monorepo style" (lerna) to share components between 2 projects. This folder should be shared only for this project.Additional information:
monorepo
is root repository with .gitmodules
theme
and on the client
and admin
project on the same time.Questions:
We run yarn start
only in client
project and admin
project. Both projects are using the same theme
and same lib
functionality. Because the lib
is shared with other projects, it is updated on a weekly base:
tags
in git repository or should I remove lib
from the monorepo worksapce and to work with it as npm package
(the whole point is to have easy development process when we change the lib
file we do not need to npm update
it again and again.lib
will be npm package, How can I tell monorepo to use workspaces when I run yarn start
and to use the npm version when I run yarn build
?Please advice on the best practices for this scenario.
Thanks in advance, Leo.
FINAL ANSWER: I found the best solution for me and I tried it for 6 weeks during development (best practice).
I ended up with this structure:
The client
and admin
use the theme
as yarn workspaces
https://classic.yarnpkg.com/en/docs/workspaces/
lib
is used as Git npm package with git+ssh://[email protected]:xxxx/xxx/lib.git#v1.0.1
The main/sub repositories structure gives me the ability the manage version control for each project separately and on the same time to use shared "theme" (workspaces) and "lib" core (npm) by versions.
Tip:
For easy development I recommend to add the lib
as yarn workspace
because when we run yarn start
it hot reload the changes in real time. When we do yarn build
we use the lib as npm package with an ssh link.
Good luck! Leo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With