2023-07-24
2047
#create react app#react
Andrew James
19505
Jul 24, 2023 ⋅ 7 min read

Creating multiple entry points in Create React App without ejecting

Andrew James Frontend Engineer @ Coinbase

Recent posts:

LLMs are facing a QA crisis here’s how we could solve it

LLMs are facing a QA crisis: Here’s how we could solve it

LLM QA isn’t just a tooling gap — it’s a fundamental shift in how we think about software reliability.

Rosario De Chiara
Aug 4, 2025 ⋅ 7 min read

Windsurf vs. Cursor: When to choose the challenger

Windsurf AI brings agentic coding and terminal control right into your IDE. We compare it to Cursor, explore its features, and build a real frontend project.

Chizaram Ken
Jul 31, 2025 ⋅ 9 min read

The CSS if() function: Conditional styling will never be the same

The CSS Working Group has approved the if() function for development, a feature that promises to bring true conditional styling directly to our stylesheets.

Ikeh Akinyemi
Jul 30, 2025 ⋅ 12 min read
what's new in next js 15.4

Next.js 15.4 is here: What’s new and what to expect

Next.js 15.4 is here, and it’s more than just a typical update. This version marks a major milestone for the framework and its growing ecosystem.

Abiola Farounbi
Jul 29, 2025 ⋅ 6 min read
View all posts

12 Replies to "Creating multiple entry points in Create React App without ejecting"

  1. This could be used to dynamically import assets (images, logos, backgrounds, fonts..) and bundle only that are conditionally used? Or maybe there is a better way to do that? Thank you!

    I come from Angular 2-4 that has a angular-cli.json file, and you could define multiple asset paths to be included from a parameter input called “app” (in latest angular versions “project”) and in React, this is managed by Webpack but if you start with CRA and don’t want to eject.. it’s a bit cumbersome. And this could be a solution.

  2. Hi Andrew, thanks for the post.

    I’ve been trying this with the dynamic import but am finding that each file is still included in the bundle and can be accessed if you find the chunk filename, i.e.the ‘test’ module is accessible in the ‘app’ deployment and vice versa:

    https://multiple-entry-points-app.netlify.app/static/js/1.295a3794.chunk.js

    https://multiple-entry-points-test.netlify.app/static/js/0.408b3a91.chunk.js

  3. You are right. I did some tries and tests, and seems that if you do an image or asset conditionally import goes well (it’s not included in the final bundle), but if you try to with a JS file, it’s including anyway to the bundle. So, I think this post needs to be updated..

  4. Thanks for this! I was under the impression that the dynamic import would tree-shake the unused imports.

    I should have some time next week to update the post

  5. Great concept. But as others have posted build process is including all files in project regardless of the dynamic import entry file. Have you found a workaround?

  6. I’m additionally having the issue that css files from the non-included containers are being bundled in, causing clashes between styles.

  7. Nice article Andrew.

    It led me to look into React.lazy as an alternative that renders a dynamic import as a regular component.

    I’m pretty sure the React.lazy approach would work here (wrapped in a React Suspense with fallback) and only bundle in the dynamic import. This will likely resolve the issue people are having in these comments where the bundle currently contains both files?

    I’m not sure if a code snippet will work in this comment, but I’ll try:

    const BuildTarget = React.lazy(() => import(`./${process.env.REACT_APP_BUILD_TARGET}`));

    Reference: https://reactjs.org/docs/code-splitting.html#reactlazy

  8. Thanks a lot for this! I had been searching all day for a “monorep” solution. However, I was unable to get your final solution to work as I was hitting a compile error with Sass that I could not resolve. Instead I modified the last step to just use a switch statement:

    // To add a new app, import it here…
    import ExampleReactApp from “./apps/example-react-app/App”;
    import ImsApp from “./apps/ims/App”;

    // …then add a line to the switch statement below, ensuring the “name” exactly matches the entry in the .env file
    let app;
    switch (process.env.REACT_APP_BUILD_TARGET) {
    case “ims”:
    app = ;
    break;
    default:
    app = ;
    break;
    }

    ReactDOM.render({app}, document.getElementById(“root”));

  9. thank you for the PR, does that mean when the name is explicit, the import can be target. Otherwise it’ll try to include all of them? I’ll give it a shot, but seems making perfect sense.

Leave a Reply