I'm trying to make gulp compile and watch TypeScript files. This is what I have got so far
var tsProject = plugins.typescript.createProject(
{
removeComments: false,
target: 'ES5',
module: 'amd',
noExternalResolve: false,
noImplicitAny: false,
});
var typescriptGlob = [
presentationScriptsDir + '**/*.ts',
definitelyTypedDefinitions
];
gulp.task("compile-typescript", function () {
return gulp.src(typescriptGlob)
.pipe(plugins.typescript(tsProject))
.pipe(gulp.dest(presentationScriptsDir));
});
gulp.task("watch-typescript", function() {
return gulp.watch(typescriptGlob, ["compile-typescript"]);
});
I am using gulp-typescript.
However, since we have hundreds of TypeScript files I don't want to recompile all files every time one of them changes. The code above does that (I can tell because watch-typescript
takes at least as much time as the compile-typescript
)
I have tried using gulp-changed, like this
gulp.task("compile-typescript", function () {
return gulp.src(typescriptGlob)
.pipe(plugins.changed(presentationScriptsDir, {extension: '.js'}))
.pipe(plugins.typescript(tsProject))
.pipe(gulp.dest(presentationScriptsDir));
});
That indeed filters out unchanged files. But then the typescript compiler reports errors since it only gets a single file, which lacks type declarations that it normally gets from other files.
I do not want to set the noExternalResolve
flag to true, since then a lot of type checking will not be done, which defeats a lot of the reason for using TypeScript in the first place.
How can I write this gulpfile better?