2

I'm trying to compile typescript files and concatenate the output with some other existing javascript files.

I'm using gulp-sourcemaps with the load maps option set to true. Unfortunately the source map for the concatenated file contains wong paths to the TypeScript files. The paths for the Javascript files are correct.

I have the following files, that must be bundled in the given order:

/source/firstDir/jsFile.js
/source/someDir/tsFile.ts
/source/someDir/jsFile.js
/source/someOtherDir/tsFile.ts
/source/anotherDir/jsFile.js

In the first step I compile the TypeScript files with sourcemaps using something like this:

gulp.src('/source/**/*.ts')
  .pipe(sourcemaps.init())
  .pipe(ts({
    target: 'ES5'
  }))
  .pipe(sourcemaps.write())
  .pipe(gulp.dest(scriptBaseDir));

Afterwards, I have the following files:

/source/firstDir/jsFile.js
/source/someDir/tsFile.js  <-- compiled
/source/someDir/jsFile.js
/source/someOtherDir/tsFile.js <-- compiled
/source/anotherDir/jsFile.js

These files are then concatenated by performing:

gulp.src(['files', 'in', 'correct', 'order'])
  .pipe(sourcemaps.init({ loadMaps: true }))
  .pipe(concat('bundle.js'))
  .pipe(sourcemaps.write('../maps'))
  .pipe(gulp.dest('/dest'));

The generated sourcemap is not valid. The paths to the original TypeScript files isn't correct. How do I get a valid source map when I need to concatenate both TypeScript files and JavaScipt files in a given order?

torjue
  • 83
  • 1
  • 6

0 Answers0