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

Allow to import a CRA app as a node.js package #8321

Open
Vadorequest opened this issue Jan 15, 2020 · 0 comments
Open

Allow to import a CRA app as a node.js package #8321

Vadorequest opened this issue Jan 15, 2020 · 0 comments

Comments

@Vadorequest
Copy link

Is your proposal related to a problem?

Sometimes, you start a project as an "app", and it perfectly fits. But then, later, your app grows, and what was an "app" before becomes a "module" within a bigger app.

And at this point you may get stuck because you can't import that "module" as a node dependency, and that can be a real blocker for product growth.

This has potential to be more and more a real blocker, especially because of universal apps (like Next.js) that could have the ability to "just import" CRA apps, but can't, because of this CRA's limitation.

Describe the solution you'd like

Assuming I write a CRA app my-cra-app, and I want to use this app in another node.js project - such as Next.s -, I'd like to import it that way:

import MyApp from 'my-cra-app'; // The CRA app loaded as a node.js module
import React from 'react';

const MyCustomCraApp: React.FunctionComponent<Props> = (props: Props): JSX.Element => {
  const { prop2 } = props;

  return (
    <MyApp
      prop1={true}
      prop2={prop2}
    />
  );
};

type Props = {
  prop2: string;
}

export default MyCustomCraApp;

Describe alternatives you've considered

At the moment, the only possibility is to load a CRA app on the browser-side. Meaning loading the CSS and JS files in the section, and creating a DOM element that matches the element where gets injected the CRA app.

I haven't found any solution to load a CRA app as a node.js module, and it's therefore not SSR compatible. (loading has to happens on the client side)

Additional context

Discussed with the community at https://spectrum.chat/create-react-app/general/how-to-convert-a-cra-app-into-a-package~23fd401e-ebb4-409f-9c8f-599fdddb0882

I don't know if it's technically doable, nor how hard it might be.

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

No branches or pull requests

1 participant