作用

  • 校验依赖关系
  • 生成依赖图

安装

npm install --save-dev dependency-cruiser
# 或者使用 yarn
yarn add -D dependency-cruiser
# 或者使用 pnpm
pnpm add -D dependency-cruiser

生成配置文件

npx depcruise --init

一定要, 不然无法执行命令

校验依赖关系

npx depcruise src

配置参考教程文档

生成依赖图

npx dependency-cruiser --output-type mermaid src --output-to dependency-graph.mmd
  • npx: 在 node_modules 中查找安装的包并执行
  • dependency-cruiser: 要执行的包名称
  • —output-type mermaid: 制定格式为 mermaid , 参考
  • src: 对 src 文件夹中的文件进行依赖关系分析
  • —output-to dependency-graph.mmd: 指定输出文件的名称为 dependency-graph.mmd

生成 svg:

brew install graphviz
npx depcruise src --output-type dot | dot -T svg > dependency-graph.svg