How to set up gulp-typescript to generate one javascript file per typescript file into the same directory?
Asked Answered
T

2

5

I would like to use gulp-typescript module to take care typescript compiling. The current setup I would like to achieve is having one javascript file per typescript file in the same directory. It is the same what VS Typescript module does.

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

Thanks for any help in advance!

Templetempler answered 27/3, 2016 at 12:40 Comment(0)
E
7

The following will look for each .ts file in src directory and compile it in the same path as the source

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;
  }));
});
Eliza answered 27/3, 2016 at 13:29 Comment(0)
F
2

Below is sample gulp task that will compile your program in accordance with tsconfig and put js files in the same folder as ts ones:

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

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

    return tsResult.js.pipe(gulp.dest("./"));
});
Foresee answered 27/3, 2016 at 13:26 Comment(1)
var ts = require('gulp-typescript');Agriculture

© 2022 - 2024 — McMap. All rights reserved.