or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

custom-plugin-factories.mdindex.mdinput-plugin.mdoutput-plugin.md

input-plugin.mddocs/

0

# Input Plugin

1

2

The input plugin transforms source files during the input processing phase of Rollup. It's the primary way to use Babel with Rollup and supports comprehensive configuration options for file filtering, helper handling, and Babel integration.

3

4

## Capabilities

5

6

### Main Plugin Function

7

8

The default export and primary plugin function for input transformation.

9

10

```javascript { .api }

11

/**

12

* A Rollup plugin for seamless integration between Rollup and Babel

13

* @param options - Plugin options extending Babel transform options

14

* @returns Plugin instance for input transformation

15

*/

16

function babel(options?: RollupBabelInputPluginOptions): Plugin;

17

18

// Alias for babel function

19

function getBabelInputPlugin(options?: RollupBabelInputPluginOptions): Plugin;

20

```

21

22

**Usage Examples:**

23

24

```javascript

25

import { babel } from '@rollup/plugin-babel';

26

27

// Basic usage with bundled helpers

28

export default {

29

input: 'src/index.js',

30

plugins: [babel({ babelHelpers: 'bundled' })],

31

output: { file: 'dist/bundle.js', format: 'es' }

32

};

33

34

// Advanced configuration

35

export default {

36

input: 'src/index.js',

37

plugins: [

38

babel({

39

babelHelpers: 'runtime',

40

extensions: ['.js', '.jsx', '.ts', '.tsx'],

41

exclude: 'node_modules/**',

42

include: 'src/**/*',

43

skipPreflightCheck: false,

44

presets: ['@babel/preset-env', '@babel/preset-react'],

45

plugins: ['@babel/plugin-transform-runtime']

46

})

47

],

48

output: { file: 'dist/bundle.js', format: 'es' }

49

};

50

```

51

52

### Configuration Options

53

54

Complete configuration interface for input plugin.

55

56

```javascript { .api }

57

interface RollupBabelInputPluginOptions extends Omit<BabelTransformOptions, 'include' | 'exclude'> {

58

/**

59

* A picomatch pattern, or array of patterns, which specifies the files to include

60

* @default undefined

61

*/

62

include?: FilterPattern;

63

64

/**

65

* A picomatch pattern, or array of patterns, which specifies the files to exclude

66

* @default undefined

67

*/

68

exclude?: FilterPattern;

69

70

/**

71

* Custom filter function for determining which modules should be operated upon

72

* @default undefined

73

*/

74

filter?: ReturnType<CreateFilter>;

75

76

/**

77

* An array of file extensions that Babel should transpile

78

* @default ['.js', '.jsx', '.es6', '.es', '.mjs']

79

*/

80

extensions?: string[];

81

82

/**

83

* How babel helpers are inserted into the code

84

* @default 'bundled'

85

*/

86

babelHelpers?: 'bundled' | 'runtime' | 'inline' | 'external';

87

88

/**

89

* Skip validation checks for better performance in large projects

90

* @default false

91

*/

92

skipPreflightCheck?: boolean;

93

}

94

```

95

96

**Usage Examples:**

97

98

### File Filtering

99

100

Control which files are processed by the plugin:

101

102

```javascript

103

import { babel } from '@rollup/plugin-babel';

104

import { createFilter } from '@rollup/pluginutils';

105

106

// Using include/exclude patterns

107

babel({

108

babelHelpers: 'bundled',

109

include: ['src/**/*', 'lib/**/*'],

110

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

111

});

112

113

// Using custom filter function

114

const filter = createFilter('src/**/*.js', 'src/**/*.test.js');

115

babel({

116

babelHelpers: 'bundled',

117

filter: filter

118

});

119

120

// Using extensions

121

babel({

122

babelHelpers: 'bundled',

123

extensions: ['.js', '.jsx', '.ts', '.tsx']

124

});

125

```

126

127

### Helper Strategies

128

129

Different approaches for handling Babel helpers:

130

131

```javascript

132

// Bundled helpers (recommended for applications)

133

babel({ babelHelpers: 'bundled' });

134

135

// Runtime helpers (recommended for libraries)

136

babel({

137

babelHelpers: 'runtime',

138

plugins: ['@babel/plugin-transform-runtime']

139

});

140

141

// External helpers (requires global babelHelpers)

142

babel({

143

babelHelpers: 'external',

144

plugins: ['@babel/plugin-external-helpers']

145

});

146

147

// Inline helpers (not recommended - causes duplication)

148

babel({ babelHelpers: 'inline' });

149

```

150

151

### Performance Optimization

152

153

Options for improving build performance:

154

155

```javascript

156

// Skip preflight checks for better performance

157

babel({

158

babelHelpers: 'bundled',

159

skipPreflightCheck: true, // Only use if configuration is stable

160

exclude: 'node_modules/**' // Exclude dependencies

161

});

162

```

163

164

### Integration with Other Plugins

165

166

Proper plugin ordering, especially with CommonJS:

167

168

```javascript

169

import commonjs from '@rollup/plugin-commonjs';

170

import { babel } from '@rollup/plugin-babel';

171

172

export default {

173

plugins: [

174

// CommonJS must come before Babel

175

commonjs(),

176

babel({ babelHelpers: 'bundled' })

177

]

178

};

179

```

180

181

## Types

182

183

```javascript { .api }

184

// From @rollup/pluginutils

185

type FilterPattern = string | RegExp | Array<string | RegExp>;

186

type CreateFilter = (include?: FilterPattern, exclude?: FilterPattern, options?: FilterOptions) => (id: string | unknown) => boolean;

187

188

interface FilterOptions {

189

resolve?: string | false | null;

190

}

191

192

// From @babel/core

193

interface BabelTransformOptions {

194

filename?: string;

195

filenameRelative?: string;

196

presets?: any[];

197

plugins?: any[];

198

sourceMaps?: boolean;

199

sourceType?: 'script' | 'module' | 'unambiguous';

200

// ... other Babel options

201

}

202

203

// From rollup

204

interface Plugin {

205

name: string;

206

options?(): void;

207

resolveId?(id: string): string | null;

208

load?(id: string): string | null;

209

transform?(code: string, filename: string): TransformResult | null;

210

}

211

212

interface TransformResult {

213

code: string;

214

map?: SourceMap;

215

}

216

217

interface SourceMap {

218

version: number;

219

sources: string[];

220

names: string[];

221

mappings: string;

222

file?: string;

223

sourcesContent?: string[];

224

}

225

```