Is there a tool to remove unused methods in javascript?

前端 未结 7 1907
一生所求
一生所求 2020-12-02 19:50

I\'ve got a collection of javascript files from a 3rd party, and I\'d like to remove all the unused methods to get size down to a more reasonable level.

Does anyone

7条回答
  •  独厮守ぢ
    2020-12-02 20:45

    I know this is an old question by UglifyJS2 supports removing unused code which may be what you are looking for.

    Also worth noting that eslint supports an option called no-unused-vars which actually does some basic handling of detecting if functions are being used or not. It definitely detects it if you make the function anonymous and store it as a variable (but just be aware that as a variable the function declaration doesn't get hoisted immediately)

    In the context of detecting unused functions, while extreme, you can consider breaking up a majority of your functions into separate modules because there are packages and tools to help detect unused modules. There is a little segment of sindreshorus's thoughts on tiny modules which might be relevant to that philosophy but that may be extreme for your use case.

提交回复
热议问题