Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Support Lerna/Yarn Workspaces #295

Open
osdiab opened this issue Apr 6, 2018 · 3 comments
Open

Support Lerna/Yarn Workspaces #295

osdiab opened this issue Apr 6, 2018 · 3 comments

Comments

@osdiab
Copy link

osdiab commented Apr 6, 2018

Is this a bug report?

No.

As discussed in facebook/create-react-app#1333 and merged in facebook/create-react-app#3741, [email protected] has support for monorepos. I'd like to make use of that functionality in my create-react-app-typescript projects, want to make sure this doesn't get lost as time goes on :) Looks like 2.0.0 hasn't been released yet, so we can wait on that.

@untsamphan
Copy link

I've implemented a workaround using tsc's baseUrl which CRA-ts already supported.

https://github.com/untsamphan/cra-ts-monorepo-example

Need to eject (only) if you want tsc/webpack to grab .ts from the local packages.

Steps

  1. Initial boilerplate from create-react-app-typescript in root/webapp commit.

  2. Create yarn workspace commit.

  3. Move CRA tsconfig.json to root to be shared with other local packages commit 1, commit 2.

  4. Implement a trivial local packages root/packages/mymain commit. Run yarn now so it'll create symlink to mymain in root/node_modules. Then we can import from 'mymain' from anywhere.

  5. Make the CRA app use the new local packages commit. Now the CRA app will tsc compile correctly (because we have index.ts at mymain root). But when yarn start it'll fail in browser because mymain isn't built. To fix this we can tsc in mymain to build the package and the app will run successfully. However, when we go to definition to a symbol in mymain, it'll goto a .d.ts.

  6. To achieve goal 3 (go to definition -> .ts), we configure tsconfig.json baseUrl to directly reference local packages. Since webpack won't bundle code outside webapp/src, and jest won't find the packages, we have to eject to configure them. commit

  7. Simple webpack config hack to allow it to bundle code outside webpack/src. This to achieve goal 3. commit. Don't forget to delete build in local packages, because otherwise everyone will use build/index.* (per NPM spec) instead of index.ts at the local package root (a TS-specific behavior).

  8. Simple jest config hack to make jest inside webapp also run all tests in local packages. commit

@watiko
Copy link

watiko commented Jul 20, 2018

@untsamphan Thank you for your great instructions. This is very much helpful for me.
However I'd not like to eject and manage complicated configurations so I made another version using react-app-rewired.

Thx again!

@hieu-nv
Copy link

hieu-nv commented Oct 4, 2018

You can try to use https://www.npmjs.com/package/@hieunv/react-scripts. See sample https://github.com/react-chartjs/core

First, You create a project with

cd packages
npx create-react-app my-app --scripts-version=@hieunv/react-scripts

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants