-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Importing Sibling Workspace Source #4507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @SavePointSam I am currently running exactly what you described having a UI and a separate app which uses the UI source code. You'll need to setup yarn workspaces properly and it should work as expected. The use of lerna is not required. Here is my package.json if it helps you:
|
@bugzpodder Thanks! Lerna automatically sets up workspaces for me, so I shouldn't have to do anything. However, there is an issue on the [email protected] roadmap item that also deals with this, #1333. |
Yep, if you use the latest version of CRA2, you should already have proper yarn workspaces support. If you are running into trouble, checkout the user guide in CRA2 to see if you missed a step. |
@SavePointSam are you still having issues setting up your repo? As I mentioned before I have been using the setup with no problems. Let me know if you need any help on this by provide additional details on your config files and versions of the tools. |
@bugzpodder Thanks for the support! However, I have had the basic set-up working with CRA 1 no problem. My real problem arises in a situation that is not yet supported. I've had a couple of discussions with Dan over Twitter about it. It appears we need to follow through on this issue #4092. I'm hoping to work on this in the near future and get it working before the proper CRA 2 release. |
I'm actually able to accomplish this by using CRA 2 and swapping my uiKit For the time being I'll close this issue as I am happy with my current solution while we work on a better one. There was one other issue I had where ESLint was trying to run against my uiKit bundle though. I'm not sure how much of an edge case that will be in the future, but worth noting for now I think. |
As a note: my solution only works because I subscribe to having the same babel settings in both my CRA app and my uiKit. So your milage may vary if you're using different plugins or settings. |
The |
@SavePointSam FYI, CRA2.0 does already support source packages throughout the monorepo, like in your example above.
#4092 is an alternative approach to fix the opt in issue (and also specifies that the "source" entry point should be supported, so it would fix that issue, too). |
@bradfordlemley thanks for the detailed overview! I'm actually in the process of assisting with those efforts. I totally agree that workspace/monorepo support should be opt in and have it's own section in the guide before the launch of CRA 2. For now I'm abusing the |
Is this a bug report?
No
Problem
I'm using lerna and yarn to manage a set of packages that make up our frontend. I want to import an internal UI toolkit (
uiKit
) into my CRA-based app (app
). However, I'm unsure how I go about importinguiKit
in such a way that I don't need to commit / manage a distributable that previously only existed in a private NPM package (how it was imported before the monorepo switch). While I don't think this is directly a CRA issue to solve, I needed a place to start and @gaearon asked me to open a detailed issue here.I use the same babel settings as CRA in
uiKit
, but CRA doesn't transpile anything it believes is in node_modules. However, in react-scripts@2 there will be support for fundamental transpiling node_modules, but this is for known language features, not things like flow, so no luck there.The only solution I've found so far is to manually build
uiKit
and then commit the distributable. This leads to a clunky developer experience as they may be working onuiKit
andapp
at the same time but not seeing updates fromuiKit
update inapp
in any sort of real time. They would need to manually rebuilduiKit
and restart the app server to see changes reflected. IMO, this defeats the purpose of using lerna to access indev packages without explicit build steps.Folder Structure
Other Thoughts
Maybe I'm looking at how I import my UI library wrong? Although, IMO it should work just the same as if the
uiKit
components we inside the source forapp
. Maybe there is something I missed in the lerna set-up that would fix this? It would be nice if I could have it run the packaging process and symlink that instead of the source itself? Although it would need to run on every change which would be heavy and a running CRA dev server wouldn't see the update anyway AFAIK. There might not be any solution other than committing the distributable, which is really unfortunate. I could configure a setting so that CRA thinks that it's not actually a node_module in some way and it will transpile as expected, but I have no idea if that is even possible.I looked into providing a different package.json attribute that would represent an entry point that hasn't been transpiled, but all the attributes are based on the expected module definition type, not the state of the code itself. I could symlink the
uiKit
components into theapp
source but thats even messier to maintain.I'm at a loss at what should be done here. I want to keep my component library separate for usage in other places, but also don't want to explicitly build and commit the distributable to enable seamless cross-package development.
The text was updated successfully, but these errors were encountered: