var _ = require('lodash')

/**
 * Create a new StatsPlugin that causes webpack to generate a stats file as
 * part of the emitted assets.
 * @constructor
 * @param {String} output Path to output file.
 * @param {Object} options Options passed to the stats' `.toJson()`.
 */
function StatsPlugin (output, options, cache) {
  this.output = output
  this.options = options
  this.cache = cache || {}
}

StatsPlugin.prototype.apply = function apply (compiler) {
  var output = this.output
  var options = this.options
  var cache = this.cache

  compiler.plugin('emit', function onEmit (compilation, done) {
    var result

    compilation.assets[output] = {
      size: function getSize () {
        return result && result.length || 0
      },
      source: function getSource () {
        var stats = compilation.getStats().toJson(options)
        cache = _.merge(cache, stats)
        result = JSON.stringify(cache)
        return result
      }
    }
    done()
  })
}

module.exports = StatsPlugin

@@ -267,16 +267,17 @@
 )%60.%0A */%0A
+%0A
 function
@@ -388,14 +388,8 @@
 ache
- %7C%7C %7B%7D
 %0A%7D%0A%0A
@@ -827,16 +827,59 @@
 ptions)%0A
+        var result%0A%0A        if (cache) %7B%0A  
         
@@ -916,16 +916,18 @@
         
+  
 result =
@@ -949,16 +949,84 @@
 (cache)%0A
+        %7D else %7B%0A          result = JSON.stringify(stats)%0A        %7D%0A
         

Disable default caching