{"id":13671318,"url":"https://github.com/alienzhou/webpack-internal-plugin-relation","last_synced_at":"2025-05-06T13:32:08.047Z","repository":{"id":107436620,"uuid":"150125958","full_name":"alienzhou/webpack-internal-plugin-relation","owner":"alienzhou","description":"🔎 a tiny tool to show the relation of webpack internal plugins \u0026 hooks","archived":false,"fork":false,"pushed_at":"2019-06-04T02:36:50.000Z","size":27631,"stargazers_count":156,"open_issues_count":0,"forks_count":22,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-03T09:09:20.967Z","etag":null,"topics":["hook","plugin","relation","visualization","webpack","webpack4"],"latest_commit_sha":null,"homepage":"https://alienzhou.com/projects/webpack-internal-plugin-relation/","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/alienzhou.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-09-24T15:35:46.000Z","updated_at":"2024-04-03T17:20:44.000Z","dependencies_parsed_at":"2023-06-12T18:00:48.096Z","dependency_job_id":null,"html_url":"https://github.com/alienzhou/webpack-internal-plugin-relation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alienzhou%2Fwebpack-internal-plugin-relation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alienzhou%2Fwebpack-internal-plugin-relation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alienzhou%2Fwebpack-internal-plugin-relation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alienzhou%2Fwebpack-internal-plugin-relation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alienzhou","download_url":"https://codeload.github.com/alienzhou/webpack-internal-plugin-relation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224079324,"owners_count":17252267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["hook","plugin","relation","visualization","webpack","webpack4"],"created_at":"2024-08-02T09:01:06.017Z","updated_at":"2024-11-11T09:30:21.654Z","avatar_url":"https://github.com/alienzhou.png","language":"JavaScript","readme":"# webpack-internal-plugin-relation\n\n\u003e 目前支持 webpack v4+\n\n## 介绍\n\n一个用来展示webpack内置插件调用关系（钩子）的小工具。\n\n[https://alienzhou.github.io/webpack-internal-plugin-relation](https://alienzhou.github.io/webpack-internal-plugin-relation)\n\n也许可以用来帮助理清webpack内部插件之间的关系，促进webpack源码结构的理解与阅读。\n\n![](./doc/img/sample.png)\n\n## 起因\n\n- webpack使用tapable的钩子虽然能有效解耦，但是类似事件监听这种模式，其注册与调用几乎完全无关，很难将一个钩子的创建 - 注册 - 调用有效联系起来。对此，往往只能使用关键词搜索。\n\n- webpack内部的钩子非常多，数量达到了180+。除了官网列出的`compiler`与`compilation`中那些常用的钩子，还存在着众多其他可以使用的钩子。有些挺有用的钩子你可能都无从知晓。\n\n- webpack v4+ 本身内置了许多插件，即使非插件，webpack的模块也经常使用tapable钩子来交互。甚至你可以认为，webpack项目中的各个模块都是“插件化”的。这也使得模块间的调用与方法的触发关系更加不明确了。\n\n这些主要导致了，想要全局细致了解webpack中模块（插件）、钩子之间的关系具有一定的困难。为了帮助理解与阅读webpack源码，我制作了一个工具应用，来进行可视化展示，并支持一些交互操作。\n\n## 演示\n\n**关系展示：**\n\n![](./doc/img/1.gif)\n\n**点击交互，展示模块信息，跳转到相应源码位置：**\n\n![](./doc/img/2.gif)\n\n**筛选关系类型进行展示：**\n\n![](./doc/img/3.gif)\n\n## 功能\n\n- 收集webpack内部插件中钩子的创建、注册、调用关系，并生成原始数据\n- 力导向图可视化展示插件、钩子间关系\n- 支持力导向图节点的选择\n- 单击javascript module类节点，可在左下角展示详细信息\n- 双击javascript module类节点，可直接打开webpack对应源码查看\n- 双击节点间关系，可直接打开并定位源码具体行数，进行查看\n- ……\n\n## 使用\n\n你可以直接启动查看应用效果，或者只是生成所需的关系数据，或者构建应用并托管在自己的网站……\n\n### 启动服务预览\n\n```bash\n# 拷贝代码库\ngit clone git@github.com:alienzhou/webpack-internal-plugin-relation.git\ncd webpack-internal-plugin-relation\n\n# 安装依赖\nnpm i\n\n# 启动服务\nnpm start\n```\n\n![](./doc/img/start.png)\n\n启动完成后可以在 `127.0.0.1:8085` 上看到服务\n\n### 生成plugin与hook相关数据\n\n如果不想使用力导向图功能，只是需要plugin、hook之间的关系数据，可以\n\n```bash\nnpm run data\n```\n\n生成的数据在 `config/` 目录下：\n\n- hook.json: plugin与hook收集的原始数据\n- forceData.json: 整理合并的力导向图数据\n\n![](./doc/img/datapath.png)\n\n`hook.json`数据格式如下：\n\n```json\n\"lib/MultiCompiler.js\": {\n  \"hooks\": [\n    {\n      \"name\": \"done\",\n      \"line\": 17\n    },\n    {\n      \"name\": \"invalid\",\n      \"line\": 18\n    },\n    {\n      \"name\": \"run\",\n      \"line\": 19\n    },\n    {\n      \"name\": \"watchClose\",\n      \"line\": 20\n    },\n    {\n      \"name\": \"watchRun\",\n      \"line\": 21\n    }\n  ],\n  \"taps\": [\n    {\n      \"hook\": \"done\",\n      \"type\": \"tap\",\n      \"plugin\": \"MultiCompiler\",\n      \"line\": 37\n    },\n    {\n      \"hook\": \"invalid\",\n      \"type\": \"tap\",\n      \"plugin\": \"MultiCompiler\",\n      \"line\": 48\n    }\n  ],\n  \"calls\": [\n    {\n      \"hook\": \"done\",\n      \"type\": \"call\",\n      \"line\": 44\n    }\n  ]\n}\n```\n\n### 应用构建\n\n```bash\nnpm run build\n```\n\n生成的静态文件位于 `dist/` 目录下，可将站点应用托管至任何静态文件服务器。\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falienzhou%2Fwebpack-internal-plugin-relation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falienzhou%2Fwebpack-internal-plugin-relation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falienzhou%2Fwebpack-internal-plugin-relation/lists"}