gulp-typescript icon indicating copy to clipboard operation
gulp-typescript copied to clipboard

When preprocessing .ts files, in the sourcemap the original file is inlined (and not the processed one)

Open mircolino opened this issue 11 years ago • 2 comments

var gulp = require('gulp');
var tsc  = require('typescript');
var preprocess = require('gulp-preprocess');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');

var prj = {
  src: '/dev/prj/src/main/webapp/',
  dst: '/dev/prj/build/webapp/main/',

  tsFiles: [
    'src/config.ts',
    'src/log.ts',
    'src/main.ts'
  ],

  context: { ... },

  tsProject: null,
  tsConfig: {
    typescript: tsc,
    sortOutput: true,
    module: 'commonjs',
    target: 'ES5',
    declarationFiles: false,
    noExternalResolve: false,
    noImplicitAny: true
  }
};

prj.tsProject = ts.createProject(prj.tsConfig);

gulp.task('transpile', function() {
  gulp.src(prj.tsFiles, {cwd: prj.src, base: prj.src})
    .pipe(preprocess(prj.context))
    .pipe(sourcemaps.init())
    .pipe(ts(prj.tsProject))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(prj.dst));
});

When executing the above gulpfile the processed .ts files are properly transpiled but the resulting .map has inlined the original (unprocessed) .ts source.

mircolino avatar Jun 04 '15 20:06 mircolino

That's just what should happen? Browsers use this to show the original source code (ts) instead of the generated code (js), that's why source-maps were made.

ivogabe avatar Jun 04 '15 21:06 ivogabe

Yes, but the processed/filtered .ts should be inlined in the sourcemap, not the original .ts. The generated .js and the inlined .ts are out of sync and browser debugging becomes impossible.

mircolino avatar Jun 04 '15 21:06 mircolino