Gulp - typescript and outFile option in tsconfig.json

I am using gulpfile.js to compile my tsconfig.json project as follows:

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 fine and compiles my typescript files and puts js files in wwwroot / app folder

The problem arises, then I want the typescript compiler to output one concatenated file using the 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 creates an empty output file and creates * .js files with contents next to * .ts files.

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

+4
source share
3 answers

Don't have external modules in TypeScript sources?

. outFile, . , "-" ( outDir).

plain tsc -p . , gulp-typescript?

+7

gulp-concat . Gulp, , Gulp.

var concat = require('gulp-concat');

gulp.task('scripts', function() {
  return gulp.src('./lib/*.js')
    .pipe(concat('all.js'))
    .pipe(gulp.dest('./dist/'));
});
+3

, --outDir TypeScript. . https://github.com/Microsoft/TypeScript/wiki/Compiler-Options , , gulp - typescript , :

outDir (string) - transferring output to another (virtual) directory. Note that you still need gulp.dest to write the output to disk.

+1
source

Source: https://habr.com/ru/post/1612111/


All Articles