• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..11-Sep-2021-

README.mdH A D11-Sep-20216.3 KiB185144

bash_completionH A D11-Sep-20211.5 KiB3627

fs.goH A D11-Sep-20217.9 KiB22395

io.goH A D11-Sep-20212.3 KiB11891

io_test.goH A D11-Sep-20213.3 KiB153118

main.goH A D11-Sep-202122.2 KiB900799

watch.goH A D11-Sep-20212.9 KiB132112

README.md

1# 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)
2
3**[Download binaries](https://github.com/tdewolff/minify/releases) for Windows, Linux and macOS**
4
5Minify is a CLI implementation of the minify [library package](https://github.com/tdewolff/minify).
6
7## Installation
8Make sure you have [Go](http://golang.org/) and [Git](http://git-scm.com/) installed.
9
10Run the following command
11
12    mkdir $HOME/src
13    cd $HOME/src
14    git clone https://github.com/tdewolff/minify.git
15    cd minify
16    make install
17
18and the `minify` command will be in `$GOPATH/bin` or `$HOME/go/bin`.
19
20If you do not have `make`, instead run the following lines to install `minify` and enable bash tab completion:
21
22    go install ./cmd/minify
23    source minify_bash_tab_completion
24
25### Arch Linux
26Using `yay`:
27
28```
29yay -Syu minify
30```
31
32[Minify in AUR](https://aur.archlinux.org/packages/minify/)
33
34### FreeBSD
35```
36pkg install minify
37```
38
39### MacOS
40Using Homebrew:
41
42```
43brew install tdewolff/tap/minify
44```
45
46[Brew tap](https://github.com/tdewolff/homebrew-tap/)
47
48### Ubuntu
49Update the package index:
50
51```
52sudo apt-get update
53```
54
55Install minify deb package:
56```
57sudo apt-get install minify
58```
59
60## Usage
61    Usage: minify [options] [input]
62
63    Options:
64      -a, --all                              Minify all files, including hidden files and files in hidden directories
65      -b, --bundle                           Bundle files by concatenation into a single file
66          --cpuprofile string                Export CPU profile
67          --css-precision int                Number of significant digits to preserve in numbers, 0 is all (default 0)
68      -h, --help                             Show usage
69          --html-keep-comments               Preserve all comments
70          --html-keep-conditional-comments   Preserve all IE conditional comments
71          --html-keep-default-attrvals       Preserve default attribute values
72          --html-keep-document-tags          Preserve html, head and body tags
73          --html-keep-end-tags               Preserve all end tags
74          --html-keep-quotes                 Preserve quotes around attribute values
75          --html-keep-whitespace             Preserve whitespace characters but still collapse multiple into one
76          --js-precision int                 Number of significant digits to preserve in numbers, 0 is all (default 0)
77          --js-keep-var-names                Preserve original variable names
78          --json-precision int               Number of significant digits to preserve in numbers, 0 is all (default 0)
79      -l, --list                             List all accepted filetypes
80          --match string                     Filename pattern matching using regular expressions
81          --memprofile string                Export memory profile
82          --mime string                      Mimetype (eg. text/css), optional for input filenames, has precedence over --type
83      -o, --output string                    Output file or directory (must have trailing slash), leave blank to use stdout
84      -p, --preserve[=mode,ownership,timestamp]   Preserve options (mode, ownership, timestamps, links)
85	  --preserve-links                   Copy symbolic links without dereferencing and without minifying the referenced file (only with --sync)
86      -r, --recursive                        Recursively minify directories
87          --svg-precision int                Number of significant digits to preserve in numbers, 0 is all (default 0)
88	  -s, --sync                             Copy all files to destination directory and minify when filetype matches
89          --type string                      Filetype (eg. css), optional for input filenames
90          --url string                       URL of file to enable URL minification
91      -v, --verbose                          Verbose
92          --version                          Version
93      -w, --watch                            Watch files and minify upon changes
94          --xml-keep-whitespace              Preserve whitespace characters but still collapse multiple into one
95
96    Input:
97      Files or directories, leave blank to use stdin
98
99### Types
100
101	css     text/css
102	htm     text/html
103	html    text/html
104	js      application/javascript
105	json    application/json
106	svg     image/svg+xml
107	xml     text/xml
108
109## Examples
110Minify **index.html** to **index-min.html**:
111```sh
112$ minify -o index-min.html index.html
113```
114
115Minify **index.html** to standard output (leave `-o` blank):
116```sh
117$ minify index.html
118```
119
120Normally the mimetype is inferred from the extension, to set the mimetype explicitly:
121```sh
122$ minify --type=html -o index-min.tpl index.tpl
123```
124
125You need to set the type or the mimetype option when using standard input:
126```sh
127$ minify --mime=application/javascript < script.js > script-min.js
128
129$ cat script.js | minify --type=js > script-min.js
130```
131
132### Directories
133You can also give directories as input, and these directories can be minified recursively.
134
135Minify files in the current working directory to **out/** (no subdirectories):
136```sh
137$ minify -o out/ *
138```
139
140Minify files recursively in **src/**:
141```sh
142$ minify -r -o out/ src
143```
144
145Minify only javascript files in **src/**:
146```sh
147$ minify -r -o out/ --match=\.js src
148```
149
150### Concatenate
151When multiple inputs are given and the output is either standard output or a single file, it will concatenate the files together if you use the bundle option.
152
153Concatenate **one.css** and **two.css** into **style.css**:
154```sh
155$ minify -b -o style.css one.css two.css
156```
157
158Concatenate all files in **styles/** into **style.css**:
159```sh
160$ minify -r -b -o style.css styles
161```
162
163You can also use `cat` as standard input to concatenate files and use gzip for example:
164```sh
165$ cat one.css two.css three.css | minify --type=css | gzip -9 -c > style.css.gz
166```
167
168### Watching
169To watch file changes and automatically re-minify you can use the `-w` or `--watch` option.
170
171Minify **style.css** to itself and watch changes:
172```sh
173$ minify -w -o style.css style.css
174```
175
176Minify and concatenate **one.css** and **two.css** to **style.css** and watch changes:
177```sh
178$ minify -w -o style.css one.css two.css
179```
180
181Minify files in **src/** and subdirectories to **out/** and watch changes:
182```sh
183$ minify -w -r -o out/ src
184```
185