Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

exreplay/nuxt-compression

Repository files navigation

!!!Archived!!!

Nitro now has an option compressPublicAssets which can be used in nuxt3. Please consider using that. https://nitro.unjs.io/config#compresspublicassets

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.