如何让 gulp-typescript 输出到与源文件相同的目录?

How can I get gulp-typescript to output to the same directory as the source file?

我有以下管道

  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));
  }

我似乎必须根据 src 路径的根使 "hard code" 成为目标路径。如果我的源路径是 app/modules/**.ts,我的目标路径必须是 app/modules。这限制了我使用单个根 src 路径,我不能使用兄弟姐妹。

我希望能够制作我的 src ['path1/**/*.ts', 'path2/**/*.ts] 并将转译后的输出写入源文件所在的同一文件夹。

如果您有这样的源文件:

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

比等于:

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

这意味着,您可以将目的地设为:

gulp.dest('.')

因为这是最小公分母。剩下的由 Gulp.

完成