gulp-typescript is a Gulp plugin designed for integrating TypeScript compilation into Gulp build workflows, offering features like incremental compilation and project reference support. The package is currently in an active development phase, with v5.0.1 being the latest stable release and v6.0.0-alpha.1 actively being developed. New releases, including alphas and minor fixes, are frequent. It serves as a key tool for developers who leverage Gulp for task automation and need to compile TypeScript, providing a direct interface to TypeScript's compiler options and supporting `tsconfig.json` configurations. Its main differentiators include tight integration with Gulp's streaming API, efficient incremental compilation, and support for advanced TypeScript features like custom transformers introduced in v5.
npm install gulp-typescriptVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to compile TypeScript files using `gulp-typescript` with sourcemaps and `tsconfig.json` support, outputting both JavaScript and declaration files. It also includes a basic watch task for development.
Ensure your project's `gulp` dependency is `^4.0.0` or higher. Upgrade your `gulpfile.js` syntax to Gulp 4 API if necessary.
Handle errors appropriately within your Gulp task, for example, by using `gulp-plumber` to prevent the stream from stopping on errors in watch mode, or by ensuring your TypeScript code is error-free for non-watch builds.
Pipe your TypeScript stream through `gulp-sourcemaps.init()` before `tsProject()` and `gulp-sourcemaps.write()` after the `.js` stream. Example provided in the quickstart.
Remove the `watch` option from your `tsconfig.json` or `ts.createProject` options. Implement file watching using `gulp.watch` to trigger compilation tasks.
For production, prefer the latest stable v5.x release. If using v6 alpha, closely monitor release notes for breaking changes and update dependencies as advised.
After piping through `tsProject()`, append `.js.pipe(gulp.dest('output'))` for JavaScript and `.dts.pipe(gulp.dest('output'))` for declaration files to ensure both are written to disk.Ensure `ts.createProject()` is called to create the project instance, e.g., `const tsProject = ts.createProject('tsconfig.json');`, and then use `tsProject()` as the gulp plugin, e.g., `gulp.src('src/**/*.ts').pipe(tsProject()).js.pipe(...)`.Verify that your `gulp.src()` glob pattern only selects TypeScript source files (`.ts`, `.tsx`). If you intend to compile JavaScript files, ensure `allowJs: true` is set in your `tsconfig.json` or `createProject` options.
Correct the TypeScript code identified by the error message. For development and watch mode, consider using `gulp-plumber` before the `tsProject()` pipe to prevent the stream from stopping on errors, allowing continuous watch and reporting.
Either ensure `gulp.src` only selects `.ts` or `.tsx` files, or enable the `allowJs` option in your `tsconfig.json` or `ts.createProject` configuration if you intend to process JavaScript files.