or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

custom-transformers.mdfile-processing.mdindex.mdlogging-diagnostics.mdplugin-configuration.mdtypescript-integration.md

plugin-configuration.mddocs/

0

# Plugin Configuration

1

2

Core plugin setup and configuration options for integrating TypeScript compilation into Rollup builds.

3

4

## Capabilities

5

6

### Main Plugin Function

7

8

Creates and configures a Rollup plugin instance for TypeScript compilation.

9

10

```typescript { .api }

11

/**

12

* Main plugin function that creates a Rollup plugin instance

13

* @param options - Plugin configuration options (all optional)

14

* @returns Rollup plugin instance with TypeScript support

15

*/

16

declare function typescript(options?: RPT2Options): Plugin;

17

18

type RPT2Options = Partial<IOptions>;

19

```

20

21

**Usage Example:**

22

23

```javascript

24

import typescript from 'rollup-plugin-typescript2';

25

26

// Basic usage with default options

27

export default {

28

plugins: [typescript()]

29

};

30

31

// With custom options

32

export default {

33

plugins: [

34

typescript({

35

check: true,

36

verbosity: 2,

37

clean: false,

38

tsconfig: './src/tsconfig.json',

39

tsconfigOverride: {

40

compilerOptions: {

41

declaration: true

42

}

43

}

44

})

45

]

46

};

47

```

48

49

### Configuration Options Interface

50

51

Complete interface defining all available plugin configuration options.

52

53

```typescript { .api }

54

interface IOptions {

55

/** Current working directory (defaults to process.cwd()) */

56

cwd: string;

57

58

/** File patterns to include for compilation */

59

include: string | string[];

60

61

/** File patterns to exclude from compilation */

62

exclude: string | string[];

63

64

/** Enable/disable diagnostic checks (transpile-only when false) */

65

check: boolean;

66

67

/** Logging verbosity level (0=Error, 1=Warning, 2=Info, 3=Debug) */

68

verbosity: number;

69

70

/** Disable cache and perform clean build */

71

clean: boolean;

72

73

/** Path to cache directory */

74

cacheRoot: string;

75

76

/** Bail out on first syntactic or semantic error */

77

abortOnError: boolean;

78

79

/** Deprecated option for CommonJS compatibility */

80

rollupCommonJSResolveHack: boolean;

81

82

/** Path to tsconfig.json file */

83

tsconfig?: string;

84

85

/** Use tsconfig declarationDir instead of Rollup output directory */

86

useTsconfigDeclarationDir: boolean;

87

88

/** Custom TypeScript module to use instead of peerDependency */

89

typescript: typeof tsModule;

90

91

/** Override options for tsconfig */

92

tsconfigOverride: any;

93

94

/** Array of TypeScript transformers (experimental) */

95

transformers: TransformerFactoryCreator[];

96

97

/** Default options merged with tsconfig */

98

tsconfigDefaults: any;

99

100

/** Callback function for source map processing */

101

sourceMapCallback: (id: string, map: string) => void;

102

103

/** Make object-hash ignore unknown types for cache key generation */

104

objectHashIgnoreUnknownHack: boolean;

105

}

106

```

107

108

### Default Configuration Values

109

110

The plugin applies these default values when options are not specified:

111

112

```typescript { .api }

113

const defaultOptions = {

114

check: true,

115

verbosity: VerbosityLevel.Warning, // 1

116

clean: false,

117

cacheRoot: "node_modules/.cache/rollup-plugin-typescript2",

118

include: ["*.ts+(|x)", "**/*.ts+(|x)", "**/*.cts", "**/*.mts"],

119

exclude: ["*.d.ts", "**/*.d.ts", "**/*.d.cts", "**/*.d.mts"],

120

abortOnError: true,

121

rollupCommonJSResolveHack: false,

122

tsconfig: undefined,

123

useTsconfigDeclarationDir: false,

124

tsconfigOverride: {},

125

transformers: [],

126

tsconfigDefaults: {},

127

objectHashIgnoreUnknownHack: false,

128

cwd: process.cwd()

129

};

130

```

131

132

**Configuration Examples:**

133

134

```javascript

135

// Development build with detailed logging

136

typescript({

137

verbosity: 3, // Debug level logging

138

clean: true, // Always clean cache

139

check: true // Full type checking

140

})

141

142

// Production build optimized for speed

143

typescript({

144

check: false, // Skip type checking (transpile only)

145

verbosity: 0, // Only show errors

146

clean: false // Use cache for speed

147

})

148

149

// Custom TypeScript version

150

typescript({

151

typescript: require('ttypescript'), // Alternative TS implementation

152

transformers: [myTransformerFactory]

153

})

154

```

155

156

### TypeScript Configuration Integration

157

158

The plugin integrates with TypeScript configuration through multiple mechanisms:

159

160

```typescript { .api }

161

/**

162

* Configuration precedence (lowest to highest):

163

* 1. Plugin defaults

164

* 2. tsconfigDefaults

165

* 3. tsconfig.json contents

166

* 4. tsconfigOverride

167

* 5. Forced compiler options

168

*/

169

interface ConfigurationFlow {

170

/** Base defaults provided by the plugin */

171

defaults: Partial<IOptions>;

172

173

/** User-provided default values merged first */

174

tsconfigDefaults: any;

175

176

/** Loaded tsconfig.json configuration */

177

tsconfig: any;

178

179

/** User overrides applied after tsconfig loading */

180

tsconfigOverride: any;

181

182

/** Plugin-enforced compiler options (cannot be overridden) */

183

forcedOptions: CompilerOptions;

184

}

185

```

186

187

**Forced Compiler Options:**

188

189

Some TypeScript compiler options are automatically set by the plugin and cannot be overridden:

190

191

- `noEmitHelpers`: false

192

- `importHelpers`: true

193

- `noResolve`: false

194

- `noEmit`: false

195

- `noEmitOnError`: false

196

- `inlineSourceMap`: false

197

- `outDir`: Cache directory

198

- `declarationDir`: Rollup output directory (unless `useTsconfigDeclarationDir` is true)

199

- `allowNonTsExtensions`: true

200

201

**Multi-Config Example:**

202

203

```javascript

204

// Complex configuration with multiple sources

205

typescript({

206

// Default values merged first

207

tsconfigDefaults: {

208

compilerOptions: {

209

declaration: true,

210

sourceMap: true

211

}

212

},

213

214

// Specific tsconfig file

215

tsconfig: './build/tsconfig.build.json',

216

217

// Override specific options

218

tsconfigOverride: {

219

compilerOptions: {

220

declaration: false, // Override tsconfig setting

221

target: 'ES2020' // Override tsconfig setting

222

}

223

}

224

})

225

```