作用 去除 svg 文件中的多余字符,减少文件体积。一般情况下能减少 50% 左右的文件大小。

这里的svgo,指的是 node.js 的一个库,如果您需要使用的话,需要安装 node.js,并使用如下 npm 方式进行安装:

[sudo] npm install svgo -g

在系统终端输入如下命令:

svgo

如果出现如下内容,则表示安装成功:

    Nodejs-based tool for optimizing SVG vector graphics files
    Usage:
      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 exit
    Arguments:
      INPUT : Alias to --input
      OUTPUT : Alias to --output

因为 svgo 是非必需的,所以这里不深入,因为我们使用了性能更出色的Go语言的库:

https://github.com/tdewolff/minify

测试的时候,性能大概将近是 svgo 的 几十倍,压缩的svg体积,出于svg文件质量的考虑,只压缩到了 原 svg 文件体积的 60% 左右。

作者:Jeebiz  创建时间:2023-02-15 23:19
最后编辑:Jeebiz  更新时间:2024-07-02 22:15