简体   繁体   English

如何根据自己的需要定制基于jQuery的JavaScript库?

[英]How to tailor a jQuery based javascript library to my own needs?

I use a library which provides lots and lots of utility functions. 我使用的库提供了很多实用程序功能。 It's based on jQuery, so I have to include jQuery too. 它基于jQuery,因此我也必须包含jQuery。 Both of these libraries are huge in size but I only use a single functionality in a single function only once. 这两个库都很大,但是我只在一个函数中使用一个函数一次。

I've gathered all the code in a single .js file and measured code coverage using jscoverage . 我将所有代码收集到一个.js文件中,并使用jscoverage测量了代码覆盖率。 It seems that only 13% of the statements are executed. 似乎只执行了13%的语句。 This means more than 200KB's of dead code. 这意味着超过200KB的无效代码。

Here is what the combined.js file looks like: 这是combined.js文件的外观:

// jQuery code copy-pasted here

... 

// libX code copy-pasted here

...

libX().doSomething();

So my questions are: 所以我的问题是:

1) How can I remove all dead code from this one .js file? 1)如何从此.js文件中删除所有无效代码? I've tried Google Closure but then the code doesn't work. 我已经尝试过Google Closure,但是代码不起作用。 I guess it messed up with all the jQuery stuff. 我猜它把所有的jQuery东西弄乱了。

2) I will be serving this .js file composed of jQuery, another library and my own little code to 3rd parties so I don't want jQuery involved, even with noconflict mode. 2)我将向第3方提供由jQuery,另一个库和我自己的小代码组成的.js文件,因此即使在没有冲突模式的情况下,我也不想涉及jQuery。 How can I tailor this to my own needs? 我该如何根据自己的需要定制它? Perhaps replace the dollar sign with an arbitrary symbol or something? 也许用任意符号或其他符号替换美元符号?

Any help appreciated. 任何帮助表示赞赏。

jquery minified is small(<20kb), you can use a cdn so it won't have to be downloaded (and thus won't effect performance) and you'll probably use the rest of jquery's functionality at a later date. 缩小的jquery很小(<20kb),您可以使用CDN,因此不必下载它(因此不会影响性能),并且稍后可能会使用jquery的其余功能。

I don't understand this : I will be serving this .js file composed of jQuery, ... so I don't want jQuery involved 我不明白这一点: 我将提供由jQuery组成的.js文件,因此我不希望jQuery参与其中

And noconfilct does replace the dollar sign with an arbitrary symbol of your choosing, thats what you want isn't it ? 而且noconfilct不会用您选择的任意符号替换美元符号,这就是您想要的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM