or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

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

To install, run

npx @tessl/cli install tessl/npm-rollup--plugin-multi-entry@6.0.0

0

# Rollup Multi-Entry Plugin

1

2

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.

3

4

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.

5

6

## Package Information

7

8

- **Package Name**: @rollup/plugin-multi-entry

9

- **Package Type**: npm

10

- **Language**: JavaScript/TypeScript

11

- **Installation**: `npm install @rollup/plugin-multi-entry --save-dev`

12

13

## Core Imports

14

15

```javascript

16

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

17

```

18

19

For CommonJS:

20

21

```javascript

22

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

23

```

24

25

## Basic Usage

26

27

```javascript

28

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

29

30

export default {

31

input: ['src/batman.js', 'src/robin.js', 'src/joker.js'],

32

output: {

33

dir: 'output'

34

},

35

plugins: [multiEntry()]

36

};

37

```

38

39

With the following input files:

40

41

```javascript

42

// batman.js

43

export const belt = 'utility';

44

45

// robin.js

46

export const tights = 'tight';

47

48

// joker.js

49

export const color = 'purple';

50

```

51

52

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

53

54

## Architecture

55

56

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

57

58

- **Virtual Entry Generation**: Creates a virtual entry file that imports/exports from all matched input files

59

- **Input Transformation**: Modifies Rollup's input option to point to the virtual entry file

60

- **Hook Implementation**: Uses Rollup hooks (`options`, `outputOptions`, `buildStart`, `resolveId`, `load`) to coordinate the virtual entry system

61

- **Pattern Matching**: Leverages the `matched` library for glob pattern resolution

62

- **File Combination**: Combines named exports from all entry files into a single bundle

63

64

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.

65

66

## Capabilities

67

68

### Multi-Entry Plugin Factory

69

70

Creates a Rollup plugin for multi-entry bundling.

71

72

```typescript { .api }

73

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

74

import type { Plugin } from 'rollup';

75

76

function multiEntry(options?: RollupMultiEntryOptions): Plugin;

77

78

interface RollupMultiEntryOptions {

79

/**

80

* A minimatch pattern, or array of patterns, which specifies the files

81

* in the build the plugin should operate on. By default all files are targeted.

82

*/

83

include?: FilterPattern;

84

/**

85

* A minimatch pattern, or array of patterns, which specifies the files

86

* in the build the plugin should ignore. By default no files are ignored.

87

*/

88

exclude?: FilterPattern;

89

/**

90

* If true, instructs the plugin to export named exports to the bundle from all entries.

91

* If false, the plugin will not export any entry exports to the bundle.

92

* @default true

93

*/

94

exports?: boolean;

95

/**

96

* Changes the name of the generated entry file.

97

* By default, it will override outputOptions.entryFileNames to be 'multi-entry.js'.

98

* @default 'multi-entry.js'

99

*/

100

entryFileName?: string;

101

/**

102

* The preserveModules option is to be used in conjunction with output.preserveModules.

103

* If true, overrides the entryFileName option to be output.entryFileNames.

104

* If false, the plugin will respect the entryFileName option.

105

* @default false

106

*/

107

preserveModules?: boolean;

108

}

109

```

110

111

### Input Type Support

112

113

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

114

115

#### String (Glob Pattern)

116

Single file path or glob pattern:

117

118

```javascript

119

export default {

120

input: 'src/**/*.js',

121

plugins: [multiEntry()]

122

};

123

```

124

125

#### Array of Strings

126

Multiple file paths or glob patterns:

127

128

```javascript

129

export default {

130

input: ['src/core/*.js', 'src/utils/*.js'],

131

plugins: [multiEntry()]

132

};

133

```

134

135

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

136

137

```javascript

138

export default {

139

input: [],

140

plugins: [multiEntry()]

141

};

142

```

143

144

#### Object with Include/Exclude

145

Fine-grain control with include and exclude patterns:

146

147

```javascript

148

export default {

149

input: {

150

include: ['src/**/*.js'],

151

exclude: ['src/**/*.test.js'],

152

exports: true,

153

entryFileName: 'my-bundle.js'

154

},

155

plugins: [multiEntry()]

156

};

157

```

158

159

### Configuration Options

160

161

#### Export Control

162

163

Control whether named exports are combined:

164

165

```javascript

166

// Export all named exports (default)

167

multiEntry({ exports: true })

168

169

// Don't export any named exports (just combine code)

170

multiEntry({ exports: false })

171

```

172

173

#### Entry File Naming

174

175

Customize the generated entry file name:

176

177

```javascript

178

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

179

```

180

181

#### Preserve Modules

182

183

Compatible with Rollup's `preserveModules` option:

184

185

```javascript

186

export default {

187

input: 'src/**/*.js',

188

output: {

189

dir: 'dist',

190

preserveModules: true

191

},

192

plugins: [multiEntry({ preserveModules: true })]

193

};

194

```

195

196

## Requirements

197

198

- **Node.js**: v14.0.0+

199

- **Rollup**: v1.20.0+ (supports v1.20.0, v2.x, v3.x, and v4.x)

200

201

## Limitations

202

203

- Default exports cannot be combined and exported by this plugin

204

- Only named exports will be exported to the bundle

205

- The plugin creates a virtual entry file to coordinate the multi-entry bundling

206

207

## Dependencies

208

209

- `@rollup/plugin-virtual`: Virtual file system plugin for creating the entry file

210

- `matched`: File matching utility for glob pattern support