如何从 Javascript 中删除死代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6730358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove dead code from Javascript
提问by Yuvals
I am trying to remove unused functions from my project. Since it has thousands of lines, this takes forever.
我正在尝试从我的项目中删除未使用的功能。由于它有数千行,这需要永远。
Code coverage tools may suggest functions that are not used in a given test case, but it may be dangerous to rely only on this.
代码覆盖工具可能会建议给定测试用例中未使用的函数,但仅依赖于此可能会很危险。
Is there another tool which can help with this?
有没有其他工具可以帮助解决这个问题?
回答by daveoncode
You can try Google Closure compiler. It has different settings and you can also remove dead code automatically. You can try it here: http://closure-compiler.appspot.com/home
你可以试试 Google Closure 编译器。它有不同的设置,您还可以自动删除死代码。你可以在这里尝试:http: //closure-compiler.appspot.com/home
For more info read here: http://code.google.com/closure/compiler/docs/compilation_levels.html
有关更多信息,请阅读此处:http: //code.google.com/closure/compiler/docs/compilation_levels.html