CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rollup--plugin-multi-entry

A Rollup plugin that allows use of multiple entry points for a bundle, combining named exports from all entry files

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Rollup Multi-Entry Plugin

A Rollup plugin that enables use of multiple entry points for a single bundle, automatically combining named exports from all entry files. It extends Rollup's input option to support various input types including glob patterns, arrays of paths, and include/exclude configurations for fine-grain control over which files should be used as entry points.

The plugin works by creating a virtual entry file that imports or exports from all matched entry files, then hands control back to Rollup for the actual bundling process.

Package Information

  • Package Name: @rollup/plugin-multi-entry
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install @rollup/plugin-multi-entry --save-dev

Core Imports

import multiEntry from '@rollup/plugin-multi-entry';

For CommonJS:

const multiEntry = require('@rollup/plugin-multi-entry');

Basic Usage

import multiEntry from '@rollup/plugin-multi-entry';

export default {
  input: ['src/batman.js', 'src/robin.js', 'src/joker.js'],
  output: {
    dir: 'output'
  },
  plugins: [multiEntry()]
};

With the following input files:

// batman.js
export const belt = 'utility';

// robin.js  
export const tights = 'tight';

// joker.js
export const color = 'purple';

The resulting bundle will export belt, tights, and color as named exports.

Architecture

The plugin implements a virtual entry file approach with the following key components:

  • Virtual Entry Generation: Creates a virtual entry file that imports/exports from all matched input files
  • Input Transformation: Modifies Rollup's input option to point to the virtual entry file
  • Hook Implementation: Uses Rollup hooks (options, outputOptions, buildStart, resolveId, load) to coordinate the virtual entry system
  • Pattern Matching: Leverages the matched library for glob pattern resolution
  • File Combination: Combines named exports from all entry files into a single bundle

The plugin intercepts Rollup's normal entry resolution process, replaces the input with a virtual entry file, and then provides that virtual file's content through Rollup's plugin hooks.

Capabilities

Multi-Entry Plugin Factory

Creates a Rollup plugin for multi-entry bundling.

import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

function multiEntry(options?: RollupMultiEntryOptions): Plugin;

interface RollupMultiEntryOptions {
  /** 
   * A minimatch pattern, or array of patterns, which specifies the files 
   * in the build the plugin should operate on. By default all files are targeted.
   */
  include?: FilterPattern;
  /** 
   * A minimatch pattern, or array of patterns, which specifies the files 
   * in the build the plugin should ignore. By default no files are ignored.
   */
  exclude?: FilterPattern;
  /** 
   * If true, instructs the plugin to export named exports to the bundle from all entries.
   * If false, the plugin will not export any entry exports to the bundle.
   * @default true
   */
  exports?: boolean;
  /** 
   * Changes the name of the generated entry file.
   * By default, it will override outputOptions.entryFileNames to be 'multi-entry.js'.
   * @default 'multi-entry.js'
   */
  entryFileName?: string;
  /** 
   * The preserveModules option is to be used in conjunction with output.preserveModules.
   * If true, overrides the entryFileName option to be output.entryFileNames.
   * If false, the plugin will respect the entryFileName option.
   * @default false
   */
  preserveModules?: boolean;
}

Input Type Support

The plugin extends Rollup's input option to support multiple value types:

String (Glob Pattern)

Single file path or glob pattern:

export default {
  input: 'src/**/*.js',
  plugins: [multiEntry()]
};

Array of Strings

Multiple file paths or glob patterns:

export default {
  input: ['src/core/*.js', 'src/utils/*.js'],
  plugins: [multiEntry()]
};

Empty arrays are also supported and result in an empty bundle:

export default {
  input: [],
  plugins: [multiEntry()]
};

Object with Include/Exclude

Fine-grain control with include and exclude patterns:

export default {
  input: {
    include: ['src/**/*.js'],
    exclude: ['src/**/*.test.js'],
    exports: true,
    entryFileName: 'my-bundle.js'
  },
  plugins: [multiEntry()]
};

Configuration Options

Export Control

Control whether named exports are combined:

// Export all named exports (default)
multiEntry({ exports: true })

// Don't export any named exports (just combine code)
multiEntry({ exports: false })

Entry File Naming

Customize the generated entry file name:

multiEntry({ entryFileName: 'my-custom-entry.js' })

Preserve Modules

Compatible with Rollup's preserveModules option:

export default {
  input: 'src/**/*.js',
  output: {
    dir: 'dist',
    preserveModules: true
  },
  plugins: [multiEntry({ preserveModules: true })]
};

Requirements

  • Node.js: v14.0.0+
  • Rollup: v1.20.0+ (supports v1.20.0, v2.x, v3.x, and v4.x)

Limitations

  • Default exports cannot be combined and exported by this plugin
  • Only named exports will be exported to the bundle
  • The plugin creates a virtual entry file to coordinate the multi-entry bundling

Dependencies

  • @rollup/plugin-virtual: Virtual file system plugin for creating the entry file
  • matched: File matching utility for glob pattern support
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@rollup/plugin-multi-entry@6.0.x
Publish Source
CLI
Badge
tessl/npm-rollup--plugin-multi-entry badge