gulp-usemin
gulp-usemin copied to clipboard
usemin + sourcemaps generates maps with empty names and mappings
I am facing some problems generating sourcemaps using usemin. I am using the latest versions of the plugins. Here there is my task, which is very simple:
var gulp = require('gulp'); //"3.5.6"
var usemin = require('gulp-usemin'); //"0.3.8"
var uglify = require('gulp-uglify'); //"0.2.1"
var rev = require('gulp-rev'); //"0.2.1"
var sourcemaps = require('gulp-sourcemaps'); //"1.2.8"
gulp.task('default', function() {
gulp.src('*.php')
.pipe(usemin({
js: [sourcemaps.init(), uglify(), rev(), sourcemaps.write('.')]
}))
.pipe(gulp.dest('dist/'));
});
And here there is the output, a map without the mappings and names. userfile-652284cb.js.map
{"version":3,"file":"js/userfile-652284cb.js","names":[],"mappings":"","sources":["js/userfile.js"]}
What am I doing wrong?
Try:
gulp.task('default', function() {
gulp.src('*.php')
.pipe(usemin({
js: [sourcemaps.init(), 'concat', uglify(), rev(), sourcemaps.write('.')]
}))
.pipe(gulp.dest('dist/'));
});
I got hung up on this for a long time too. Eventually it hit me and I finally noticed this small tidbit in the docs:
If exist used for modify files. If does not contain string 'concat', then it added as first member of pipeline
The apparent issue that @joanscript and I were struggling with is a misunderstanding of the default behaviour of usemin, which is to concat the source files before running the pipeline plugins (i.e.: generating sourcemaps). The result is a sourcemap of the resulting concatenated file - not as useful :).
@zont While I think this can be closed, better highlighting of the default behaviour would help steer people away from this sinkhole. Would you take a pull on the readme?