A universal compress plugin for Webpack / Vite / Rollup, powered by Unplugin, generating compressed file using gzip / brotli / etc...
See more usage example in folder
/examples
. Feel free to modify and play it on your own!
// webpack.config.js
const compress = require('unplugin-compress/webpack');
module.exports = ({
mode: 'production',
entry: './src/index.js',
output: {
path: distPath,
},
plugins: [
compress({
filter: /\.js$/,
}),
compress({
filter: /main\.js$/,
algorithm: 'brotliCompress',
extname: '.br',
}),
// etc...
]
});
// in vite.config.ts
import { defineConfig } from 'vite';
import compress from 'unplugin-compress/vite';
export default defineConfig({
plugins: [
compress({
filter: /\.js$/,
}),
compress({
filter: /\.(js|css)$/,
algorithm: 'brotliCompress',
extname: '.br',
}),
]
});
// in rollup.config.js
import compress from 'unplugin-compress/rollup';
export default {
// ...
plugins: [
compress({
filter: /\.js$/,
})
],
// ...
};
Key | Type | Default | Description |
---|---|---|---|
verbose | boolean |
true |
Whether to output the compressed result in the console |
filter | RegExp | (filename: string) => boolean |
() => false |
Distinguish whether a chunk/asset should be compressed or not. If filter is undefined, nothing will be compressed. |
algorithm | Algorithm |
gzip |
Possible values are gzip , brotliCompress , deflate and deflateRaw |
extname | string |
.gz |
The extension name of output file |
threshold | number |
0 |
Only assets bigger than this size are processed (in bytes) |
- Vite support.
- Webpack(both 4 and 5) support.
- Rollup support.