New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

compression-webpack-plugin

Package Overview
Dependencies
Maintainers
3
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compression-webpack-plugin

Prepare compressed versions of assets to serve them with Content-Encoding

11.1.0
latest
Source
npm
Version published
Weekly downloads
1.2M
3.82%
Maintainers
3
Weekly downloads
 
Created

What is compression-webpack-plugin?

The compression-webpack-plugin is a plugin for Webpack that allows you to compress assets with various compression algorithms before they are output to the file system. This can help reduce the size of your assets, leading to faster load times for your web application.

What are compression-webpack-plugin's main functionalities?

Compression of assets

This feature allows you to compress files using gzip. The 'test' option is a RegExp that matches the files to compress.

const CompressionPlugin = require('compression-webpack-plugin');

module.exports = {
  plugins: [
    new CompressionPlugin({
      algorithm: 'gzip',
      test: /\.js(\?.*)?$/i,
    }),
  ],
};

Custom compression options

This feature allows you to use different compression algorithms like Brotli, and set custom compression options such as the compression level.

const CompressionPlugin = require('compression-webpack-plugin');

module.exports = {
  plugins: [
    new CompressionPlugin({
      algorithm: 'brotliCompress',
      test: /\.js(\?.*)?$/i,
      compressionOptions: { level: 11 },
    }),
  ],
};

Asset filtering

This feature allows you to exclude certain assets from being compressed by using the 'exclude' option.

const CompressionPlugin = require('compression-webpack-plugin');

module.exports = {
  plugins: [
    new CompressionPlugin({
      test: /\.js(\?.*)?$/i,
      exclude: /node_modules/,
    }),
  ],
};

Threshold and minRatio settings

This feature allows you to only compress assets that are larger than a certain size (threshold) and only if the compression ratio is below a certain value (minRatio).

const CompressionPlugin = require('compression-webpack-plugin');

module.exports = {
  plugins: [
    new CompressionPlugin({
      test: /\.js(\?.*)?$/i,
      threshold: 10240,
      minRatio: 0.8
    }),
  ],
};

Other packages similar to compression-webpack-plugin

Keywords

webpack

FAQs

Package last updated on 27 Feb 2024

Did you know?

Socket

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