title: Gulp: Generate sourcemaps for both minified and non-minified scripts
body: <p>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.</p>
  
  <p>What I'm trying to achive is the following file structure:</p>
  
  <pre><code>framework.js
  framework.js.map &lt; this won't work
  framework.min.js
  framework.min.js.map
  </code></pre>
  
  <p>This is my gulp task:</p>
  
  <pre><code>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']);
  </code></pre>
  
  <p>As you can see, I'm running sourcemaps.write() twice to get the two different files. This gives me an error</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Leaving out the first one of the sourcemap.write() calls will result in a correct sourcemap for the minified version of the file.</p>
  
  <p>Any ideas how to fix this?</p>
  
  <p>EDIT: This is not exactly a duplicate of <a href="https://stackoverflow.com/questions/32502678/gulp-uglify-and-sourcemaps">gulp: uglify and sourcemaps</a> as I need to write multiple sourcemaps with multiple calls to gulp.dest()</p>