A TypeScript compiler for gulp with incremental compilation support
npx @tessl/cli install tessl/npm-gulp-typescript@5.0.0Gulp TypeScript is a comprehensive TypeScript compiler plugin for the gulp build system that enables incremental compilation, source map support, and flexible configuration options. It exposes TypeScript's compiler API to gulp workflows, allowing developers to compile TypeScript files with full control over compiler options including target ECMAScript versions, module systems, declaration file generation, and custom transformers.
npm install gulp-typescript typescriptimport * as ts from 'gulp-typescript';For CommonJS:
const ts = require('gulp-typescript');import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
// Basic compilation
gulp.task('compile', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
noImplicitAny: true,
outDir: 'dist'
}))
.pipe(gulp.dest('dist'));
});
// Project-based compilation with incremental builds
const tsProject = ts.createProject('tsconfig.json');
gulp.task('compile-project', () => {
return gulp.src('src/**/*.ts')
.pipe(tsProject())
.pipe(gulp.dest('dist'));
});
// Separate JavaScript and declaration outputs
gulp.task('compile-separate', () => {
const tsResult = gulp.src('src/**/*.ts')
.pipe(tsProject());
return merge([
tsResult.js.pipe(gulp.dest('dist/js')),
tsResult.dts.pipe(gulp.dest('dist/types'))
]);
});Gulp TypeScript is built around several key components:
compilecreateProjectPrimary compilation functionality for transforming TypeScript files into JavaScript with full compiler option support.
function compile(proj: Project, theReporter?: Reporter): CompileStream;
function compile(settings: Settings, theReporter?: Reporter): CompileStream;
function compile(): CompileStream;
function filter(...args: any[]): void;Project creation and management for incremental compilation and configuration reuse.
function createProject(tsConfigFileName: string, settings?: Settings): Project;
function createProject(settings?: Settings): Project;
interface Project {
(reporter?: Reporter): ICompileStream;
src(): NodeJS.ReadWriteStream;
readonly typescript?: typeof ts;
readonly projectDirectory: string;
readonly configFileName: string;
readonly rawConfig: any;
readonly config: TsConfig;
readonly options: ts.CompilerOptions;
readonly projectReferences: ReadonlyArray<ts.ProjectReference> | undefined;
}Comprehensive error reporting system with multiple reporter types for different output formats and integration scenarios.
interface Reporter {
error?: (error: TypeScriptError, typescript: typeof ts) => void;
finish?: (results: CompilationResult) => void;
}
function nullReporter(): Reporter;
function defaultReporter(): Reporter;
function longReporter(): Reporter;
function fullReporter(fullFilename?: boolean): Reporter;Complete TypeScript compiler configuration with gulp-specific extensions and deprecated option handling.
interface Settings {
out?: string;
outFile?: string;
outDir?: string;
allowNonTsExtensions?: boolean;
charset?: string;
codepage?: number;
declaration?: boolean;
locale?: string;
mapRoot?: string;
noEmitOnError?: boolean;
noImplicitAny?: boolean;
noLib?: boolean;
noLibCheck?: boolean;
noResolve?: boolean;
preserveConstEnums?: boolean;
removeComments?: boolean;
suppressImplicitAnyIndexErrors?: boolean;
target?: string | ts.ScriptTarget;
module?: string | ts.ModuleKind;
moduleResolution?: string | number;
jsx?: string | number;
declarationFiles?: boolean;
noExternalResolve?: boolean;
sortOutput?: boolean;
getCustomTransformers?: GetCustomTransformers;
typescript?: typeof ts;
isolatedModules?: boolean;
rootDir?: string;
rootDirs?: any;
lib?: string[];
experimentalDecorators?: boolean;
sourceRoot?: string;
[name: string]: any;
}Gulp stream integration with separate JavaScript and declaration file outputs for flexible build pipeline integration.
interface ICompileStream extends NodeJS.ReadWriteStream {
js: stream.Readable;
dts: stream.Readable;
}type CompileStream = ICompileStream;
interface CompilationResult {
transpileErrors: number;
optionsErrors: number;
syntaxErrors: number;
globalErrors: number;
semanticErrors: number;
declarationErrors: number;
emitErrors: number;
noEmit: boolean;
emitSkipped: boolean;
}
interface TypeScriptError extends Error {
fullFilename?: string;
relativeFilename?: string;
diagnostic: ts.Diagnostic;
startPosition?: {
position: number;
line: number;
character: number;
};
endPosition?: {
position: number;
line: number;
character: number;
};
}
type GetCustomTransformers = string | ((program?: ts.Program) => ts.CustomTransformers | undefined);
interface TsConfig {
files?: string[];
include?: string[];
exclude?: string[];
compilerOptions?: any;
}