or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-rollup-plugin-multi-input

Rollup plugin for bundling modular libraries with multiple entry points and preserved directory structure.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rollup-plugin-multi-input@3.0.x

To install, run

npx @tessl/cli install tessl/npm-rollup-plugin-multi-input@3.0.0

index.mddocs/

Rollup Plugin Multi Input

Rollup Plugin Multi Input is a Rollup plugin for bundling modular libraries that allows multiple entry points while preserving the source directory structure in the distribution folder. It supports glob patterns in entry definitions and provides options for customizing the relative path handling and output path transformation.

Package Information

  • Package Name: rollup-plugin-multi-input
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install rollup-plugin-multi-input

Core Imports

import multiInput from "rollup-plugin-multi-input";
import type { MultiInputOptions } from "rollup-plugin-multi-input";

For CommonJS:

const multiInput = require("rollup-plugin-multi-input");

Note: The plugin exports as a default export, and also exports the MultiInputOptions type for TypeScript users.

Basic Usage

import multiInput from "rollup-plugin-multi-input";

export default {
  // Use glob patterns in input
  input: ['src/**/*.js'],
  output: {
    format: 'esm',
    dir: 'dist'
  },
  plugins: [multiInput()],
};

Architecture

The plugin operates by transforming Rollup's input configuration during the options lifecycle hook:

  • Glob Resolution: Uses fast-glob to resolve glob patterns into specific file paths
  • Path Transformation: Converts file paths based on the relative directory and optional transformation function
  • Output Mapping: Creates a mapping between input files and their corresponding output locations
  • Directory Structure Preservation: Maintains the source directory structure in the distribution folder

Capabilities

Multi Input Plugin Creation

Creates a Rollup plugin that processes multiple input files and glob patterns while preserving directory structure.

/**
 * Creates a Rollup plugin for multi-input bundling with directory structure preservation
 * @param options - Configuration options for the plugin
 * @returns Rollup plugin object with name and lifecycle hooks
 */
function multiInput(options?: MultiInputOptions): Plugin;

export type MultiInputOptions = {
  /** Configuration options for fast-glob pattern matching */
  glob?: FastGlob.Options;
  /** Relative path to use as base for output directory structure (default: 'src/' on Unix, 'src\\' on Windows) */
  relative?: string;
  /** Custom function to transform output file paths */
  transformOutputPath?: (path: string, fileName: string) => string;
}

interface Plugin {
  /** Plugin name identifier */
  name: string;
  /** Build start lifecycle hook that displays informational message about Rollup 3+ alternatives */
  buildStart(): void;
  /** Options lifecycle hook that processes input configuration and resolves globs */
  options(config: RollupOptions): RollupOptions;
}

Usage Examples:

import multiInput from "rollup-plugin-multi-input";

// Basic usage with default options
export default {
  input: ['src/**/*.js'],
  output: { format: 'esm', dir: 'dist' },
  plugins: [multiInput()],
};

// Custom relative path
export default {
  input: ['lib/**/*.ts'],
  output: { format: 'cjs', dir: 'build' },
  plugins: [multiInput({ relative: 'lib/' })],
};

// Custom output path transformation
export default {
  input: ['src/**/*.js'],
  output: { format: 'esm', dir: 'dist' },
  plugins: [
    multiInput({
      relative: 'src/',
      transformOutputPath: (path, fileName) => `custom/${path.basename(path)}`,
    })
  ],
};

// Advanced glob options
export default {
  input: ['src/**/*.{js,ts}'],
  output: { format: 'esm', dir: 'dist' },
  plugins: [
    multiInput({
      glob: {
        ignore: ['**/*.test.*', '**/*.spec.*'],
        dot: false
      }
    })
  ],
};

Input Format Support

The plugin supports multiple input formats that can be mixed:

  • String patterns: 'src/**/*.js'
  • Array of patterns: ['src/**/*.js', 'lib/**/*.ts']
  • Mixed arrays: ['src/**/*.js', { customEntry: 'path/to/file.js' }]
// Supported input types
type RollupInput = 
  | string 
  | string[] 
  | Array<string | Record<string, string>>;

Fast Glob Integration

Built on fast-glob for efficient pattern matching with full configuration support.

interface FastGlob.Options {
  /** Current working directory for pattern matching */
  cwd?: string;
  /** Enable deep directory traversal */
  deep?: number;
  /** Patterns to ignore */
  ignore?: string[];
  /** Include dotfiles in matching */
  dot?: boolean;
  /** Follow symbolic links */
  followSymbolicLinks?: boolean;
  /** Additional fast-glob options */
  [option: string]: any;
}

Error Handling

The plugin handles several common error scenarios:

  • Unresolved globs: Non-matching patterns are filtered out silently
  • Invalid non-string entries: Object entries that can't be resolved will cause Rollup to throw during bundle creation
  • Path resolution: Handles both relative and absolute paths with cross-platform compatibility

Integration Notes

  • Works with Rollup 2, 3, and 4
  • Compatible with other Rollup plugins
  • Informational Message: Displays a message during build start asking if you still need the plugin given Rollup 3+'s native preserveModules and preserveModulesRoot options
  • Maintains Rollup's standard plugin interface and lifecycle hooks

Platform Compatibility

  • Windows Support: Uses path.sep for correct path separators in default options (src/ on Unix, src\ on Windows)
  • Cross-platform paths: Normalizes glob patterns with forward slashes internally
  • Node.js versions: Compatible with Node.js 16+