Code Monkey home page Code Monkey logo

cra-monorepo's Introduction

UI monorepo setup

This project is using Lerna to manage a monorepo for React apps development.

Create React App v2 with TypeScript (without ejecting!) is used for React applications development and TypeScript compiler tsc (you can also use Babel or Rollup) is used to bundle the @ui/shared package which contains React components shared between two/multiple React apps.

Development

First you need to install the dependencies, by runnig lerna boostrap command, or simply:

yarn setup

Then run yarn start in the root of the monorepo. Lerna will then run start scripts in every package.

yarn start

If everything works ok, any change to components within @ui/shared package will cause tsc to recompile the package (and TS types) and it will be picked up by running CRA dev servers recompiling React applications.

For ease of development you can create additional script for running only one app and shared components package compilation, ie. yarn start:hooks will run start scripts only in @ui/react-app-hooks and @ui/shared packages.

React apps were bootstraped by running npx create-react-app react-app --typescript inside /packages folder and then rm -rf react-app/node_modules react-app/yarn.lock to remove local node_modules and *.lock files.

If you have ideas how to improve this setup please file an issue.

Caveats

  • when running CRA dev server (yarn start) through Lerna you need to reload the opened browser tab sometimes to see the app, but then it sould work without any issues.
  • if you want to run multiple CRA projects simultaneously you need to manualy configure PORT environment variable for each React app, ie. using .env file as described in the official documentation. Otherwise Lerna script will have some issues.

cra-monorepo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.