How do I compile a custom version of the latest jquery class library by myself?

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Do you feel that the jquery library is not flexible enough to load modules dynamically like other frameworks or libraries, such as dojo, or that you don't use all of the functionality that jquery provides in your project, such as AJAX-related functionality, and only DOM-related operations. So can we lose some of our jquery? In today's article, we'll show you how to use some compilation tools to create our own jquery class libraries.

Tools needed for compiling

Before we compile, we need to prepare 3 compilation tools:

git 1.7 or update: Used to clone crawl jquery code library

NPM: This was introduced in our previous node.js, and if you install the Node.js, you include this tool

Grunt: A task-based command line JavaScript compilation tool

Install and compile

First please download git and NPM, we are using the Windows environment, download and install Git and node.js. Follows:

Download git and install:

  

Download Node.js and install:

  

Note that we use NPM to install grunt.

Get jquery code and compile

First open git Bash, and if you install Git, you can find the shortcuts in the Start menu and run the commands as follows:

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

You will see the relevant files that are crawling jquery. The following figure:

  

Upon completion, we will find the directory jquery in the personal directory of the native user. This is the jquery engineering file directory.

Next, go to the jquery directory and run NPM:

CD jquery && npm Install

  

Confirm that you have installed the grunt, enter the following command:

Grunt-version

  

Finally, compile with grunt, as follows:

Grunt

You will be able to see your compiled jquery in the Dist directory.

Note: If you encounter an error as follows:

  

The reason is that no child modules have been extracted, please use the following method to resolve:

git submodule update--init

  

To run grunt again, you can see the following output:

  

You can see that we've generated 3 versions of Jquery.js in the Dist directory.

Compiling a custom version of jquery

Here we will compile a custom version of jquery, before making a product-level jquery class Library, please confirm the latest stable version as follows:

Git pull; Git checkout $ (git describe--abbrev=0--tags)

Then confirm that all node dependencies and all Git modules have been check out.

NPM Install && Grunt

Now that we start compiling the custom version, for example, we don't need AJAX functionality, we run the following command line:

Grunt Custom:-ajax

CSS not required:

Grunt Custom:-css

No deprecated required:

Grunt custom:-deprecated

No dimensions required:

Grunt Custom:-dimensions

No effects required:

Grunt Custom:-effects

No offset required:

Grunt Custom:-offset

No optional modules are required:

Grunt Custom:-offsetgrunt Custom:-ajax,-css,-deprecated,-dimensions,-effects,-offset

Note that all dependencies are compiled and processed internally. You don't have to worry.

Finally, run the unit test case to ensure that the code is correct.

CD jquery && Grunt Watch

So you go to dist and look at the number of lines of code for the jquery class library, and you can see that the file is smaller.

For more compilation information, see JQuery's GitHub Address: https://github.com/jquery/jquery

Hope you like this article, if you have any questions, please leave a message in our article, thank you for reading!

Source: How do you compile your own custom version of the latest jquery class library?

Date: 2012-9-21 Source: gbin1.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.