title: How to save Gulp bundle in the source directory?
body: <p>I am following the <a href="https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md" rel="nofollow">Fast browserify builds with watchify recipe</a> and get it working, but would like my bundles to be written to the original source folder.</p>
  
  <p>For example, I have the following code (taken directly from the recipe, but modified slightly)</p>
  
  <pre><code>// add custom browserify options here
  var customOpts = {
      entries: glob.sync("./dev/www/**/*-root.js"),
      debug: true
  };
  var opts = _.assign({}, watchify.args, customOpts);
  var b = watchify(browserify(opts)); 
  
  
  
  gulp.task('js', bundle); // so you can run `gulp js` to build the file
  b.on('update', bundle); // on any dep update, runs the bundler
  b.on('log', gutil.log); // output build logs to terminal
  
  
  function bundle() {
      return b.bundle()
      // log errors if they happen
          .on('error', gutil.log.bind(gutil, 'Browserify Error'))
          .pipe(source('bundle.js'))
      // optional, remove if you don't need to buffer file contents
          .pipe(buffer())
      // optional, remove if you dont want sourcemaps
          .pipe(sourcemaps.init({ loadMaps: true })) // loads map from browserify file
      // Add transformation tasks to the pipeline here.
          .pipe(sourcemaps.write('./')) // writes .map file
          .pipe(gulp.dest((file) =&gt; {return file.base;}));
          //.pipe(gulp.dest('./dist'));
  }
  </code></pre>
  
  <p>as you can see in the <code>entries: glob.sync("./dev/www/**/*-root.js"),</code> line, I am scanning for multiple files to be bundled.</p>
  
  <p>The problem I am encountering is the <code>.pipe(gulp.dest((_file: any) =&gt; {return file.base;}));</code> line, which returns the root project folder's path, not the original source folder's path.</p>
  
  <p>How can I obtain the source folder path for writing to?</p>
  
  <h3>Edit</h3>
  
  <p>I found <a href="http://fettblog.eu/gulp-browserify-multiple-bundles/" rel="nofollow">http://fettblog.eu/gulp-browserify-multiple-bundles/</a>  which describes how to create multiple bundles, but it doesn't use watchify.   it looks like this issue might be a limitation of vinyl-source-stream?</p>