{"id":17345387,"url":"https://github.com/binbiubiubiu/log-webpack-plugin","last_synced_at":"2026-01-19T18:31:18.494Z","repository":{"id":43993644,"uuid":"240161322","full_name":"Binbiubiubiu/log-webpack-plugin","owner":"Binbiubiubiu","description":"a note for study webpack plugin","archived":false,"fork":false,"pushed_at":"2023-01-07T14:47:12.000Z","size":419,"stargazers_count":2,"open_issues_count":10,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-25T15:36:56.516Z","etag":null,"topics":["log","plugin","study-project","webpack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Binbiubiubiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-13T02:35:24.000Z","updated_at":"2023-03-10T08:00:20.000Z","dependencies_parsed_at":"2023-02-07T11:15:39.570Z","dependency_job_id":null,"html_url":"https://github.com/Binbiubiubiu/log-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Binbiubiubiu/log-webpack-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Binbiubiubiu%2Flog-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Binbiubiubiu%2Flog-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Binbiubiubiu%2Flog-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Binbiubiubiu%2Flog-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Binbiubiubiu","download_url":"https://codeload.github.com/Binbiubiubiu/log-webpack-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Binbiubiubiu%2Flog-webpack-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28580149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T18:29:59.827Z","status":"ssl_error","status_checked_at":"2026-01-19T18:29:40.878Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["log","plugin","study-project","webpack"],"created_at":"2024-10-15T16:30:47.455Z","updated_at":"2026-01-19T18:31:18.479Z","avatar_url":"https://github.com/Binbiubiubiu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# log-webpack-plugin\n\n## 知识点\n\n- [compiler](\"https://www.webpackjs.com/api/compiler-hooks/\") Compiler 模块是 webpack 的支柱引擎\n- [compilation](\"https://www.webpackjs.com/api/compilation-hooks/\") Compilation 模块会被 Compiler 用来创建新的编译（或新的构建）\n- [resolver](\"https://www.webpackjs.com/api/resolvers/#%E7%B1%BB%E5%9E%8B\") resolver 是由 enhanced-resolve package 创建出来的。Resolver 类继承了 tapable 类，并且使用 tapable 提供的一些钩子。\n- [parser](\"https://www.webpackjs.com/api/parser/\") parser 实例，是用来解析由 webpack 处理过的每个模块。\n\n### 总结\n\n`webpack plugin` 就是一个 js 的类 通过 `constructor` 传递 `options`\n\n`apply` 会在 `webpack` 执行 `new MyPlugin` 时候 传递 `compiler`\n\n基于`hooks` 每个知识点中提到的内容都提到一系列钩子\n\n```js\ncompiler.hooks.compile.tapAsync(\"LogWebpackPlugin\", function(\n  compilation,\n  callback\n) {\n  // compilation.chunks 存放所有代码块，是一个数组\n  compilation.chunks.forEach(function(chunk) {\n    // chunk 代表一个代码块\n    // 代码块由多个模块组成，通过 chunk.forEachModule 能读取组成代码块的每个模块\n    for (const module of chunk.modulesIterable) {\n      // module 代表一个模块\n      // module.dependencies 存放当前模块的所有依赖的文件路径，是一个数组\n      module.dependencies.forEach(function(filepath) {\n        console.log(filepath);\n      });\n    }\n\n    // Webpack 会根据 Chunk 去生成输出的文件资源，每个 Chunk 都对应一个及其以上的输出文件\n    // 例如在 Chunk 中包含了 CSS 模块并且使用了 ExtractTextPlugin 时，\n    // 该 Chunk 就会生成 .js 和 .css 两个文件\n    chunk.files.forEach(function(filename) {\n      // compilation.assets 存放当前所有即将输出的资源\n      // 调用一个输出资源的 source() 方法能获取到输出资源的内容\n      let source = compilation.assets[filename].source();\n    });\n  });\n\n  // 这是一个异步事件，要记得调用 callback 通知 Webpack 本次事件监听处理结束。\n  // 如果忘记了调用 callback，Webpack 将一直卡在这里而不会往后执行。\n  callback();\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinbiubiubiu%2Flog-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinbiubiubiu%2Flog-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinbiubiubiu%2Flog-webpack-plugin/lists"}