ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
839 stars 129 forks source link

Multiple Outfiles, One Task, Incremental Building #601

Closed mikob closed 5 years ago

mikob commented 5 years ago

My project has a bunch of folders with typescript files within them that need to be compiled into one js file per folder. I want to have incremental building, so I've used ts.createProject outside of the task. To accomplish this I'm calling createProject dynamically to create a project per folder, then referring back to those folders in the gulp task.

This seems like a lot of acrobatics to pull something fairly "standard" together. Also, it doesn't work the way I have it setup. Nothing is output, I think because the projects are not getting any file input as it stands currently.

Is there a simple way to do this that I'm overlooking? How do I pass in files to the tsProject like in the 2nd tap function I wrote below?

const gulp = require('gulp');
const ts = require('gulp-typescript');
const tap = require('gulp-tap');

const FOLDER_REGX = /src\/([^\/]*)/;

let projects = {};

gulp.src(['src/*', '!src/@types/**'])
        .pipe(tap(function (file, t) {
            let folderName = FOLDER_REGX.exec(file.path)[1];
            console.log(folderName);
            projects[folderName] = ts.createProject('tsconfig.json', {
                outFile: folderName + '.js'
            });
        }));

gulp.task('default', function(done) {
    return gulp.src(['src/*', '!src/@types/**'])
        .pipe(tap(function (file, t) {
            let folderName = FOLDER_REGX.exec(file.path)[1];
            return projects[folderName](); // executes ts.createProject()()
        }))
        .pipe(gulp.dest('build'))
        .on('end', done);
});
mikob commented 5 years ago

For anyone with a similar issue, I've switched to rollup for this particular use-case, seems to be a better fit for the job. Things are now working as I needed.