rollup / rollup/rollup

Supporting multiple entries/inputs in the Javascript API

Open
#3,325 12 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
26.3k
Forks
1.8k
Avg merge
2d 11h
Merged PRs (30d)
20

Description

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • Not Sure?
Please Explain in Detail...

The documentation surrounding supporting multiple entries in the Javascript API is confusing.

The docs cover multiple entries/inputs briefly and suggest using a rollup.config.js that exports an array as opposed to an object, i.e:

export default [{
  input: 'main-a.js',
  output: {
    file: 'dist/bundle-a.js',
    format: 'cjs'
  }
}, {
  input: 'main-b.js',
  output: [
    {
      file: 'dist/bundle-b1.js',
      format: 'cjs'
    },
    {
      file: 'dist/bundle-b2.js',
      format: 'esm'
    }
  ]
}];

Alternatively see #2935 for a more in depth discussion surrounding this.

What is unclear is whether or not you can use this in the Javascript API, essentially I thought I would be able to call rollup.rollup and pass it an array similar to the one exported in the above example, however this results in the following error:

Unknown input option: 0. Allowed options: acorn, acornInjectPlugins, cache, chunkGroupingSize, context, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, perf, plugins, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch
Error: You must supply options.input to rollup

I have since realized that rollup.rollup is only capable of accepting one config object and must be called multiple times with each config.

Based on this comment in #863 this is not possible (although from what I can see rollup.watch may accept multiple arguments and as mentioned in the referenced comment this may warrant it's own issue).

As a side note it is also unclear that rollup.watch does accept an array when rollup.rollup does not.

Your Proposal for Changes

If this is the intended behaviour and there is not a planned changed on the immediate horizon I think it would be good to explicitly highlight that the Javascript API does not support multiple entries.

I think it would also be beneficial to perhaps give a rudimentary example of calling rollup.rollup multiple times in the event that a user needs to bundle multiple entries/inputs.

something like:

const { rollup } = require('rollup');

const buildEntries = entries => {
    const pending = entries.map(async item => {
        const [inputOptions, outputOptions] = item;

        const bundle = await rollup(inputOptions);
        await bundle.write(outputOptions);
        return;
    });

    // returns promise that resolves when all rollups complete
    return Promise.all(pending);
}

export default buildEntries;

Where entries would look something like:

[[{
    input: 'component.js',
    plugins: []
},
{
    dir: '/dist',
    name: 'Component',
    format: 'umd'
}]]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Configuration Files and Javascript API documentation, then compare their descriptions of multiple inputs and entries with the reported rollup.rollup and rollup.watch behavior. Done means the API documentation clearly states whether each API accepts multiple configurations and includes guidance or an example for bundling multiple entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.