0

I am trying to get Gulp to transpile my .ts files in my /dev directory and move the transpiled .js file to a /build directory.

The desired structure is as follows:

/dev
 - index.ts
/build
 - index.js

What is actually occuring looks like this:

/dev
 - index.ts
/build
 - /dev
    - index.js

As you can see the dev folder is being duplicated. The relevant code in gulpfile.js is as follows:

var gulp = require('gulp');
var ts = require('gulp-typescript');
var tsProject = ts.createProject('./tsconfig.json');

// gulp ts
gulp.task('ts', function () {
  return tsProject.src('dev/**/*.ts')
    .pipe(ts(tsProject))
    .pipe(gulp.dest('build/'));
});

I can get my other build tasks to behave in the desired manner but for whatever reason the TypeScript task is giving me grief.

murtrex
  • 31
  • 6
  • Possible duplicate of [Can you remove a folder structure when copying files in gulp?](http://stackoverflow.com/questions/24658011/can-you-remove-a-folder-structure-when-copying-files-in-gulp) – dotnetom Feb 04 '16 at 05:31
  • I do not want to flatten or remove the folder structure but rather maintain it. I want `dev` and `build` to share the same structure. – murtrex Feb 04 '16 at 05:36
  • I believe you can use gulp.dest callback to modify the file path: http://stackoverflow.com/a/33743973/99256 (i.e. `.pipe(gulp.dest(function(file) {);)` – MartyIX Feb 04 '16 at 05:53
  • @Vizkos I have tried that with the same results. The `.pipe(ts(tsProject))` line is doing something under the hood that I cannot figure out. Commenting out that line maintains the desired structure but obviously does not transpile my files. – murtrex Feb 04 '16 at 06:21

1 Answers1

1

I solved my problem. Adding "rootDir": "dev" to the compilerOptions in tsconfig.json made the gulp task behave as expected.

An unexpected side-effect also occurred and the TypeScript compiler started throwing errors stating that it could not find modules that it previously had no problem finding before. I explicitly added /// <reference path="../typings/tsd.d.ts" /> to my .ts files and was back in business.

murtrex
  • 31
  • 6