ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
839 stars 129 forks source link

Filter files with supported file extensions #678

Closed stefanpoeter closed 1 year ago

stefanpoeter commented 1 year ago

I'll parse multiple html files in my projects source folder and extract every asset like images, scripts, styles etc. and put them into the stream. The plugin does not seem to filter out files in the stream that are not typescript files. Is there a configuration where a filter can be applied to only compile TypeScript files?

gulp.src('src/**/*')
  .pipe(typescript(someConfiguration))
  .pipe(gulp.dest('dist/'))

Expected behavior:

I'll expect that files are ignored without a file extension supported by typescript. All other files should be compiled to js files.

Actual behavior:

Error Message: The file has an unsupported file extension.

stefanpoeter commented 1 year ago

I've figured out a solution. There is a branch-pipe module and gulp-filter module which lets me create a separate stream branch where I can isolate the typescript files by applying a filter to the stream. The basic idea looks like this:

const branch = require('branch-pipe')
const filter = require('gulp-filter')

gulp.src('src/**/*')
  .pipe(branch(src => [
     src.pipe(filter('*.ts')).pipe(typescript(someConfiguration)),
  ]))
  .pipe(gulp.dest('dist/'))