or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-rollup-plugin-typescript2

Seamless integration between Rollup and TypeScript with comprehensive error reporting.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rollup-plugin-typescript2@0.36.x

To install, run

npx @tessl/cli install tessl/npm-rollup-plugin-typescript2@0.36.0

0

# Rollup Plugin TypeScript2

1

2

Rollup plugin for TypeScript with comprehensive error reporting and diagnostic capabilities. This is a rewrite of the original rollup-plugin-typescript that provides seamless integration between Rollup and TypeScript while displaying TypeScript syntactic and semantic diagnostic messages during the build process.

3

4

## Package Information

5

6

- **Package Name**: rollup-plugin-typescript2

7

- **Package Type**: npm

8

- **Language**: TypeScript/JavaScript

9

- **Installation**: `npm install rollup-plugin-typescript2 typescript tslib --save-dev`

10

11

## Core Imports

12

13

```typescript

14

// Default export - main plugin function

15

import typescript from 'rollup-plugin-typescript2';

16

17

// Named export - options type

18

import { RPT2Options } from 'rollup-plugin-typescript2';

19

20

// Combined import

21

import typescript, { RPT2Options } from 'rollup-plugin-typescript2';

22

```

23

24

For CommonJS:

25

26

```javascript

27

// Default export

28

const typescript = require('rollup-plugin-typescript2');

29

30

// Destructured named export

31

const { RPT2Options } = require('rollup-plugin-typescript2');

32

```

33

34

## Basic Usage

35

36

```javascript

37

// rollup.config.js

38

import typescript from 'rollup-plugin-typescript2';

39

40

export default {

41

input: './main.ts',

42

43

plugins: [

44

typescript({

45

// Plugin options (all optional)

46

check: true, // Enable type checking

47

verbosity: 1, // 0=Error, 1=Warning, 2=Info, 3=Debug

48

clean: false, // Clean build cache

49

tsconfig: undefined, // Path to tsconfig.json

50

useTsconfigDeclarationDir: false, // Use tsconfig declarationDir

51

// ... other options

52

})

53

],

54

55

output: {

56

file: 'dist/bundle.js',

57

format: 'es'

58

}

59

};

60

```

61

62

## Architecture

63

64

Rollup Plugin TypeScript2 is built around several core components:

65

66

- **Plugin Core**: Main Rollup plugin implementation with lifecycle hooks

67

- **TypeScript Service**: Language service integration for compilation and diagnostics

68

- **Caching System**: Intelligent caching for improved build performance

69

- **Configuration Management**: TSConfig parsing and option overrides

70

- **Error Reporting**: Comprehensive diagnostic message display

71

- **Declaration Generation**: Support for .d.ts file output

72

73

## Capabilities

74

75

### Plugin Configuration

76

77

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

78

79

```typescript { .api }

80

/**

81

* Main plugin function that creates a Rollup plugin instance (default export)

82

* @param options - Plugin configuration options

83

* @returns Rollup plugin instance

84

*/

85

export default function typescript(options?: RPT2Options): Plugin;

86

87

/**

88

* Type alias for plugin options (named export)

89

*/

90

export type RPT2Options = Partial<IOptions>;

91

```

92

93

[Plugin Configuration](./plugin-configuration.md)

94

95

### TypeScript Integration

96

97

TypeScript compiler integration with language service, diagnostics, and type checking capabilities.

98

99

```typescript { .api }

100

interface IOptions {

101

cwd: string;

102

check: boolean;

103

verbosity: VerbosityLevel;

104

typescript: typeof import('typescript');

105

tsconfig?: string;

106

tsconfigOverride: any;

107

tsconfigDefaults: any;

108

}

109

```

110

111

[TypeScript Integration](./typescript-integration.md)

112

113

### File Processing

114

115

File filtering, caching, and transformation system for handling TypeScript source files.

116

117

```typescript { .api }

118

interface IOptions {

119

include: string | string[];

120

exclude: string | string[];

121

clean: boolean;

122

cacheRoot: string;

123

abortOnError: boolean;

124

}

125

```

126

127

[File Processing](./file-processing.md)

128

129

### Custom Transformers

130

131

Experimental support for TypeScript transformers to modify the compilation process.

132

133

```typescript { .api }

134

import * as tsTypes from 'typescript';

135

136

interface ICustomTransformer {

137

before?: tsTypes.TransformerFactory<tsTypes.SourceFile>;

138

after?: tsTypes.TransformerFactory<tsTypes.SourceFile>;

139

afterDeclarations?: tsTypes.TransformerFactory<tsTypes.Bundle | tsTypes.SourceFile>;

140

}

141

142

type TransformerFactoryCreator = (ls: tsTypes.LanguageService) => tsTypes.CustomTransformers | ICustomTransformer;

143

```

144

145

[Custom Transformers](./custom-transformers.md)

146

147

### Logging and Diagnostics

148

149

Verbosity control and diagnostic message reporting system.

150

151

```typescript { .api }

152

import { PluginContext } from 'rollup';

153

154

enum VerbosityLevel {

155

Error = 0,

156

Warning = 1,

157

Info = 2,

158

Debug = 3

159

}

160

161

class RollupContext {

162

constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);

163

164

warn(message: string | (() => string)): void;

165

error(message: string | (() => string)): void | never;

166

info(message: string | (() => string)): void;

167

debug(message: string | (() => string)): void;

168

}

169

```

170

171

[Logging and Diagnostics](./logging-diagnostics.md)

172

173

## Core Types

174

175

```typescript { .api }

176

import { Plugin, PluginContext } from 'rollup';

177

import * as tsTypes from 'typescript';

178

179

interface IOptions {

180

cwd: string;

181

include: string | string[];

182

exclude: string | string[];

183

check: boolean;

184

verbosity: VerbosityLevel;

185

clean: boolean;

186

cacheRoot: string;

187

abortOnError: boolean;

188

rollupCommonJSResolveHack: boolean;

189

tsconfig?: string;

190

useTsconfigDeclarationDir: boolean;

191

typescript: typeof import('typescript');

192

tsconfigOverride: any;

193

transformers: TransformerFactoryCreator[];

194

tsconfigDefaults: any;

195

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

196

objectHashIgnoreUnknownHack: boolean;

197

}

198

199

type RPT2Options = Partial<IOptions>;

200

201

enum VerbosityLevel {

202

Error = 0,

203

Warning = 1,

204

Info = 2,

205

Debug = 3

206

}

207

208

interface ICustomTransformer {

209

before?: tsTypes.TransformerFactory<tsTypes.SourceFile>;

210

after?: tsTypes.TransformerFactory<tsTypes.SourceFile>;

211

afterDeclarations?: tsTypes.TransformerFactory<tsTypes.Bundle | tsTypes.SourceFile>;

212

}

213

214

type TransformerFactoryCreator = (ls: tsTypes.LanguageService) => tsTypes.CustomTransformers | ICustomTransformer;

215

216

class RollupContext {

217

constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);

218

219

warn(message: string | (() => string)): void;

220

error(message: string | (() => string)): void | never;

221

info(message: string | (() => string)): void;

222

debug(message: string | (() => string)): void;

223

}

224

```