[Grunt & Yeoman] grunt-contrib-compress で JavaScript や CSS ファイルを gzip する
grunt-contrib-compress で、JavaScript や CSS を gzip します。
[markdown]
> * [gruntjs/grunt-contrib-compress · GitHub](https://github.com/gruntjs/grunt-contrib-compress)
## インストール
“`prettyprinted
% npm install grunt-contrib-compress –save-dev
“`
## Gruntfile
“`
# grunt-contrib-compress
compress:
css:
options:
mode: ‘gzip’
files: [
expand: true,
src: ‘dist/stylesheets/*.min.css’,
ext: ‘.min.css.gz’
]
js:
options:
mode: ‘gzip’
files: [
expand: true,
src: ‘dist/javascripts/*.min.js’,
ext: ‘.min.js.gz’
]
archive:
options:
archive: ‘archive.zip’
files: [
expand: true,
cwd: ‘<%= pkg.path.dist %>/’,
src: ‘**/*’,
dest: ”
]
“`
> * [GruntをCoffeeScriptで書いてcompileしてconcatしてminifyしてgzipする【2日目】 | Developers.IO](http://dev.classmethod.jp/tool/grunt-coffee/)
## つかいかた
例えば、公開用に minify 済ファイルの gzip 版を作成する。
“`prettyprinted
% grunt compress:css
Running “compress:css” (compress) task
Created dist/stylesheets/gruntSample.min.css.gz (1335 bytes)
Done, without errors.
“`
grunt-contrib-cssmin や grunt-contrib-uglify の report オプションの結果と比較すると、圧縮率が低いようだ。
> * [Grunt: css ファイルの結合・圧縮をする | deadwood](https://www.d-wood.com/blog/2013/11/28_5065.html)
> * [Grunt: JavaScript ファイルの結合・難読化・圧縮をする | deadwood](https://www.d-wood.com/blog/2013/11/25_5063.html)
例えば、納品用として電磁媒体に記録するための archive ファイルを作成する。
“`prettyprinted
% grunt compress:archive
Running “compress:archive” (compress) task
Created archive.zip (913572 bytes)
Done, without errors.
“`
[/markdown]