Closed wayneseymour closed 9 years ago
The names array?
cc @floridoo
My apologies @contra The names array in the sourcemap object literal.
I'm seeing the same thing (without gulp-rev
in play). Where the fault lies, who knows; there seem to be a lot of source map-related issues and bad interactions going on between gulp plugins right now. And further complicating matters, the names
feature doesn't even seem to be working for me in Chrome.
A task like this produces source map output like this:
gulp.task('default', function () {
return gulp
.src(['./src/script.js'])
.pipe(sourcemaps.init())
.pipe(concat('script.js'))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
});
{"version":3,"sources":["script.js"],"names":[],"mappings":"CAAA,SAAA,GAAA,QAAA,IAAA,IAAA","file":"script.js","sourcesContent":["(function (x) { console.log(x); })(\"x\");\n"],"sourceRoot":"/source/"}
While a task like this produces source map output like this:
gulp.task('default', function () {
return gulp
.src(['./src/script.js'])
.pipe(sourcemaps.init())
// .pipe(concat('script.js'))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
});
{"version":3,"sources":["?"],"names":["x","console","log"],"mappings":"CAAA,SAAWA,GAAKC,QAAQC,IAAIF,IAAO","file":"script.js","sourcesContent":[null],"sourceRoot":"/source/"}
cc @floridoo
Yeah, there are a lot of problems with gulp-sourcemaps right now. It seems to be extremely fragile and plugins need to be very careful to pass the perfect data into it.
@floridoo Is there any way we can throw errors on missing data, or try to be more lenient on input data to prevent these problems from happening? For example, less updated so gulp-less updated to the new version. sourcemaps broke because the sourcemap less was giving back needed to be massaged to work with the apply sourcemaps stuff, but this was only found out after users reported it was broken.
This seems to work now.
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
gulp.task('default', function () {
return gulp.src(['src/script.js'])
.pipe(sourcemaps.init())
.pipe(concat('script.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
package.json
{
"dependencies": {
"gulp": "^3.8.11",
"gulp-concat": "^2.5.0",
"gulp-sourcemaps": "^1.3.0",
"gulp-uglify": "^1.1.0"
}
}
dist/script.js
function foo(o,n){console.log(o,n)}
//# sourceMappingURL=script.js.map
dist/script.js.map
{"version":3,"sources":["script.js"],"names":["foo","bar","baz","console","log"],"mappings":"AAAA,QAAAA,KAAAC,EAAAC,GACAC,QAAAC,IAAAH,EAAAC","file":"script.js","sourcesContent":["function foo(bar, baz) {\n\tconsole.log(bar, baz);\n}\n"],"sourceRoot":"/source/"}
What I'm experiencing
I was working through this issue and noticed that when I use
gulp-concat
, thenames
array is always empty.This is true even during trivial cases (one file being source-mapped). @floridoo mentioned it was probably
gulp-rev
causing my issue, but so far that's not what I've found.btw, thanks to @floridoo for responding expediently.
Snippet
My true intention
I want to un-minify the source maps (due to an exception being thrown) at runtime.
so far using mozilla source-map I can still get the line number and column, but not the name.