Compress

PlayFormCC0-1.0活跃维护

Astro 集成插件,在构建时自动压缩 HTML、CSS、JavaScript 和图片,减少产物体积、加快页面加载。

Compress 🗜️

Compress/v0.2.5发布于 2026-08-07 02:00 UTC665star13fork同步于 2026-11-10 06:00 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
npx astro add @playform/compress
yarn astro add @playform/compress
npm install -D -E @playform/compress
硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本Compress/v0.2.5
  1. AstroCompress/v2.4.32026-08-07 · 2026-08-07 02:42 UTC
    查看更新说明
  2. Compress/v0.2.5最新正式版2026-08-07 · 2026-08-07 02:00 UTC
  3. AstroCompress/v2.4.22026-08-05 · 2026-08-05 13:56 UTC
    查看更新说明

    What's Changed

  4. Compress/v0.2.42026-08-05 · 2026-08-05 13:02 UTC
    查看更新说明

    What's Changed

  5. Compress/v0.2.32026-04-07 · 2026-04-07 14:00 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/PlayForm/Compress/compare/Compress/v0.2.2...Compress/v0.2.3

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Compress 🗜️

    This Astro integration brings compression utilities to your Astro project.

    CSS (csso) 🎁

    CSS (lightningcss) 🎁

    HTML (html-minifier-terser) 🎁

    Image (sharp) 🎁

    JavaScript (terser) 🎁

    SVG (svgo) 🎁

    JSON 🎁

    Note

    Compress will not compress your requests, only your statically generated build and pre-rendered routes.

    [!IMPORTANT]

    Use Compress last in your integration list for the best optimizations.

    Installation 🚀

    There are two ways to add integrations to your project. Let's try the most convenient option first!

    astro add command

    Astro includes a CLI tool for adding first party integrations: astro add. This command will:

    1. (Optionally) Install all necessary dependencies and peer dependencies
    2. (Also optionally) Update your astro.config.* file to apply this integration

    To install Compress, run the following from your project directory and follow the prompts:

    Using NPM:

    npx astro add @playform/compress
    

    Using Yarn:

    yarn astro add @playform/compress
    

    Using PNPM:

    pnpx astro add @playform/compress
    

    Install dependencies manually

    First, install the Compress integration like so:

    npm install -D -E @playform/compress
    

    Then, apply this integration to your astro.config.* file using the integrations property:

    astro.config.ts

    export default {
    	integrations: [(await import("@playform/compress")).default()],
    };
    

    Getting started

    The utility will now automatically compress all your CSS, HTML, SVG, JavaScript, JSON and image files in the Astro outDir folder.

    The following image file types will be compressed via sharp:

    • avci
    • avcs
    • avif
    • avifs
    • gif
    • heic
    • heics
    • heif
    • heifs
    • jfif
    • jif
    • jpe
    • jpeg
    • jpg
    • apng
    • png
    • raw
    • tiff
    • webp

    SVG compression is supported, as well via svgo.

    Default Compression

    You can override any of the default options from the configurations of:

    [!IMPORTANT]

    lightningcss is the default CSS compressor and csso is disabled by default. csso silently deletes modern CSS it cannot parse rather than leaving it untouched — Media Queries Level 4 range syntax (@media (width>=40rem), which Tailwind CSS v4 emits for every responsive breakpoint) and CSS nesting blocks are dropped from the output with no error or warning.

    If you still want csso, enable it explicitly — and be aware it runs after lightningcss, so it can undo what lightningcss correctly preserved:

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			CSS: {
    				csso: true,
    				lightningcss: true,
    			},
    		}),
    	],
    };
    

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			CSS: false,
    			HTML: {
    				"html-minifier-terser": {
    					removeAttributeQuotes: false,
    				},
    			},
    			Image: false,
    			JavaScript: false,
    			JSON: false,
    			SVG: false,
    		}),
    	],
    };
    

    or disable them entirely:

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			CSS: false,
    			HTML: false,
    			Image: false,
    			JavaScript: false,
    			JSON: false,
    			SVG: false,
    		}),
    	],
    };
    

    You can see the full option map here: Source/Interface/Option.ts

    Output

    By default Compress compresses the outDir Astro directory, if you'd like it to compress a different directory you would have to add it to the Compress Path option, as well:

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			Path: ["./dist", "./Compress"],
    		}),
    	],
    };
    

    Add Multiple Paths

    You can add multiple paths to compress by specifying an array as the Path variable.

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			Path: ["./Target", "./Build"],
    		}),
    	],
    };
    

    Input-Output Mapping

    You can also provide a map of paths for different input output directories.

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			Path: new Map([["./Source", "./Target"]]),
    		}),
    	],
    };
    

    Or an array of the two:

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			Path: [
    				// Compress Target
    				"./Target",
    				// Compress Target one more time into a different directory
    				new Map([["./Target", "./TargetCompress"]]),
    			],
    		}),
    	],
    };
    

    File Filtering

    You can filter files to exclude specific ones from compression. A filter can be an array of regular expressions or a single match. You can also use functions to match on file names:

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			Exclude: [
    				"File.png",
    				(File: string) =>
    					File === "./Target/Favicon/Image/safari-pinned-tab.svg",
    			],
    		}),
    	],
    };
    

    Controlling Logging

    You can control the logging level by setting the Logger parameter. The default value is 2, but you can set it to 0 if you don't want to see debug messages:

    astro.config.ts

    export default {
    	integrations: [
    		(await import("@playform/compress")).default({
    			Logger: 0,
    		}),
    	],
    };
    

    Changelog

    See CHANGELOG.md for a history of changes to this integration.