gulp-typescript and outFile option in tsconfig.json

Rem picture Rem · Oct 18, 2015 · Viewed 8.3k times · Source

I'm using gulpfile.js to compile my tsconfig.json project this way:

var ts = require('gulp-typescript');

var tsProject = ts.createProject('Modeler/tsconfig.json',
    { typescript: require('typescript') });

gulp.task('build:ts', function () {
    var tsResult = tsProject.src()
        .pipe(ts(tsProject));
    return tsResult.pipe(gulp.dest('wwwroot/app'));
});

It works ok and compiles my typescript files and put js files into wwwroot/app folder

The problem arises then I want TypeScript compiler to output single concatenated file using outFile property

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "outFile": "modeler.js"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]  
}

The gulp task does create an empty output file and creates *.js files with content next to *.ts files.

What should I fix to create desired output file without polluting my source folders?

Answer

ahz picture ahz · Oct 18, 2015

Are you sure you don't have external modules in your TypeScript sources?

I've encountered similar behavior in that case. External modules are not allowed when using outFile option, but compiler does not complain and emits empty file. Additionally external modules should be emitted "somewhere" (in outDir).

If the problem is not about external modules using plain tsc -p . behaves the same way as using gulp-typescript?