Seamless integration between Rollup and TypeScript with comprehensive error reporting.
—
Core plugin setup and configuration options for integrating TypeScript compilation into Rollup builds.
Creates and configures a Rollup plugin instance for TypeScript compilation.
/**
* Main plugin function that creates a Rollup plugin instance
* @param options - Plugin configuration options (all optional)
* @returns Rollup plugin instance with TypeScript support
*/
declare function typescript(options?: RPT2Options): Plugin;
type RPT2Options = Partial<IOptions>;Usage Example:
import typescript from 'rollup-plugin-typescript2';
// Basic usage with default options
export default {
plugins: [typescript()]
};
// With custom options
export default {
plugins: [
typescript({
check: true,
verbosity: 2,
clean: false,
tsconfig: './src/tsconfig.json',
tsconfigOverride: {
compilerOptions: {
declaration: true
}
}
})
]
};Complete interface defining all available plugin configuration options.
interface IOptions {
/** Current working directory (defaults to process.cwd()) */
cwd: string;
/** File patterns to include for compilation */
include: string | string[];
/** File patterns to exclude from compilation */
exclude: string | string[];
/** Enable/disable diagnostic checks (transpile-only when false) */
check: boolean;
/** Logging verbosity level (0=Error, 1=Warning, 2=Info, 3=Debug) */
verbosity: number;
/** Disable cache and perform clean build */
clean: boolean;
/** Path to cache directory */
cacheRoot: string;
/** Bail out on first syntactic or semantic error */
abortOnError: boolean;
/** Deprecated option for CommonJS compatibility */
rollupCommonJSResolveHack: boolean;
/** Path to tsconfig.json file */
tsconfig?: string;
/** Use tsconfig declarationDir instead of Rollup output directory */
useTsconfigDeclarationDir: boolean;
/** Custom TypeScript module to use instead of peerDependency */
typescript: typeof tsModule;
/** Override options for tsconfig */
tsconfigOverride: any;
/** Array of TypeScript transformers (experimental) */
transformers: TransformerFactoryCreator[];
/** Default options merged with tsconfig */
tsconfigDefaults: any;
/** Callback function for source map processing */
sourceMapCallback: (id: string, map: string) => void;
/** Make object-hash ignore unknown types for cache key generation */
objectHashIgnoreUnknownHack: boolean;
}The plugin applies these default values when options are not specified:
const defaultOptions = {
check: true,
verbosity: VerbosityLevel.Warning, // 1
clean: false,
cacheRoot: "node_modules/.cache/rollup-plugin-typescript2",
include: ["*.ts+(|x)", "**/*.ts+(|x)", "**/*.cts", "**/*.mts"],
exclude: ["*.d.ts", "**/*.d.ts", "**/*.d.cts", "**/*.d.mts"],
abortOnError: true,
rollupCommonJSResolveHack: false,
tsconfig: undefined,
useTsconfigDeclarationDir: false,
tsconfigOverride: {},
transformers: [],
tsconfigDefaults: {},
objectHashIgnoreUnknownHack: false,
cwd: process.cwd()
};Configuration Examples:
// Development build with detailed logging
typescript({
verbosity: 3, // Debug level logging
clean: true, // Always clean cache
check: true // Full type checking
})
// Production build optimized for speed
typescript({
check: false, // Skip type checking (transpile only)
verbosity: 0, // Only show errors
clean: false // Use cache for speed
})
// Custom TypeScript version
typescript({
typescript: require('ttypescript'), // Alternative TS implementation
transformers: [myTransformerFactory]
})The plugin integrates with TypeScript configuration through multiple mechanisms:
/**
* Configuration precedence (lowest to highest):
* 1. Plugin defaults
* 2. tsconfigDefaults
* 3. tsconfig.json contents
* 4. tsconfigOverride
* 5. Forced compiler options
*/
interface ConfigurationFlow {
/** Base defaults provided by the plugin */
defaults: Partial<IOptions>;
/** User-provided default values merged first */
tsconfigDefaults: any;
/** Loaded tsconfig.json configuration */
tsconfig: any;
/** User overrides applied after tsconfig loading */
tsconfigOverride: any;
/** Plugin-enforced compiler options (cannot be overridden) */
forcedOptions: CompilerOptions;
}Forced Compiler Options:
Some TypeScript compiler options are automatically set by the plugin and cannot be overridden:
noEmitHelpers: falseimportHelpers: truenoResolve: falsenoEmit: falsenoEmitOnError: falseinlineSourceMap: falseoutDir: Cache directorydeclarationDir: Rollup output directory (unless useTsconfigDeclarationDir is true)allowNonTsExtensions: trueMulti-Config Example:
// Complex configuration with multiple sources
typescript({
// Default values merged first
tsconfigDefaults: {
compilerOptions: {
declaration: true,
sourceMap: true
}
},
// Specific tsconfig file
tsconfig: './build/tsconfig.build.json',
// Override specific options
tsconfigOverride: {
compilerOptions: {
declaration: false, // Override tsconfig setting
target: 'ES2020' // Override tsconfig setting
}
}
})Install with Tessl CLI
npx tessl i tessl/npm-rollup-plugin-typescript2