[英]How to find unused/dead code in web projects (90% code in javascript)
I did find a very interesting tool for identify unused css definitions in a web project.我确实找到了一个非常有趣的工具来识别 web 项目中未使用的 css 定义。 http://www.sitepoint.com/dustmeselectors/ http://www.sitepoint.com/dustmeselectors/
Are there similar tools also for javascript projects?是否也有用于 javascript 项目的类似工具?
PS I know there is no program for deterministically finding unused code. PS 我知道没有程序可以确定地查找未使用的代码。 But I am looking for a report to identify possible unused code.但我正在寻找一份报告来确定可能未使用的代码。 Then the last decision will always be your own.那么最后的决定将永远是你自己的。
Problem is there is no way to be really sure.问题是没有办法真正确定。 Suppose the following:假设如下:
Static analysis utilities are therefore useless.因此,静态分析实用程序是无用的。 I do not know whether there exists a browser extension that marks all JS usage from a running browser though.我不知道是否存在一个浏览器扩展来标记正在运行的浏览器中的所有 JS 使用情况。
You can try using tombstones to safely locate and remove dead code from your JavaScript.您可以尝试使用墓碑从 JavaScript 中安全地定位和删除死代码。
https://blog.bugsnag.com/javascript-refactoring-with-bugsnag-and-tombstones/ https://blog.bugsnag.com/javascript-refactoring-with-bugsnag-and-tombstones/
In order to find the unused assets, to remove manually, you can use deadfile library: https://m-izadmehr.github.io/deadfile/为了找到未使用的资产,手动删除,您可以使用死文件库: https : //m-izadmehr.github.io/deadfile/
It can simply find unused files, in any JS project.它可以简单地在任何 JS 项目中找到未使用的文件。
Without any config, it supports ES6, JSX, and Vue files:无需任何配置,支持 ES6、JSX 和 Vue 文件:
The one that comes to mind most quickly is Javascript LINT ( http://www.javascriptlint.com /) and JSLint ( http://www.jslint.com/ ).最容易想到的是 Javascript LINT ( http://www.javascriptlint.com/ ) 和 JSLint ( http://www.jslint.com/ )。
Beware though: the latter hurts your feelings.不过要小心:后者会伤害你的感情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.