Vite 中文文档 Vite 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • vite

    • 指引
    • 为什么选 Vite
    • 开始
    • 功能
    • 命令行界面
    • 使用插件
    • 依赖预构建
    • 静态资源处理
    • 构建生产版本
    • 部署静态站点
    • 环境变量和模式
    • 服务端渲染
    • 后端集成
    • 与其他工具比较
    • 故障排除
    • 从 v3 迁移
  • API

  • 配置参考

  • vite

  • API

  • 配置参考

vite-plugin-compression


English| 中文

Use gzip or brotli to compress resources.

Since vite-plugin-compress does not support gzip compression, a separate copy has been modified and some functions have been added.

Install (yarn or npm)


node version:>=12.0.0

vite version:>=2.0.0

  1. ``` sh
  2. yarn add vite-plugin-compression -D

  3. ```

or

  1. ``` sh
  2. npm i vite-plugin-compression -D

  3. ```

Usage


Configuration plugin in vite.config.ts

  1. ``` ts
  2. import viteCompression from 'vite-plugin-compression';

  3. export default () => {
  4.   return {
  5.     plugins: [viteCompression()],
  6.   };
  7. };
  8. ```

Options


params type default default
:--- :--- :--- :---
verbose boolean true Whether to output the compressed result in the console
filter RegExp or (file: string) => boolean DefaultFilter Specify which resources are not compressed
disable boolean false Whether to disable
threshold number 1025 It will be compressed if the volume is larger than threshold, the unit is b
algorithm string gzip Compression algorithm, optional ['gzip','brotliCompress' ,'deflate','deflateRaw']
ext string .gz Suffix of the generated compressed package
compressionOptions object - The parameters of the corresponding compression algorithm
deleteOriginFile boolean - Whether to delete source files after compression

DefaultFilter

/\.(js|mjs|json|css|html)$/i

Example


Run Example

  1. ``` shell
  2. cd ./example

  3. yarn install

  4. yarn test:gzip

  5. yarn test:br

  6. ```

Sample project


Vben Admin

License


MIT

Inspiration


vite-plugin-compress
Last Updated: 2023-05-23 11:11:51