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?

3
  • Possible duplicate of Typescript compile to single file Commented Jan 6, 2016 at 13:23
  • you will probably have to let tsc do the concatenation instead of doing it in gulp. Commented Jan 6, 2016 at 13:24
  • But can tsc take javascript files as input? Commented Jan 7, 2016 at 13:41

0

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.