Reputation: 8784
I want to include typescript in my main gulp tool chain, so that I can convert .js files to .ts files as-needed and as time permits. It's fine if the typescript step performs no action on .js files.
Does that make sense? If so, how can I accomplish this? I tried the following:
function compileScript(inputFiles, outputName, outputPath) {
return r.gulp.src(inputFiles)
.pipe(r.sourcemaps.init())
.pipe(r.ngAnnotate())
// I'd like to do this, but processing fails if not all files are *.ts
// .pipe(r.typescript({ target: 'ES5' }))
.pipe(r.uglify())
.pipe(r.concat(outputName))
.pipe(r.sourcemaps.write('.'))
.pipe(r.gulp.dest(outputPath));
}
But it produces no output, citing:
ERROR 6054: File 'script.js' must have extension '.ts' or '.d.ts'.
Perhaps there is a typescript option that I've overlooked, or a gulp conditional pipe tool that won't break my sourcemaps? If I run two separate steps of .ts and .js files, they will end up concatenated out-of-order.
I'd like to avoid a big-bang approach.
p.s. I'm building an ASP.NET project in Visual Studio.
Upvotes: 0
Views: 583
Reputation: 7004
It seems that you're currently providing full list of files to gulp-typescript
, filter out only *.ts
ones using gulp-filter
:
function compileScript(inputFiles, outputName, outputPath) {
var filter = require('gulp-filter')('**/*.ts'); // setup filter
return r.gulp.src(inputFiles)
.pipe(r.sourcemaps.init())
.pipe(filter) // filter out *.ts files
.pipe(r.typescript({ target: 'ES5' })) // compile them
.pipe(filter.restore()) // restore all other files to proceed
.pipe(r.ngAnnotate())
.pipe(r.uglify())
.pipe(r.concat(outputName))
.pipe(r.sourcemaps.write('.'))
.pipe(r.gulp.dest(outputPath));
}
As a side note, I think you should first compile *.ts
files and only after that ng-annotate
them.
Upvotes: 1