jQuery 2.0 Grunt ビルド

jQuery 2.0 Grunt ビルド

Clock Icon2013.04.19

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

jQuery 2.0 をビルドしてみよう

jQuery 2.0 を自前でビルドしてみます。自前でビルドすることでモジュールを省くことができます。

ビルド

ビルドするためにはgruntコマンドを使います。インストールしていない場合は、gruntをインストールしておきます。
gruntについては、nodebrew, npm, grunt 環境構築手順でインストールしてください。
また、grunt -version コマンドでgrunt-cliが入っていない場合は、grunt-cliをインストールしておきます。

$ grunt -version
grunt-cli v0.1.7
grunt v0.4.1

ソース取得

githubからjqueryのソースを取得します

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

依存ファイル取得

npm install

ビルド

grunt

カスタムビルド

custom:のあとにモジュールを指定します。
モジュール

  • ajax: AJAX関連のモジュール
  • ajax/xhr: XMLHTTPRequestを使ったAJAXのモジュール
  • ajax/script: <script>タグを使ったAJAXのモジュール
  • ajax/jsonp: JSONPを使ったAJAXのモジュール
  • css:.css()メソッドなどcssに関連するモジュール
  • deprecated: 廃止予定として文書化するモジュール
  • dimensions: サイズを指定するモジュール
  • effects: エフェクトに関するモジュール
  • event-alias: イベントエイリアスのモジュール
  • offset: オフセットのモジュール
  • wrap: ラップモジュール
  • sizzle: Sizzle セレクターエンジンのモジュール

詳しくはこちら https://github.com/jquery/jquery#how-to-build-your-own-jquery

grunt custom:-ajax,-css,-deprecated,-dimensions,-effects,-event-alias,-offset,-sizzle

ビルドログ

$ git clone git://github.com/jquery/jquery.git
Cloning into 'jquery'...
remote: Counting objects: 28411, done.
remote: Compressing objects: 100% (7550/7550), done.
remote: Total 28411 (delta 20972), reused 27540 (delta 20262)
Receiving objects: 100% (28411/28411), 14.38 MiB | 550 KiB/s, done.
Resolving deltas: 100% (20972/20972), done.
$ cd jquery
$ ls
AUTHORS.txt		README.md		src/
CONTRIBUTING.md		build/			test/
Gruntfile.js		package.json
MIT-LICENSE.txt		speed/
$ npm install
npm http GET https://registry.npmjs.org/grunt-contrib-jshint/0.3.0
...
npm http 304 https://registry.npmjs.org/inherits
[email protected] node_modules/grunt-git-authors

[email protected] node_modules/grunt-update-submodules

[email protected] node_modules/grunt-compare-size

[email protected] node_modules/grunt-contrib-watch
└── [email protected] ([email protected], [email protected])

[email protected] node_modules/grunt
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])

[email protected] node_modules/gzip-js
├── [email protected]
└── [email protected]

[email protected] node_modules/grunt-contrib-uglify
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])

[email protected] node_modules/testswarm
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules/grunt-contrib-jshint
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
$ grunt
Running "update_submodules" task

Running "selector" task
File 'src/selector-sizzle.js' created.

Running "build:all:*" (build) task
File 'dist/jquery.js' created.

Running "jshint:dist" (jshint) task
>> 1 file lint free.

Running "jshint:grunt" (jshint) task
>> 1 file lint free.

Running "jshint:tests" (jshint) task
>> 23 files lint free.

Running "pre-uglify:all" (pre-uglify) task

Running "uglify:all" (uglify) task
Source Map "dist/jquery.min.map" created.
File "dist/jquery.min.js" created.
Original: 239820 bytes.
Minified: 83139 bytes.

Running "dist:*" (dist) task

Running "compare_size:files" (compare_size) task
   raw     gz Sizes                                                            
240204  71171 dist/jquery.js                                                   
 83103  29030 dist/jquery.min.js                                               

Saved as: master

Done, without errors.

$ grunt custom:-ajax,-css,-deprecated,-dimensions,-effects,-event-alias,-offset,-sizzle
Running "custom:-ajax,-css,-deprecated,-dimensions,-effects,-event-alias,-offset,-sizzle" (custom) task
Creating custom build...

Running "build:all:*:-ajax:-css:-deprecated:-dimensions:-effects:-event-alias:-offset:-sizzle" (build) task
Excluding sizzle           (src/selector-sizzle.js)      
Including sizzle alternate (src/selector-native.js)      
Excluding css              (src/css.js)                  
Excluding event-alias      (src/event-alias.js)          
Excluding ajax             (src/ajax.js)                 
Excluding ajax/script      (src/ajax/script.js)          
Excluding ajax/jsonp       (src/ajax/jsonp.js)           
Excluding ajax/xhr         (src/ajax/xhr.js)             
Excluding effects          (src/effects.js)              
Excluding offset           (src/offset.js)               
Excluding dimensions       (src/dimensions.js)           
Excluding deprecated       (src/deprecated.js)           
File 'dist/jquery.js' created.

Running "pre-uglify:all" (pre-uglify) task

Running "uglify:all" (uglify) task
Source Map "dist/jquery.min.map" created.
File "dist/jquery.min.js" created.
Original: 116463 bytes.
Minified: 42045 bytes.

Running "dist" task



Done, without errors.

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.