I am trying to do gulp compilation and view TypeScript files. This is what I 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 the files every time one of them changes. The above code does this (I can say because watch-typescript takes at least as much time as compile-typescript )
I 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)); });
It really filters out immutable files. But then the TypeScript compiler reports errors, since it receives only one file, in which there are no type declarations, which it usually receives from other files.
I donโt want to set the noExternalResolve flag to true, since then a lot of type checks will not be performed, which first of all affects the reason for using TypeScript.
How can I write this gulpfile better?