How to configure gulp - typescript to create a single javascript file in a typescript file in the same directory?

I would like to use the gulp - typescript module to compile typescript. The current setup I would like to get is to have one javascript file in the typescript file in the same directory. This is what the VS typescript module does.

Unfortunately, I did not find anything like this in the documentation. I also searched this on google, but there is no result.

Thanks for any help in advance!

+4
source share
2 answers

The following will search for each file .tsin the src directory and compile it in the same path as the original

gulp.task('scripts' , function(){
    return gulp.src('src/**/*.ts')
    .pipe(
        ts({
             "compilerOptions": {
                 "target": "es5",
                 "module": "commonjs",
                 "sourceMap": true
             }
        })
    )
    .pipe(gulp.dest(function(file) {
    return file.base;
  }));
});
+5
source

gulp, tsconfig js , ts:

gulp.task('build', 
function() 
{
    var tsProject = ts.createProject('tsconfig.json');

    var tsResult = tsProject.src()
        .pipe(ts(tsProject));

    return tsResult.js.pipe(gulp.dest("./"));
});
+2

All Articles