npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lottie-compress

v1.3.0

Published

lottie compress

Downloads

770

Readme

English

NPM Build Status

lottie compress // lottie体积压缩工具

npm安装

npm i -S lottie-compress

使用方法

import LottieCompress from 'lottie-compress';

interface IOptions {
  quality: [number, number]; // [0.55, 0.75];
  traceformInto?: string, // 'pngMixWebp', 'png', 'webp', 'avif'
  tinypngKey?: string;  // tinypng api key
}

(async () => {
  const lottieCompress = new LottieCompress(data, options: IOptions);
  const ret = await lottieCompress.execute(); // The type of ret is buffer()
})();

参数设置

  • lottieJson 主参数可以是lottie的json,页可以是lottie的jsonString
  • options quality(压缩率), traceformInto(图片类型转换), tinypngKey(用tinypng的api,输入key即可)
    • traceformInto 考虑到现在绝大部分的终端机器已经支持webp格式,随意作者更推荐使用webp格式。但实际测试下来,由于webp的算法不总是优于png,同时考虑到webp在终端的解析成本可能大于png,所以强制类型转化存在特殊的定义“pngMixWebp”,在“pngMixWebp”的定义中,lottie-compress会自动选择最终输出的png还是webp,最终保证输出的体积是最优的。

相关描述

lottie-compress是lottie体积压缩的工具库。内部功能包含lottie的字符串裁剪和图片体积优化,以及自动化的解决部分兼容性问题。

如果想直接在线用压缩功能,可以直接使用蚂蚁集团提供的在线压缩工具:https://design.alipay.com/lolita; 洛丽塔内部部分lottie优化功能不在lottie-compress中,但lottie-compress已经包含了核心能力。

经验分享:

  1. lottie-compress在纯矢量的文件中,可以优化字符串的大小,但按照zip的口径计算,压缩率大概只有5%~15%,个人觉得矢量文件没有必要,也不用压缩;
  2. lottie-compress的压缩主要收益来自base64的图片,提供png、webp、avif、jpeg的压缩,目前推荐用pngMixWebp的压缩模式,该模式可以让AE导出的png体积缩小到20%~30%,收益非常大!
  3. 实际应用中,会遇到性能问题,可以考虑使用lottie-lint做检测(洛丽塔提供了该能力);

洛丽塔:https://design.alipay.com/lolita

  1. 在线压缩和性能检测工具,方便大家不想部署仓库的情况下直接使用;
  2. 洛丽塔暂时不提供英文版本,如果中国以外的用户使用,可以使用google翻译,不影响功能;