or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

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

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

index.mddocs/

Rollup Plugin TypeScript2

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.

Package Information

  • Package Name: rollup-plugin-typescript2
  • Package Type: npm
  • Language: TypeScript/JavaScript
  • Installation: npm install rollup-plugin-typescript2 typescript tslib --save-dev

Core Imports

// Default export - main plugin function
import typescript from 'rollup-plugin-typescript2';

// Named export - options type
import { RPT2Options } from 'rollup-plugin-typescript2';

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

For CommonJS:

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

// Destructured named export
const { RPT2Options } = require('rollup-plugin-typescript2');

Basic Usage

// rollup.config.js
import typescript from 'rollup-plugin-typescript2';

export default {
  input: './main.ts',
  
  plugins: [
    typescript({
      // Plugin options (all optional)
      check: true,          // Enable type checking
      verbosity: 1,         // 0=Error, 1=Warning, 2=Info, 3=Debug
      clean: false,         // Clean build cache
      tsconfig: undefined,  // Path to tsconfig.json
      useTsconfigDeclarationDir: false, // Use tsconfig declarationDir
      // ... other options
    })
  ],
  
  output: {
    file: 'dist/bundle.js',
    format: 'es'
  }
};

Architecture

Rollup Plugin TypeScript2 is built around several core components:

  • Plugin Core: Main Rollup plugin implementation with lifecycle hooks
  • TypeScript Service: Language service integration for compilation and diagnostics
  • Caching System: Intelligent caching for improved build performance
  • Configuration Management: TSConfig parsing and option overrides
  • Error Reporting: Comprehensive diagnostic message display
  • Declaration Generation: Support for .d.ts file output

Capabilities

Plugin Configuration

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

/**
 * Main plugin function that creates a Rollup plugin instance (default export)
 * @param options - Plugin configuration options
 * @returns Rollup plugin instance
 */
export default function typescript(options?: RPT2Options): Plugin;

/**
 * Type alias for plugin options (named export)
 */
export type RPT2Options = Partial<IOptions>;

Plugin Configuration

TypeScript Integration

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

interface IOptions {
  cwd: string;
  check: boolean;
  verbosity: VerbosityLevel;
  typescript: typeof import('typescript');
  tsconfig?: string;
  tsconfigOverride: any;
  tsconfigDefaults: any;
}

TypeScript Integration

File Processing

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

interface IOptions {
  include: string | string[];
  exclude: string | string[];
  clean: boolean;
  cacheRoot: string;
  abortOnError: boolean;
}

File Processing

Custom Transformers

Experimental support for TypeScript transformers to modify the compilation process.

import * as tsTypes from 'typescript';

interface ICustomTransformer {
  before?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
  after?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
  afterDeclarations?: tsTypes.TransformerFactory<tsTypes.Bundle | tsTypes.SourceFile>;
}

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

Custom Transformers

Logging and Diagnostics

Verbosity control and diagnostic message reporting system.

import { PluginContext } from 'rollup';

enum VerbosityLevel {
  Error = 0,
  Warning = 1,
  Info = 2,
  Debug = 3
}

class RollupContext {
  constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);
  
  warn(message: string | (() => string)): void;
  error(message: string | (() => string)): void | never;
  info(message: string | (() => string)): void;
  debug(message: string | (() => string)): void;
}

Logging and Diagnostics

Core Types

import { Plugin, PluginContext } from 'rollup';
import * as tsTypes from 'typescript';

interface IOptions {
  cwd: string;
  include: string | string[];
  exclude: string | string[];
  check: boolean;
  verbosity: VerbosityLevel;
  clean: boolean;
  cacheRoot: string;
  abortOnError: boolean;
  rollupCommonJSResolveHack: boolean;
  tsconfig?: string;
  useTsconfigDeclarationDir: boolean;
  typescript: typeof import('typescript');
  tsconfigOverride: any;
  transformers: TransformerFactoryCreator[];
  tsconfigDefaults: any;
  sourceMapCallback: (id: string, map: string) => void;
  objectHashIgnoreUnknownHack: boolean;
}

type RPT2Options = Partial<IOptions>;

enum VerbosityLevel {
  Error = 0,
  Warning = 1,
  Info = 2,
  Debug = 3
}

interface ICustomTransformer {
  before?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
  after?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
  afterDeclarations?: tsTypes.TransformerFactory<tsTypes.Bundle | tsTypes.SourceFile>;
}

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

class RollupContext {
  constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);
  
  warn(message: string | (() => string)): void;
  error(message: string | (() => string)): void | never;
  info(message: string | (() => string)): void;
  debug(message: string | (() => string)): void;
}