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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-minify-lottie-json

v1.0.2

Published

A Vite plugin that minifies Lottie animation JSON assets at build time, shrinking their size without breaking the animation

Readme

vite-plugin-minify-lottie-json

npm GitHub License: MIT

A Vite plugin that minifies Lottie animation JSON assets at build time, shrinking their size without breaking the animation.

Features

  • Import via the *.json?lottie suffix — the plugin hooks into Vite's transform pipeline and minifies the file automatically. No build script or CLI step required.
  • Works with both Vite flavors — compatible with rolldown-vite (Vite ≥ 8.0) and the classic rollup-vite (Vite < 8.0). The plugin auto-detects which engine is in use.
  • Minifies After Effects expressions — expression code embedded in the Lottie file is treated as JavaScript and minified.
  • Minifies marker text — After Effects marker comments that contain JSON are re-serialized without whitespace. Marker text that is not valid JSON is left untouched.
  • Does not corrupt your animation — unlike some generic Lottie minifiers, it preserves expressions and marker data.

Installation

# npm
npm install --save-dev vite-plugin-minify-lottie-json

# yarn
yarn add --dev vite-plugin-minify-lottie-json

# pnpm
pnpm add --save-dev vite-plugin-minify-lottie-json

# bun
bun add --dev vite-plugin-minify-lottie-json

Usage

Add the plugin to your vite.config.ts:

import { defineConfig } from "vite";
import minifyLottieJson from "vite-plugin-minify-lottie-json";

export default defineConfig({
	plugins: [minifyLottieJson()],
});

Then import a Lottie JSON file with the ?lottie query suffix. The plugin intercepts the import and hands you the minified JSON as a parsed object — just like a regular *.json import, but with the content minified:

import animationData from "./assets/lotties/anim.json?lottie";

// lottie-web
import lottie from "lottie-web";
lottie.loadAnimation({
	container: document.querySelector("div"),
	renderer: "svg",
	loop: true,
	autoplay: true,
	animationData,
});

// @lottiefiles/dotlottie-web
import { DotLottie } from "@lottiefiles/dotlottie-web";
new DotLottie({
	autoplay: true,
	loop: true,
	canvas: document.querySelector("canvas"),
	data: animationData,
});

Only imports that use the ?lottie suffix are affected — regular *.json imports are handled by Vite as usual.

Options

The plugin accepts an optional options object:

minifyLottieJson({
	minifyJSEngine: "oxc", // default
});

minifyJSEngine

Controls which JavaScript engine is used to minify the After Effects expressions.

  • Type: "oxc" | "swc" | "esbuild" | "terser"
  • Default: "oxc"

The default engine, "oxc", is powered by oxc-minify, which is bundled with the plugin and needs no extra setup. The other engines are not bundled — if you choose one, install its package yourself:

| Engine | Package to install | | ----------- | -------------------- | | "oxc" | oxc-minify (bundled) | | "swc" | @swc/core | | "esbuild" | esbuild | | "terser" | terser |

# example: switch to the terser engine
npm install --save-dev terser

What gets minified

The plugin walks the Lottie document and minifies two specific parts:

After Effects expressions

In the Lottie format, an expression attached to an animated property is stored in the x field of that property (alongside a, k and ix). Its value is JavaScript code wrapped in a Bodymovin-style var $bm_rt assignment, for example:

{
	"a": 0,
	"k": [16, 4],
	"ix": 2,
	"x": "var $bm_rt;\n$bm_rt = [\n    value[0],\n    value[1] + thisComp.layer('Circle 1').effect('OffsetHeight')('Slider')\n];"
}

The plugin treats this value as JavaScript and minifies it down to a compact single line.

{"a":0,"k":[16,4],"ix":2,"x":"var $bm_rt=[value[0],value[1]+thisComp.layer(`Circle 1`).effect(`OffsetHeight`)(`Slider`)];"}

After Effects marker text

Marker comments live in the top-level markers array, where each marker's text is stored in its cm field:

{
	"tm": 0,
	"dr": 15,
	"cm": "{\r\n\"name\": \"NormalToPressed\"\r\n}"
}

The plugin treats the cm text as JSON and re-serializes it without whitespace:

{"tm":0,"dr":15,"cm":"{\"name\":\"NormalToPressed\"}"}

If the cm value is not valid JSON, it is left exactly as-is.

TypeScript

The plugin ships type declarations for the *.json?lottie import. There are two ways to register them:

Via tsconfig.json (preferred for TypeScript 6.0+)

Add the package's client entry to the types array:

{
	"compilerOptions": {
		"types": [
			"vite-plugin-minify-lottie-json/client"
		]
	}
}

Via vite-env.d.ts (preferred for TypeScript below 6.0)

Add a triple-slash reference to your vite-env.d.ts file (create it if it does not already exist):

/// <reference types="vite-plugin-minify-lottie-json/client" />

Either way, TypeScript will type the default export of a *.json?lottie import as an object.

Why not use lottie-minify?

There is already an existing tool, lottie-minify, for compressing Lottie files. This plugin deliberately does not build on it: in testing, running lottie-minify on these files corrupted them — for example, the After Effects expressions were stripped out entirely. This plugin instead performs a focused, format-aware minification that shrinks the file while keeping expressions and marker data intact.

License

MIT