Socket
Socket
Sign inDemoInstall

vite-plugin-compression2

Package Overview
Dependencies
22
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vite-plugin-compression2

a fast vite compression plugin


Version published
Weekly downloads
16K
decreased by-11.52%
Maintainers
1
Install size
232 kB
Created
Weekly downloads
 

Changelog

Source

0.10.2

Background

Patches

  • Fix option filename called result same as bundle filename can't work. #31

Readme

Source

vite-plugin-compression2

codecov

This is a compression plugin for vite.

Install


$ yarn add vite-plugin-compression2 -D

# or

$ npm install vite-plugin-compression2 -D

Usage

import { defineConfig } from 'vite'

import { compression } from 'vite-plugin-compression2'

export default defineConfig({
  plugins: [
    // ...your plugin
    compression()
  ]
})

Options

paramstypedefaultdescription
includestring | RegExp | Array<string | RegExp>-Include all assets matching any of these conditions.
excludestring | RegExp | Array<string | RegExp>-Exclude all assets matching any of these conditions.
thresholdnumber0Only assets bigger than this size are processed (in bytes)
algorithmstring| functiongzipThe compression algorithm
compressionOptionsRecord<string,any>{}Compression options for algorithm(details see zlib module)
deleteOriginalAssetsbooleanfalseWhether to delete the original assets or not
skipIfLargerOrEqualbooleanfalseWhether to skip the compression if the result is larger than or equal to the original file
filenamestring[path][base].gzThe target asset filename

Q & A

Why not vite-plugin-compression

  • vite-plugin-compression no longer maintenance.

Why vite-plugin-compression2

  • vite-plugin-compression2 has minimal dependencies and better performance.

Can i custom the compression algorithm?

  • Yes, you can see the unit test case.

Can i generate multiple compressed assets with difference compression algorithm?

import { defineComponent } from 'vite'
import { compression } from 'vite-plugin-compression2'

export default defineComponent({
  plugins: [
    // ...your plugin
    compression(),
    compression({ algorithm: 'brotliCompress', exclude: [/\.(br)$/, /\.(gz)$/], deleteOriginalAssets: true })
  ]
})
  • You should set exclude for the latest compression plugin. ( Because in the full bundle process. Bundle chunk is shared. And there are write (delete) operations on the bundle inside the plugin. So you should ignore the compressed chunk :) If you want delete the original assets you also follow the way.

Others

If you want to further optimize the bundle size. You can take a look vite-plugin-cdn2

LICENSE

MIT

Author

Kanno

Keywords

FAQs

Last updated on 09 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc