0.0.5 • Published 9 months ago

vite-plugin-compression-rs v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

vite-plugin-compression-rs

English | 中文

Use gzip or brotli to compress resources.

This project is based on vite-plugin-compression and incorporates Rust support. The compression-related logic has been rewritten to enhance performance. By leveraging Rust's efficiency, this plugin aims to provide faster and more optimized compression for your Vite projects.

Install (yarn or npm)

node version: >=12.0.0

vite version: >=2.0.0

yarn add vite-plugin-compression-rs -D

or

npm i vite-plugin-compression-rs -D

Usage

  • Configuration plugin in vite.config.ts
import {
  vitePluginCompression,
  Algorithm,
  CompressionType,
} from 'vite-plugin-compression-rs'

export default () => {
  return {
    plugins: [
      // ...other plugins
      // gizp
      vitePluginCompression({
        algorithm: Algorithm.Gzip,
        ext: '.gz',
        compressionOptions: {
          compressionType: CompressionType.Best,
        },
      }),
      // br
      vitePluginCompression({
        algorithm: Algorithm.BrotliCompress,
        ext: '.br',
        compressionOptions: {
          level: 11,
        },
      }),
    ],
  }
}

Options

paramstypedefaultdefault
verbosebooleantrueWhether to output the compressed result in the console
filterRegExp or (file: string) => booleanDefaultFilterSpecify which resources are not compressed
disablebooleanfalseWhether to disable
thresholdnumber1025It will be compressed if the volume is larger than threshold, the unit is b
algorithmAlgorithmAlgorithm.GzipCompression algorithm, optional 'gzip','brotliCompress' ,'deflate','deflateRaw'
extstring.gzSuffix of the generated compressed package
compressionOptionsobject-The parameters of the corresponding compression algorithm
deleteOriginFileboolean-Whether to delete source files after compression

DefaultFilter

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

Example

Run Example

pnpm install

cd ./examples/basic

pnpm test:gzip

pnpm test:br

License

MIT

Inspiration

vite-plugin-compression

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago