# \[非必需\] svgo
**作用**去除 svg 文件中的多余字符,減少文件體積。一般情況下能減少 50% 左右的文件大小。
這里的`svgo`,指的是 node.js 的一個庫,如果您需要使用的話,需要安裝 node.js,并使用如下 npm 方式進行安裝:
~~~
[sudo] npm install svgo -g
~~~
在系統終端輸入如下命令:
~~~
svgo
~~~
如果出現如下內容,則表示安裝成功:
~~~
Nodejs-based tool for optimizing SVG vector graphics filesUsage: svgo [OPTIONS] [ARGS]Options: -h, --help : Help -v, --version : Version -i INPUT, --input=INPUT : Input file, "-" for STDIN -s STRING, --string=STRING : Input SVG data string -f FOLDER, --folder=FOLDER : Input folder, optimize and rewrite all *.svg files -o OUTPUT, --output=OUTPUT : Output file or folder (by default the same as the input), "-" for STDOUT -p PRECISION, --precision=PRECISION : Set number of digits in the fractional part, overrides plugins params --config=CONFIG : Config file or JSON string to extend or replace default --disable=DISABLE : Disable plugin by name --enable=ENABLE : Enable plugin by name --datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded) --multipass : Enable multipass --pretty : Make SVG pretty printed --indent=INDENT : Indent number when pretty printing SVGs -q, --quiet : Only output error messages, not regular status messages --show-plugins : Show available plugins and exitArguments: INPUT : Alias to --input OUTPUT : Alias to --output
~~~
因為 svgo 是非必需的,所以這里不深入,因為我們使用了性能更出色的Go語言的庫:
~~~
https://github.com/tdewolff/minify
~~~
測試的時候,性能大概將近是 svgo 的 幾十倍,壓縮的svg體積,出于svg文件質量的考慮,只壓縮到了 原 svg 文件體積的 60% 左右。