
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
vite-plugin-compression2
Advanced tools
$ yarn add vite-plugin-compression2 -D
# or
$ npm install vite-plugin-compression2 -D
import { defineConfig } from 'vite'
import { compression } from 'vite-plugin-compression2'
export default defineConfig({
plugins: [
// ...your plugins
compression()
]
})
import { compression, defineAlgorithm } from 'vite-plugin-compression2'
export default defineConfig({
plugins: [
compression({
algorithms: [
'gzip',
'brotliCompress',
defineAlgorithm('deflate', { level: 9 })
]
})
]
})
import { compression, defineAlgorithm } from 'vite-plugin-compression2'
export default defineConfig({
plugins: [
compression({
algorithms: [
defineAlgorithm(
async (buffer, options) => {
// Your custom compression logic
return compressedBuffer
},
{ customOption: true }
)
]
})
]
})
import { compression, tarball } from 'vite-plugin-compression2'
export default defineConfig({
plugins: [
compression(),
// If you want to create a tarball archive, use tarball plugin after compression
tarball({ dest: './dist/archive' })
]
})
| params | type | default | description |
|---|---|---|---|
include | string | RegExp | Array<string | RegExp> | /\.(html|xml|css|json|js|mjs|svg|yaml|yml|toml)$/ | Include all assets matching any of these conditions. |
exclude | string | RegExp | Array<string | RegExp> | - | Exclude all assets matching any of these conditions. |
threshold | number | 0 | Only assets bigger than this size are processed (in bytes) |
algorithms | Algorithms | ['gzip', 'brotliCompress'] | Array of compression algorithms or defineAlgorithm results |
filename | string | function | [path][base].gz or [path][base]. br If algorithm is zstandard be [path][base].zst | The target asset filename pattern |
deleteOriginalAssets | boolean | false | Whether to delete the original assets or not |
skipIfLargerOrEqual | boolean | true | Whether to skip the compression if the result is larger than or equal to the original file |
logLevel | string | info | Control sdout info |
artifacts | function | undefined | Sometimes you need to copy something to the final output. This option may help you. |
| params | type | default | description |
|---|---|---|---|
dest | string | - | Destination directory for tarball |
defineAlgorithm(algorithm, options?)Define a compression algorithm with options.
Parameters:
algorithm: Algorithm name ('gzip' | 'brotliCompress' | 'deflate' | 'deflateRaw' | 'zstandard' | 'gz' | 'br' | 'brotli' | 'zstd') or custom functionoptions: Compression options for the algorithmReturns: [algorithm, options] tuple
Examples:
// Built-in algorithm with default options
defineAlgorithm('gzip')
// Built-in algorithm with custom options
defineAlgorithm('gzip', { level: 9 })
// Brotli with custom quality
defineAlgorithm('brotliCompress', {
params: {
[require('zlib').constants.BROTLI_PARAM_QUALITY]: 11
}
})
// Custom algorithm function
defineAlgorithm(
async (buffer, options) => {
// Your compression implementation
return compressedBuffer
},
{ customOption: 'value' }
)
| Algorithm | Aliases | Extension | Node.js Support | Description |
|---|---|---|---|---|
gzip | gz | .gz | All versions | Standard gzip compression with good balance of speed and ratio |
brotliCompress | brotli, br | .br | All versions | Brotli compression with better compression ratio than gzip |
deflate | - | .gz | All versions | Deflate compression algorithm |
deflateRaw | - | .gz | All versions | Raw deflate compression without headers |
zstandard | zstd | .zst | >= 22.15.0 or >= 23.8.0 | Zstandard compression with excellent speed/ratio balance |
| Custom Function | - | Custom | All versions | Your own compression algorithm implementation |
The algorithms option accepts:
type Algorithms =
| Algorithm[] // ['gzip', 'brotliCompress']
| DefineAlgorithmResult[] // [defineAlgorithm('gzip'), ...]
| (Algorithm | DefineAlgorithmResult)[] // Mixed array
If you're upgrading from v1.x, please check the Migration Guide.
compression({
algorithms: ['gzip']
})
compression({
algorithms: [
defineAlgorithm('gzip', { level: 9 }),
defineAlgorithm('brotliCompress', {
params: {
[require('zlib').constants.BROTLI_PARAM_QUALITY]: 11
}
})
]
})
compression({
algorithms: ['gzip'],
filename: '[path][base].[hash].gz'
})
compression({
algorithms: ['gzip'],
deleteOriginalAssets: true
})
compression({
algorithms: ['gzip'],
threshold: 1000 // Only compress files larger than 1KB
})
tarball option dest means to generate a tarball somewheretarball is based on the ustar format. It should be compatible with all popular tar distributions (gnutar, bsdtar etc)Note: If you try to use zstd compression on an unsupported Node.js version, the plugin will throw a helpful error message indicating the required version.
FAQs
a fast vite compression plugin
The npm package vite-plugin-compression2 receives a total of 84,895 weekly downloads. As such, vite-plugin-compression2 popularity was classified as popular.
We found that vite-plugin-compression2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.