如何清除项目中没用代码
项伟平(2023.01.06)
业务仓库代码臃肿是一个普遍的现象
- 需求是分批提过来
- 小改动居多
- 前人的历史债务
- 代码所有者离职
- treeshaking 打包的时候通过语法树剔除没用的代码(原代码还在)
- 清除代码 删除没用的代码让项目变得清爽,提高研发效率
- byteforce codes handed over from supplier:
- over 40w+ lines of code
- many files are unused
- many export functions and definitions are unused
- these lead to:
- hard for new comer to familiar with projects
- hard to locate bugs
- time killer to ignore useless code every time
MSS admin项目
- partner目录(旧)
- merchant-refactor(新)
- store-refactor(新)
- merchant-host-refactor(新)

方案选型
- webpack(影响打包效率)
- ts语法树(轻量,完整语法树,类型清除)
- eslint(协助,提示作用)
手段二 语法分析工具直接删除文件
ts-unused-exports 通过ts语法分析知道代码中没有用的export
步骤三 分析部分export没用的文件
调整文件的文件,将依赖尽量合理化(需要人工)
如何清除项目中没用代码 项伟平(2023.01.06)