/**
 * Created by chendong on 2017/8/3.
 */

var fs = require('fs');
var _ = require('lodash');
var Promise = require('bluebird');
var path = require('path');


function TeldManifestWebpackPlugin() {
}

TeldManifestWebpackPlugin.prototype.apply=function(compiler) {


    compiler.plugin("emit", function(compilation, callback) {

        var basename = "manifest.js"
        var assets = compilation.assets;
        var chunk = compilation.namedChunks["frame"]
        var modules =chunk.modules;
        var cd = "";
        //console.dir(compilation.namedChunks["frame"])
       for(var index in modules){
            var module = modules[index]
           if(module.id=="./teld-router-config.js"){
               cd = module
               break
           }
        }

        //var source = compilation.moduleTemplate.render(cd, compilation.dependencyTemplates, chunk)
        var source = cd.source(compilation.dependencyTemplates, compilation.moduleTemplate.outputOptions, compilation.moduleTemplate.requestShortener);

        var content = source.source();
        compilation.assets[basename] = {
            source: function () {
                return content;
            },
            size:function () {
                return source.size()
            }
        };
        //console.dir(assets)
        callback();
    });



}



module.exports = TeldManifestWebpackPlugin;