Rollup plugin for bundling modular libraries with multiple entry points and preserved directory structure.
npx @tessl/cli install tessl/npm-rollup-plugin-multi-input@3.0.00
# Rollup Plugin Multi Input
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: rollup-plugin-multi-input
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install rollup-plugin-multi-input`
10
11
## Core Imports
12
13
```typescript
14
import multiInput from "rollup-plugin-multi-input";
15
import type { MultiInputOptions } from "rollup-plugin-multi-input";
16
```
17
18
For CommonJS:
19
20
```javascript
21
const multiInput = require("rollup-plugin-multi-input");
22
```
23
24
**Note**: The plugin exports as a default export, and also exports the `MultiInputOptions` type for TypeScript users.
25
26
## Basic Usage
27
28
```typescript
29
import multiInput from "rollup-plugin-multi-input";
30
31
export default {
32
// Use glob patterns in input
33
input: ['src/**/*.js'],
34
output: {
35
format: 'esm',
36
dir: 'dist'
37
},
38
plugins: [multiInput()],
39
};
40
```
41
42
## Architecture
43
44
The plugin operates by transforming Rollup's input configuration during the `options` lifecycle hook:
45
46
- **Glob Resolution**: Uses fast-glob to resolve glob patterns into specific file paths
47
- **Path Transformation**: Converts file paths based on the relative directory and optional transformation function
48
- **Output Mapping**: Creates a mapping between input files and their corresponding output locations
49
- **Directory Structure Preservation**: Maintains the source directory structure in the distribution folder
50
51
## Capabilities
52
53
### Multi Input Plugin Creation
54
55
Creates a Rollup plugin that processes multiple input files and glob patterns while preserving directory structure.
56
57
```typescript { .api }
58
/**
59
* Creates a Rollup plugin for multi-input bundling with directory structure preservation
60
* @param options - Configuration options for the plugin
61
* @returns Rollup plugin object with name and lifecycle hooks
62
*/
63
function multiInput(options?: MultiInputOptions): Plugin;
64
65
export type MultiInputOptions = {
66
/** Configuration options for fast-glob pattern matching */
67
glob?: FastGlob.Options;
68
/** Relative path to use as base for output directory structure (default: 'src/' on Unix, 'src\\' on Windows) */
69
relative?: string;
70
/** Custom function to transform output file paths */
71
transformOutputPath?: (path: string, fileName: string) => string;
72
}
73
74
interface Plugin {
75
/** Plugin name identifier */
76
name: string;
77
/** Build start lifecycle hook that displays informational message about Rollup 3+ alternatives */
78
buildStart(): void;
79
/** Options lifecycle hook that processes input configuration and resolves globs */
80
options(config: RollupOptions): RollupOptions;
81
}
82
```
83
84
**Usage Examples:**
85
86
```typescript
87
import multiInput from "rollup-plugin-multi-input";
88
89
// Basic usage with default options
90
export default {
91
input: ['src/**/*.js'],
92
output: { format: 'esm', dir: 'dist' },
93
plugins: [multiInput()],
94
};
95
96
// Custom relative path
97
export default {
98
input: ['lib/**/*.ts'],
99
output: { format: 'cjs', dir: 'build' },
100
plugins: [multiInput({ relative: 'lib/' })],
101
};
102
103
// Custom output path transformation
104
export default {
105
input: ['src/**/*.js'],
106
output: { format: 'esm', dir: 'dist' },
107
plugins: [
108
multiInput({
109
relative: 'src/',
110
transformOutputPath: (path, fileName) => `custom/${path.basename(path)}`,
111
})
112
],
113
};
114
115
// Advanced glob options
116
export default {
117
input: ['src/**/*.{js,ts}'],
118
output: { format: 'esm', dir: 'dist' },
119
plugins: [
120
multiInput({
121
glob: {
122
ignore: ['**/*.test.*', '**/*.spec.*'],
123
dot: false
124
}
125
})
126
],
127
};
128
```
129
130
### Input Format Support
131
132
The plugin supports multiple input formats that can be mixed:
133
134
- **String patterns**: `'src/**/*.js'`
135
- **Array of patterns**: `['src/**/*.js', 'lib/**/*.ts']`
136
- **Mixed arrays**: `['src/**/*.js', { customEntry: 'path/to/file.js' }]`
137
138
```typescript { .api }
139
// Supported input types
140
type RollupInput =
141
| string
142
| string[]
143
| Array<string | Record<string, string>>;
144
```
145
146
### Fast Glob Integration
147
148
Built on fast-glob for efficient pattern matching with full configuration support.
149
150
```typescript { .api }
151
interface FastGlob.Options {
152
/** Current working directory for pattern matching */
153
cwd?: string;
154
/** Enable deep directory traversal */
155
deep?: number;
156
/** Patterns to ignore */
157
ignore?: string[];
158
/** Include dotfiles in matching */
159
dot?: boolean;
160
/** Follow symbolic links */
161
followSymbolicLinks?: boolean;
162
/** Additional fast-glob options */
163
[option: string]: any;
164
}
165
```
166
167
## Error Handling
168
169
The plugin handles several common error scenarios:
170
171
- **Unresolved globs**: Non-matching patterns are filtered out silently
172
- **Invalid non-string entries**: Object entries that can't be resolved will cause Rollup to throw during bundle creation
173
- **Path resolution**: Handles both relative and absolute paths with cross-platform compatibility
174
175
## Integration Notes
176
177
- Works with Rollup 2, 3, and 4
178
- Compatible with other Rollup plugins
179
- **Informational Message**: Displays a message during build start asking if you still need the plugin given Rollup 3+'s native `preserveModules` and `preserveModulesRoot` options
180
- Maintains Rollup's standard plugin interface and lifecycle hooks
181
182
## Platform Compatibility
183
184
- **Windows Support**: Uses `path.sep` for correct path separators in default options (`src/` on Unix, `src\` on Windows)
185
- **Cross-platform paths**: Normalizes glob patterns with forward slashes internally
186
- **Node.js versions**: Compatible with Node.js 16+