var path = require('path'),
    fs = require('fs');

function AssetManifestPlugin(output) {
  this.output = output;
}

AssetManifestPlugin.prototype.apply = function(compiler) {
  var assets = {},
      output  = this.output;

  var outputPath = compiler.options.output.path,
      publicPath = compiler.options.output.publicPath;

  function publicRelative(url) {
    return publicPath + url;
  }

  function keyForModule(module) {
    return Object.keys(module.assets)[0];
  }

  compiler.plugin('compilation', function(compilation) {
    compilation.plugin('module-asset', function(module, file) {
      assets[keyForModule(module)] = publicRelative(file);
    });
  });

  compiler.plugin('done', function() {
    fs.writeFileSync(output, JSON.stringify(assets, null, 2));
  });
};

module.exports = AssetManifestPlugin;

var path = require('path'),
    fs = require('fs');

function AssetManifestPlugin(output, assetRoot) {
  this.output = output;
  this.assetRoot = assetRoot;
}

AssetManifestPlugin.prototype.apply = function(compiler) {
  var assets = {},
      output  = this.output,
      assetRoot = this.assetRoot;

  var publicPath = compiler.options.output.publicPath;

  function publicRelative(url) {
    return publicPath + url;
  }

  function removeAssetRoot(resource) {
    var replaceRoot = new RegExp("^" + assetRoot + "(\/)?");
    return resource.replace(replaceRoot, '');
  }

  function keyForModule(module) {
    return removeAssetRoot(module.resource);
  }

  compiler.plugin('compilation', function(compilation) {
    compilation.plugin('module-asset', function(module, file) {
      assets[keyForModule(module)] = publicRelative(file);
    });
  });

  compiler.plugin('done', function() {
    fs.writeFileSync(output, JSON.stringify(assets, null, 2));
  });
};

module.exports = AssetManifestPlugin;

Fix Asset Keys For Hashed Assets
Fix Asset Keys For Hashed Assets

Resources seems to be a better property to pull in for the key. But we
need to pass the asset root in as configuration to keep only the part we
want for the manifest key.
