A Rollup plugin that allows use of multiple entry points for a bundle, combining named exports from all entry files
npx @tessl/cli install tessl/npm-rollup--plugin-multi-entry@6.0.0A 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.
npm install @rollup/plugin-multi-entry --save-devimport multiEntry from '@rollup/plugin-multi-entry';For CommonJS:
const multiEntry = require('@rollup/plugin-multi-entry');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.
The plugin implements a virtual entry file approach with the following key components:
options, outputOptions, buildStart, resolveId, load) to coordinate the virtual entry systemmatched library for glob pattern resolutionThe 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.
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;
}The plugin extends Rollup's input option to support multiple value types:
Single file path or glob pattern:
export default {
input: 'src/**/*.js',
plugins: [multiEntry()]
};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()]
};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()]
};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 })Customize the generated entry file name:
multiEntry({ entryFileName: 'my-custom-entry.js' })Compatible with Rollup's preserveModules option:
export default {
input: 'src/**/*.js',
output: {
dir: 'dist',
preserveModules: true
},
plugins: [multiEntry({ preserveModules: true })]
};@rollup/plugin-virtual: Virtual file system plugin for creating the entry filematched: File matching utility for glob pattern support