10

I have the following pipeline

  function typescripts() {
    return gulp.src(paths.watchedFiles.ts)
        .pipe(cached('typescripts'))
        .pipe(plumber())
        .pipe(addsrc(paths.ts.include))
      //TODO: Need to eliminate the original source path (ex. /users/userName) from the sourcemap file.
        .pipe(sourcemaps.init())
        .pipe(ts(tsProjectMode, undefined, ts.reporter.fullReporter(true))).js
        .pipe(gulpIgnore.exclude(paths.ts.excludeFromPostCompilePipeline))
        .pipe(ngAnnotate({
          remove: false,
          add: true,
          gulpWarnings: false //typescript removes base path for some reason.  Warnings result that we don't want to see.
        }))
        .pipe(sourcemaps.write('.', {includeContent: false}))
        .pipe(gulp.dest(paths.ts.basePath));
  }

I seem to have to make "hard code" the dest path based on the root of the src path. If my src path is app/modules/**.ts my dest path must be app/modules. This limits me to using a single root src path and I cannot use siblings.

I would like to be able to make my src ['path1/**/*.ts', 'path2/**/*.ts] and have the transpiled output written to the same folder where the source file was located.

TianCNCA
  • 3
  • 2
Richard Collette
  • 5,462
  • 4
  • 53
  • 79

1 Answers1

6

If you have source files like that:

gulp.src(['path1/**/*.ts', 'path2/**/*.ts])

Than it's equal to that:

gulp.src(['./path1/**/*.ts', './path2/**/*.ts], { base: '.' })

Which means, you can put your destination to:

gulp.dest('.')

since that's the lowest common denominator. The rest is done by Gulp.

Shahzad
  • 473
  • 1
  • 5
  • 12
ddprrt
  • 7,424
  • 3
  • 29
  • 25
  • 17
    For me this configuration results in output files placed into the root directory. I had to add `base` option to get desired result: `gulp.src(paths.ts, { base: "." })` – Dark Daskin Jul 21 '15 at 19:03
  • @DarkDaskin I wish I had read this comment beforehand. Now I have 100 files to clean up from my root... this solution was needed for me too. On another note, you should make this a separate answer. – Matt Lishman Jul 08 '16 at 14:05