How to build custom jQuery

Yet another manual on subj

Preparation

Install node and npm packages. Test:

$ node -v; npm -v

I'm advising you to use your packaging system instead of compiling from sources and installing with make install. Packages give you contol on what is going on in your system. If you want latest version of package you can make it and then build package of it, but its too complicated, I know. On Debian you may need also nodejs-legacy package that provides compatibility symlink.

Global installation of grunt:

$ npm install -g grunt-cli
$ grunt -М

Branches

jQuery had two branches: ie6+ compatible (1.x) and ie9+ compatible (2.x). Now it's switching to 3.x numbering with master and compat ie8+ branches.

Just cloning the repo gives master = noncompatible:

$ git clone git@github.com:jquery/jquery.git

To get compatible branch you can do

$ git clone -b compat git@github.com:jquery/jquery.git

or switch branch to compat after git clone.

Normal build

$ cd jquery
$ npm install
$ grunt
$ ll -h dist
total 464K
-rw-r--r-- 1 ors ors 250K Aug 29 10:20 jquery.js
-rw-r--r-- 1 ors ors  83K Aug 29 10:21 jquery.min.js
-rw-r--r-- 1 ors ors 126K Aug 29 10:21 jquery.min.map
$ grep "version" dist/jquery.js | head -n 1
version = "3.0.0-pre+compat",

Custom build

$ grunt custom:-ajax,-css,-deprecated,-event,-dimensions,-effects,-offset,-wrap,-core/ready,-deferred,-exports/global,-exports/amd
$ grunt compare_size
Running "compare_size:files" (compare_size) task
   raw     gz Sizes
147203  43876 dist/jquery.js
 49573  17164 dist/jquery.min.js

   raw     gz Compared to compat @ 3923bb8400b149f483b7115d0edd2f304348b189
-135756-40330 dist/jquery.js
-43262 -15059 dist/jquery.min.js

   raw     gz Compared to last run
-135756-40330 dist/jquery.js
-43262 -15059 dist/jquery.min.js

On master branch you can even exclude sizzle (query engine) module:

$ grunt compare_size
Running "compare_size:files" (compare_size) task
   raw     gz Sizes
 80490  24241 dist/jquery.js
 29234  10102 dist/jquery.min.js

   raw     gz Compared to master @ 9d820fbde6d89bc7a06e2704be61cf6c0b4d6e3c
-175453-51504 dist/jquery.js
-55334 -19290 dist/jquery.min.js

   raw     gz Compared to last run
-175453-51504 dist/jquery.js
-55334 -19290 dist/jquery.min.js

Shrinks jQuery to 10k!

Read also this article.

Cheers.

 

shitpoet@gmail.com

 



 

free hit counters