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

Ric*_*tte 10 typescript gulp

我有以下管道

  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));
  }
Run Code Online (Sandbox Code Playgroud)

我似乎必须根据src路径的根目录制作"硬代码"的dest路径.如果我的src路径是app/modules/**.ts我的dest路径必须app/modules.这限制了我使用单个根src路径,我不能使用兄弟姐妹.

我希望能够创建我的src ['path1/**/*.ts', 'path2/**/*.ts]并将已转换的输出写入源文件所在的同一文件夹.

ddp*_*rrt 6

如果你有这样的源文件:

gulp.src(['path1/**/*.ts', 'path2/**/*.ts])
Run Code Online (Sandbox Code Playgroud)

比它更接近:

gulp.src(['./path1/**/*.ts', './path2/**/*.ts], { base: '.' })
Run Code Online (Sandbox Code Playgroud)

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

gulp.dest('.')
Run Code Online (Sandbox Code Playgroud)

因为那是最低的共同点.其余的由Gulp完成.

  • 对我来说,这种配置会导致输出文件放入根目录.我不得不添加`base`选项来获得所需的结果:`gulp.src(paths.ts,{base:"."})` (17认同)