Ghost source file in generated sourcemap
var gulp = require('gulp');
var tsc = require('typescript');
var concat = require('gulp-concat');
var minify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var prj = {
src: '/dev/prj/src/main/webapp/',
dst: '/dev/prj/build/webapp/main/',
min: 'src/bundle.min.js',
tsFiles: [
'src/config.ts',
'src/log.ts',
'src/main.ts'
],
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(sourcemaps.init())
.pipe(ts(prj.tsProject))
.pipe(concat(prj.min))
.pipe(minify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(prj.dst));
});
When executing the above gulpfile the generated 'bundle.min.js.map' sourcemap contains the following:
"sources":["src/config.ts","src/log.ts","src/main.ts","src/bundle.min.js"]
"file":"src/bundle.min.js"
'bundle.min.js' is in the list of sources but its source code is not inlined in the sourcemap, resulting in a ghost 'bundle.min.js' source file when debugging in Chrome.
After manually removing "src/bundle.min.js" from the "sources" array in the sourcemap, Chrome JavaScript console works as expected.
I can't reproduce that, are you using the latest versions of these plugins? Also I think it has nothing to do with gulp-typescript, since gulp-typescript doesn't know about src/bundle.min.js, it could only be added by gulp-concat, gulp-uglify or gulp-sourcemaps.
Yes, as far as I can tell I'm using the latest versions of all the plugins:
"devDependencies": {
"gulp": "^3.9.0",
"gulp-concat": "^2.5.2",
"gulp-sourcemaps": "^1.5.2",
"gulp-typescript": "^2.7.6",
"gulp-uglify": "^1.2.0",
"typescript": "^1.5.0-beta",
}
I'm really confused who's adding the empty 'bundle.min.js' to the sourcemap. I tried the following, removing typescript and reusing .js generated by a previous transpilation:
var gulp = require('gulp');
var concat = require('gulp-concat');
var minify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var prj = {
src: '/dev/prj/src/main/webapp/',
dst: '/dev/prj/build/webapp/main/',
min: 'src/bundle.min.js',
jsFiles: [
'src/config.js',
'src/log.js',
'src/main.js'
]
};
gulp.task('testmap', function() {
gulp.src(prj.jsFiles, {cwd: prj.src, base: prj.src})
.pipe(sourcemaps.init())
.pipe(concat(prj.min))
.pipe(minify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(prj.dst));
});
and the sourcemap is generated correctly, with all the sources properly inlined:
"sources":["src/config.js","src/log.js","src/laundry.js"]
"file":"src/bundle.min.js"
I still cannot reproduce it. Maybe you can try using relative paths instead of absolute paths, as the paths in your example look to be wrong.
Also, you're using gulp-concat and module: 'commonjs', you can't use these two combined. You should use something like browserify instead.
the absolute paths are actually OK, and everything works as expected if I comment the line
.pipe(minify())
but of course nothing gets minified then. Apologies for opening the issue in the wrong place. I'll repost it over to gulp-uglify.