myHotTake

Tag: Rollup configuration

  • How Does Rollup Bundle Multiple Entry Points in JS?

    Hey there! If you enjoy this little tale, feel free to give it a like or share it with your friends who love a good story. Now, let’s dive in.


    Once upon a time, I was a diligent little bird, eager to build a cozy nest for my family. In my world, each twig and leaf represented a piece of the home I envisioned, much like the JavaScript files and modules in a project. My task was to gather these elements and weave them together into a solid, unified structure.

    One day, as I flitted through the forest, I stumbled upon a tool called Rollup. It was like discovering a thread that could bind my twigs together seamlessly. But I had a challenge: I needed to construct multiple rooms in my nest, each starting from different points, just like bundling multiple entry points in a JavaScript project.

    With Rollup, I imagined that each starting twig had its own path, a unique story to tell. I carefully selected my twigs, each one representing an entry file in my project. I tucked a twig here and a leaf there, specifying in Rollup’s configuration which paths to follow. I was like an artist, orchestrating a symphony of twigs that would come together in perfect harmony.

    As I worked, I realized that Rollup allowed me to transform these individual paths into a single, cohesive nest. It was as if each entry point was a small nest of its own, but when woven together, they formed a , interconnected home.

    With every twig I placed, I felt a sense of accomplishment. Rollup’s magic made it possible to see the bigger picture, where every entry point, like a twig, had its place and purpose. My nest was now complete, a testament to the power of bringing separate paths together into one beautiful whole.


    In the world of code, imagine each twig as an entry file. Rollup, our trusty tool, can be configured to handle these files and weave them into a single bundle. Here’s how I would set it up in a rollup.config.js file:

    export default [
      {
        input: 'src/main.js', // First entry point
        output: {
          file: 'dist/bundle-main.js',
          format: 'cjs'
        }
      },
      {
        input: 'src/secondary.js', // Second entry point
        output: {
          file: 'dist/bundle-secondary.js',
          format: 'es'
        }
      }
    ];

    In this configuration, I define an array of configurations, each representing a different entry point. The input property is like choosing which twig to start with. Each entry point leads to its own output, creating separate bundles like rooms in my nest.

    Rollup takes these defined paths and, with a bit of magic, bundles the files into distinct outputs. Just as I used twigs and leaves to create a cohesive nest, Rollup uses entry files and modules to create a structured, efficient project.

    Key Takeaways

    1. Multiple Entry Points: Just as a nest can have multiple rooms, Rollup allows you to define multiple entry points, each leading to a separate output bundle.
    2. Configuration Array: Use an array of configuration objects to manage multiple entry points. Each object specifies its own input and output.
    3. Project Structure: Like building a nest, bundling with multiple entry points enhances your project’s structure and organization, letting you manage distinct parts of your application separately.