Skip to content
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

Use react app inside another react app #4062

Closed
Vadorequest opened this issue Feb 23, 2018 · 3 comments
Closed

Use react app inside another react app #4062

Vadorequest opened this issue Feb 23, 2018 · 3 comments

Comments

@Vadorequest
Copy link

I have an existing react app, which is currently used like a traditional a react app: Basically load the bundled JS version in a HTML page and get going.

I want/need to keep using it this way.

But as my needs are growing, I also need to use it within another react app and I wonder about how I should do it properly. Based on my current usage, I already have a CDN with the bundled versions.
But I don't think I can use it this way inside another react app.

I read about #1492 but didn't really find any good solution so far. I've thought about releasing a npm version, which would allow me to use it as a component (I guess), but would also be more work to deal with, with versioning and releasing both the bundled and npm version at every update. What are my options?

@Grsmto
Copy link

Grsmto commented Feb 23, 2018

I don't think you will find a better solution than using somethin like npm for this, as you suggested it.
To make it as simple as possible, you could use an npm script for that. With a single command (your build command potentially npm run build), your project could build your bundle and publish your shared components to npm at the same time.

  • First you will have to create a package.json file in the folder you want to share across projects (let's say it's src/components/).
  • Then you can alter you CRA build script with something like this:
    "build": "cd ./src/components && npm version patch && npm publish && cd / && npx react-scripts build"

Once your shared components are published on npm, you can just npm install them like any package. Check the npm doc to publish them privately.

@Vadorequest
Copy link
Author

How would you provide attributes the same way between those two ways? (bundle and npm)

My current workflow is to provide those settings through a global window variable. But that would be cleaner to instantiate the component properly with such settings given in attributes.

I wonder about a common way of doing it whether using the module as a component (npm package) or as a bundled js file injecting itself into a dom element (CRA's way)

@Timer
Copy link
Contributor

Timer commented Mar 5, 2018

2.x will have monorepo support, you can search and find more about in the 2.0 roadmap issue!

@Timer Timer closed this as completed Mar 5, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants