1.2.2 • Published 2 years ago

@averjs/nuxt-compression v1.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Compression module for Nuxt 3

npm version npm downloads ci workflow

This is an unofficial compression module for Nuxt 3. Currently it only works with vite. It uses vite-plugin-compression to generate the compressed files. To make this work and serve those files, this plugin modifies the internal code of the unjs/nitro package. There is already an issue for an official way to implement some kind of compression which you can check out here.

Setup

yarn install -D @averjs/nuxt-compression
pnpm add -D @averjs/nuxt-compression

Usage

export default defineNuxtConfig({
  buildModules: ['@averjs/nuxt-compression'],
  'compression': {
    // options
  },
});

Options

viteCompression

  • default -
{
  algorithm: 'brotliCompress',
  filter: /\.(js|mjs|json|css|html)$/i
}

Options for the vite-plugin-compression plugin

maxAge

  • default - 60 * 60 * 24 * 365

Set the maxAge for the Cache-Control Header. Can either be a number or a filter function which accepts the asset path and should return a number. Be aware, if you use cacheControl alongside maxAge, it is getting ignored.

cacheControl

  • default - undefined

Set Cache-Control Header. Can either be a string or a filter function which accespts the asset path and should return a valid Cache-Control Header string. This option has more weight than maxAge and overwrites it. You can head to MDN to see all the available options.

Development

  • Run pnpm dev:prepare to generate type stubs.
  • Use pnpm dev to start playground in development mode.