0

We have an existing Angular 1 project and we want to gradually introduce Angular 2 components and eventually convert to Angular 2. The project was not written using Typescript or a module loader and converting the whole thing would be too much right now. But the Angular 2 components will be written in Typescript and will employ a module loader (SystemJS).

The legacy javascript code is bundled through an existing gulp script. I want to make minimal modifications to that gulp script so that it ignores javascript modules that were compiled from typescript. My idea is to try to exclude .js files that have a corresponding .ts file in the same folder with the same base name. I just can't figure out how to do that in gulp.

1
  • For the Gulp task that compiles the TypeScript, could you just specify a destination that the bundling task won't use? Without specific code, I only have a vague understanding of what your problem is. Commented May 30, 2016 at 7:00

1 Answer 1

1

The following uses fs.statSync to check if the corresponding .ts file exists and gulp-filter to exclude those files were that is the case:

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

var fs = require('fs');

gulp.task('default', function() {
  return gulp.src('src/**/*.js')
    .pipe(filter(function(file) {
      try {
        return !fs.statSync(file.path.replace(/\.js$/, '.ts')).isFile();
      } catch (e) {
        return true;
      }
    }))
    .pipe(gulp.dest('dist'));
});
Sign up to request clarification or add additional context in comments.

1 Comment

Had to add handling for *.css files, but then it worked like a charm. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.