unplugin-compress
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

unplugin-compress

NPM version

A universal compress plugin for Webpack / Vite / Rollup, powered by Unplugin, generating compressed file using gzip / brotli / etc...

Usage

See more usage example in folder /examples. Feel free to modify and play it on your own!

Webpack

// 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...
  ]
});

Vite

// 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',
    }),
  ]
});

Rollup

// in rollup.config.js
import compress from 'unplugin-compress/rollup';

export default {
  // ...
  plugins: [
    compress({
      filter: /\.js$/,
    })
  ],
  // ...
};

Inspiration

Todo

  • [x] Vite support.
  • [x] Webpack(both 4 and 5) support.
  • [x] Rollup support.

Dependents (0)

Package Sidebar

Install

npm i unplugin-compress

Weekly Downloads

0

Version

0.1.3

License

MIT

Unpacked Size

133 kB

Total Files

20

Last publish

Collaborators

  • rogerleung0411