aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/tdewolff/minify/cmd/minify/README.md
blob: f042fe3e0f373ecadf4d66142f3afb765cee2848 (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
# Minify [![Join the chat at https://gitter.im/tdewolff/minify](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tdewolff/minify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

**[Download binaries](https://github.com/tdewolff/minify/releases) for Windows, Linux and macOS**

Minify is a CLI implementation of the minify [library package](https://github.com/tdewolff/minify).

## Installation
Make sure you have [Go](http://golang.org/) and [Git](http://git-scm.com/) installed.

Run the following command

	go get github.com/tdewolff/minify/cmd/minify

and the `minify` command will be in your `$GOPATH/bin`.

You can enable bash tab completion by using

    source minify_bash_tab_completion

## Usage
    Usage: minify [options] [input]

    Options:
      -a, --all                              Minify all files, including hidden files and files in hidden directories
          --css-decimals int                 Number of decimals to preserve in numbers, -1 is all (default -1)
      -h, --help                             Show usage
          --html-keep-conditional-comments   Preserve all IE conditional comments
          --html-keep-default-attrvals       Preserve default attribute values
          --html-keep-document-tags          Preserve html, head and body tags
          --html-keep-end-tags               Preserve all end tags
          --html-keep-whitespace             Preserve whitespace characters but still collapse multiple into one
      -l, --list                             List all accepted filetypes
          --match string                     Filename pattern matching using regular expressions
          --mime string                      Mimetype (eg. text/css), optional for input filenames, has precedence over -type
      -o, --output string                    Output file or directory (must have trailing slash), leave blank to use stdout
      -r, --recursive                        Recursively minify directories
          --svg-decimals int                 Number of decimals to preserve in numbers, -1 is all (default -1)
          --type string                      Filetype (eg. css), optional for input filenames
          --url string                       URL of file to enable URL minification
      -v, --verbose                          Verbose
          --version                          Version
      -w, --watch                            Watch files and minify upon changes
          --xml-keep-whitespace              Preserve whitespace characters but still collapse multiple into one

    Input:
      Files or directories, leave blank to use stdin

### Types

	css     text/css
	htm     text/html
	html    text/html
	js      text/javascript
	json    application/json
	svg     image/svg+xml
	xml     text/xml

## Examples
Minify **index.html** to **index-min.html**:
```sh
$ minify -o index-min.html index.html
```

Minify **index.html** to standard output (leave `-o` blank):
```sh
$ minify index.html
```

Normally the mimetype is inferred from the extension, to set the mimetype explicitly:
```sh
$ minify --type=html -o index-min.tpl index.tpl
```

You need to set the type or the mimetype option when using standard input:
```sh
$ minify --mime=text/javascript < script.js > script-min.js

$ cat script.js | minify --type=js > script-min.js
```

### Directories
You can also give directories as input, and these directories can be minified recursively.

Minify files in the current working directory to **out/** (no subdirectories):
```sh
$ minify -o out/ .
```

Minify files recursively in **src/**:
```sh
$ minify -r -o out/ src
```

Minify only javascript files in **src/**:
```sh
$ minify -r -o out/ --match=\.js src
```

### Concatenate
When multiple inputs are given and either standard output or a single output file, it will concatenate the files together.

Concatenate **one.css** and **two.css** into **style.css**:
```sh
$ minify -o style.css one.css two.css
```

Concatenate all files in **styles/** into **style.css**:
```sh
$ minify -o style.css styles
```

You can also use `cat` as standard input to concatenate files and use gzip for example:
```sh
$ cat one.css two.css three.css | minify --type=css | gzip -9 -c > style.css.gz
```

### Watching
To watch file changes and automatically re-minify you can use the `-w` or `--watch` option.

Minify **style.css** to itself and watch changes:
```sh
$ minify -w -o style.css style.css
```

Minify and concatenate **one.css** and **two.css** to **style.css** and watch changes:
```sh
$ minify -w -o style.css one.css two.css
```

Minify files in **src/** and subdirectories to **out/** and watch changes:
```sh
$ minify -w -r -o out/ src
```