Search code examples
javascripttypescriptgulpvisual-studio-2015

How to compile multiple typescript files into one javascript file with Gulp?


I have multiple typescript files I want to compile into one single javascript file. I have the following code so far:

var typescript = require('gulp-typescript');
gulp.task('typescript', function () {
  gulp.src('wwwroot/app/**/*.ts')
    .pipe(typescript({
      out: 'script.js'
    }))
    .pipe(sourcemaps.init())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('wwwroot/app'))      
});

I have searched online on how this is done but couldn't seem to find anything useful. I read that the 'out' option would concatenate and produce output to a single file. Can anyone point me to the right direction? So far the code I have would only create one javascript for every typescript file I have.


Solution

  • Davin is right.

    From the gulp-typescript docs:

    "Concatenate files

    The tsc command has the ability to concatenate using the --out parameter. gulp-typescript doesn't have that, because you should use the gulp-concat plugin for that, or - if you want sourcemaps - gulp-concat-sourcemaps.

    The tsc command sorts the files using the tags. gulp-typescript does this when you enable the sortOutput option. You can use the referencedFrom filter to only include files that are referenced from certain files."