aboutsummaryrefslogtreecommitdiff
path: root/node_modules/gulp-gzip/README.md
blob: 807c2c57778f5d39a72ea2f81fa51a483b15d6b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
gulp-gzip
=========

Gzip plugin for [gulp](https://github.com/wearefractal/gulp).

#Install

```
npm install --save-dev gulp-gzip
```

#Options

### append `Boolean`

Appends `.gz` file extension if true. Defaults to true.

```javascript
 gzip({ append: true })
```
`filename.txt` becomes `filename.txt.gz`.

### extension `String`

Appends an arbitrary extension to the filename. Disables `append` and `preExtension` options.

```javascript
 gzip({ extension: 'zip' }) // note that the `.` should not be included in the extension
```
`filename.txt` becomes `filename.txt.zip`.

### preExtension `String`

Appends an arbitrary pre-extension to the filename. Disables `append` and `extension` options.

```javascript
 gzip({ preExtension: 'gz' }) // note that the `.` should not be included in the extension
```
`filename.txt` becomes `filename.gz.txt`.

### threshold `String|Number|Boolean`

Minimum size required to compress a file. Defaults to false.

```javascript
gzip({ threshold: '1kb' })
```

```javascript
gzip({ threshold: 1024 })
```

```javascript
gzip({ threshold: true })
```

### gzipOptions `Object`

Options object to pass through to zlib.Gzip. See [zlib documentation](http://nodejs.org/api/zlib.html#zlib_options) for more information.

```javascript
gzip({ gzipOptions: { level: 9 } })
```

```javascript
gzip({ gzipOptions: { memLevel: 1 } })
```

### deleteMode `String|Function`

Some webserver modules such as nginx `gzip_static` looks for `example.html.gz`, serve it if it exists, else the original `example.html` will be served.

For instance, if `example.html` was 2kb, it would be gzipped and `example.html.gz` was created.

However, if later `example.html` is modified to content less than the threshold, gulp-gzip will only bypass it. Hence, you will end up with a new `example.html` yet old `example.html.gz`. Your webserver will continue to serve old content (`example.html.gz`).

Using this option, gulp-gzip will remove `example.html.gz`.

It takes in the same argument as `gulp.dest` as in `gulp.dest('mydest')`, so it knows where to look for the gzipped files. Defaults to `undefined`.

```javascript
gzip({ threshold: 1024, deleteMode: 'mydest' })
```

If you have `cwd` as in `gulp.dest('mydest', { cwd: mycwd })`. You can configure it using `deleteModeCwd`.

```javascript
gzip({ threshold: 1024, deleteMode: 'mydest', deleteModeCwd: mycwd })
```

### skipGrowingFiles `Boolean`

Some files actually get larger after compression. If true, this option passes along the original, uncompressed file if compression increases the file size. Defaults to false.

```javascript
 gzip({ skipGrowingFiles : true })
```

#Examples

```javascript
var gulp = require('gulp');
var gzip = require('gulp-gzip');

gulp.task('compress', function() {
    gulp.src('./dev/scripts/*.js')
	.pipe(gzip())
	.pipe(gulp.dest('./public/scripts'));
});
```

```javascript
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var gzip = require('gulp-gzip');

gulp.task('deployScripts', function() {
	gulp.src('./dev/scripts/*.coffee')
	.pipe(coffee())
	.pipe(concat('all.js'))
	.pipe(uglify())
	.pipe(gzip())
	.pipe(gulp.dest('./public/scripts'));
});
```

```javascript
var gulp = require('gulp');
var tar = require('gulp-tar');
var gzip = require('gulp-gzip');

gulp.task('tarball', function() {
	gulp.src('./files/*')
	.pipe(tar('archive.tar'))
	.pipe(gzip())
	.pipe(gulp.dest('.'));
});
```

[More examples](https://github.com/jstuckey/gulp-gzip/tree/master/examples).