how best to incorporate an existing package created with create-react-app
See original GitHub issueI have been working on a package that has been created with create-react-app
.
I have now come across lerna and would like be able to use lerna to link the local pacakges together without using npm link
.
How can I refactor my application into a structure that would work with lerna.
Is it even worth it?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Deployment | Create React App
Create a file called .env.staging · Install env-cmd. $ npm install env-cmd --save $ # or $ yarn add env-cmd · Add a...
Read more >Create a New React App
Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in...
Read more >How To Set Up a React Project with Create React App
To install the base project, run the following command: npx create-react-app digital-ocean-tutorial.
Read more >Switch over to Create React App on Existing Project?
Copy your src to a folder outside your repo; Clean your repo git rm -rf; Perform the above steps (create react app, install...
Read more >How to Build a React App Using Create-React-App - Radixweb
You need to install Node.js and NPM on your desktop. You can download Node at nodejs.org. Make sure to have at least Node...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve made a successful version of a create-react-app (with Redux) using lerna, but it’s a little complicated. I wouldn’t recommend the approach unless you truly need it.
This is how I’ve set it up:
Module Structure
App module
The main app module contains many of the root level files that are essential to a React application:
Other modules
All modules follow this componetized pattern:
Within each root level folder, an index.js file should exist that collects all of the exports that should be exposed to other modules so that the root index.js can succinctly expose each of these for the entire module.
The root index.js should expose (I’d love a more flat way to express this, especially for components):
To run the app, you need a few things:
Hope that helps or at least tells you it can be done!
Edit: Composing the routes can be a bit tricky in the “app” module. I had to use this technique to get it to work:
Module Route definition:
App main-router.jsx:
FYI, for those in the interest. All works well with straight up
yarn
workspaces. Although you may need to firstly create yourcreate-react-app
instance outside of your workspace and then copy the result into your workspace and run theyarn install
command again.