{"size": 1060, "ext": "js", "max_stars_repo_path": "module/webpack-plugin/emit.js", "max_stars_repo_name": "Colorssk/matter", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "module/webpack-plugin/emit.js", "max_issues_repo_name": "Colorssk/matter", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "module/webpack-plugin/emit.js", "max_forks_repo_name": "Colorssk/matter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.6486486486, "max_line_length": 66, "alphanum_fraction": 0.4952830189}
/*
 * @Descripttion: 
 * @version: 
 * @Author: Colorssk
 * @Date: 2019-10-15 11:25:26
 * @LastEditors: Colorssk
 * @LastEditTime: 2019-10-15 11:25:26
 */
class FileListPlugin{
    constructor({filename}){
        this.filename = filename
    }
    apply(compiler){
        // 文件已经准备好了，要准备发射
        //emit
        compiler.hooks.emit.tap('FileListPlugin',(compilcation)=>{
            // compilcation.assets(存放打包之后的资源)
            let assets =compilcation.assets
            let content = `## 文件名      资源大小\r\n`
            // 对象变成数组循环
            //循环数组 [[bundle.js,{}],[index,html,{}]]
            Object.entries(assets).forEach(([filename,statobj])=>{
                content +=`-${filename}    ${statobj.size()}\r\n`
            })
            //资源对象
            assets[this.filename] = {//在打包之后直接创建文件
                source(){// 一个文件由source和size两个方法实现
                    return content
                },
                size(){
                    return content.length
                }
            }
        })
    }
}
module.exports = FileListPlugin