title: Getting browserify to give me sourcemaps when building with gulp
body: <p>I've got a gulpfile (well, a gulpfile.babel.js file) that is building my es6 project into an es5 project.</p>
  
  <p>I'm trying to add sourcemaps to the build process.</p>
  
  <p>I'm doing something wrong below - I'm getting the following error when I run the file...</p>
  
  <pre><code>/Users/chris/src/MyAwesomeProject/node_modules/gulp-sourcemaps/index.js:20
      if (file.isNull() || file.sourceMap) {
               ^
  </code></pre>
  
  <p>I think I'm actually supposed to wrap the 'transform()' call between my 'sourcemaps.init()' and my 'sourcemaps.write()'... but those want to live in the chain of 'pipe()' methods, and those methods don't exist until after I call 'bundle()'...</p>
  
  <p>How can I get this process to spit out sourcemaps?</p>
  
  <pre><code>import {createWriteStream} from "fs";
  import {spawn} from "child_process";
  import gulp from "gulp";
  import browserify from "browserify";
  import browserifyInc from "browserify-incremental";
  import babelify from "babelify";
  import rename from "gulp-rename";
  import runSequence from "run-sequence";
  import sourcemaps from "gulp-sourcemaps";
  import gutil from "gulp-util";
  const debug = process.env.NODE_ENV === "development";
  let cocosWebProcess = null;
  
  gulp.task("babel", () =&gt; {
    const b = browserify("./lib/app.js", Object.assign({
      debug: true,
      paths: ["./node_modules", "./lib"]
    }, browserifyInc.args));
  
    // compile ES6/JSX
    b.transform(babelify.configure({
      ignore: /node_modules/,
      stage: 1
    })).on("error", function(error) {
      console.log(`Babel Error: ${error}`);
      this.emit("end");
    });
  
    // Cache
    browserifyInc(b, {cacheFile: "./.browserify-cache"});
  
    return b
      .bundle()
      .pipe(sourcemaps.init({loadMaps: true}))
      .pipe(sourcemaps.write("./cocos-app/src/"))
      .pipe(createWriteStream("./cocos-app/src/app.js"));
  });
  
  // etc... gulp file does other things after this...
  </code></pre>