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

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

我似乎必须根据 src 路径的根来“硬编码” dest 路径。如果我的 src 路径是 app/modules/**.ts 我的 dest 路径必须是 app/modules。这限制了我使用单个根 src 路径,我不能使用同级。

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

最佳答案

如果你有这样的源文件:

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

比它等于:

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

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

gulp.dest('.')

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

关于typescript - 如何让 gulp-typescript 输出到与源文件相同的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29505055/

相关文章:

javascript - 使 gulpfile : getting an error when call gulp. 并行

javascript - 使用 gulp.watch 会抛出 "TypeError: Object #<Object> has no method ' watch'"

javascript如何动态地将子字典附加到父字典

typescript - 如何为 TypeScript 中类的所有属性赋值?

typescript - 转到定义在 VS Code 版本 1.47.2 中不起作用

node.js - 队列消费者中的 Nestjs Shell 命令

typescript - Angular 2 HTTP "Cannot resolve all parameters for ' AppService'”

javascript - 包含带有 css/js 的前端 npm 包的最佳实践?

jquery - Gulp 不注入(inject) jquery ui 主题 css

gulp - 使用文件目录的父目录作为 gulp 中的目标