I'm new to gulp and have run into a problem which probably is a pretty common scenario. What I'm trying todo is compiling typescript into javascript, creating a sourcemap for it and then running uglify. I would like to have a sourcemap for the ugliyfied as well as the non uglified js.
What I'm trying to achive is the following file structure:
framework.js
framework.js.map < this won't work
framework.min.js
framework.min.js.map
This is my gulp task:
var gulp = require('gulp'),
uglify = require('gulp-uglify')
ts = require("gulp-typescript")
sourcemaps = require('gulp-sourcemaps')
rename = require('gulp-rename');
var tsProject = ts.createProject("tsconfig.json");
gulp.task('typescript', function(){
tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject()).js
.pipe(sourcemaps.write('.')) // Write sourcemap for non-minified version
.pipe(gulp.dest("dist"))
.pipe(uglify()) // Code will fail here
.pipe(rename({suffix:'.min'}))
.pipe(sourcemaps.write('.')) // Write sourcemap for minified version.
.pipe(gulp.dest("dist"));
});
gulp.task('default', ['typescript']);
As you can see, I'm running sourcemaps.write() twice to get the two different files. This gives me an error
tream.js:74
throw er; // Unhandled stream error in pipe.
^ GulpUglifyError: unable to minify JavaScript
at createError (C:\Users\alexa\Dropbox\code\Web\mhadmin\framework\node_modules\gulp-uglify\lib\create-error.js:6:14)
Leaving out the first one of the sourcemap.write() calls will result in a correct sourcemap for the minified version of the file.
Any ideas how to fix this?
EDIT: This is not exactly a duplicate of gulp: uglify and sourcemaps as I need to write multiple sourcemaps with multiple calls to gulp.dest()