# nuxt-precompress

> Precompress files to gzip and brotli and serve them automatically

Latest version **0.5.9** (published 2021-05-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install nuxt-precompress
pnpm add nuxt-precompress
yarn add nuxt-precompress
bun add nuxt-precompress
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.9 |
| Published | 2021-05-06 |
| First published | 2020-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | frenchrabbit |
| Maintainers | frenchrabbit |
| Keywords | vue, nuxt, nuxt.js, module, build, compress, compression, gzip, brotli |

## Links

- npm: https://www.npmjs.com/package/nuxt-precompress
- Repository: https://github.com/frenchrabbit/nuxt-precompress
- Homepage: https://github.com/frenchrabbit/nuxt-precompress#readme
- Issues: https://github.com/frenchrabbit/nuxt-precompress/issues
- npm.io page: https://npm.io/package/nuxt-precompress

## Dependencies (2)

- [consola](https://npm.io/package/consola.md) ^2.3.2
- [compression-webpack-plugin](https://npm.io/package/compression-webpack-plugin.md) ^4.0.1

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 0.5.9 (latest) — 2021-05-06
- 0.5.8 — 2021-03-25
- 0.5.7 — 2021-03-25
- 0.5.2 — 2020-08-18
- 0.5.1 — 2020-08-15
- 0.4.5 — 2020-08-15
- 0.4.9 — 2020-07-30
- 0.4.1 — 2020-04-18
- 0.4.0 — 2020-04-12
- 0.3.9 — 2020-04-11
- 0.3.8 — 2020-04-11
- 0.3.7 — 2020-04-11
- 0.3.6 — 2020-04-11
- 0.3.5 — 2020-04-11

## README

# Precompress files to gzip and brotli and serve them automatically

This may increase performance of your nuxt application:

Compress files to gzip and brotli at build-time,
And serve them if browser supports them.

### Please note:  
This module uses [compression-webpack-plugin](https://github.com/webpack-contrib/compression-webpack-plugin) for gzip and brotli.
compression-webpack-plugin support brotli based on [native nodejs support](https://nodejs.org/api/zlib.html#zlib_zlib_createbrotlicompress_options) added in 11.7.0, 
so if you use lower nodejs version, this module will make only gzip version for you, 
but will serve brotli as well if they exist.  

Module does not override render.compressor option, so it compress only build static files /.nuxt/dist/client/.


## Installation

```bash
$ yarn add nuxt-precompress # or npm install
```

## Usage

As usual, add to modules section, not buildModules because of middleware using
set options, if needed, this are defaults:

```javascript
// nuxt.config.js
export default {
  // ...
  modules: ['nuxt-precompress'],
  // Default options, override if needed
  nuxtPrecompress: {
    enabled: true, // Enable in production
    report: false, // set true to turn one console messages during module init
    test: /\.(js|css|html|txt|xml|svg)$/, // files to compress on build
    // Serving options
    middleware: {
      // You can disable middleware if you serve static files using nginx...
      enabled: true,
      // Enable if you have .gz or .br files in /static/ folder
      enabledStatic: true, 
      // Priority of content-encodings, first matched with request Accept-Encoding will me served
      encodingsPriority: ['br', 'gzip'],
    },
 
    // build time compression settings
    gzip: {
      // should compress to gzip?
      enabled: true,
      // compression config
      // https://www.npmjs.com/package/compression-webpack-plugin
      filename: '[path].gz[query]', // middleware will look for this filename
      threshold: 10240,
      minRatio: 0.8,
      compressionOptions: { level: 9 },
    },
    brotli: {
      // should compress to brotli?
      enabled: true,
      // compression config
      // https://www.npmjs.com/package/compression-webpack-plugin
      filename: '[path].br[query]', // middleware will look for this filename
      compressionOptions: { level: 11 },
      threshold: 10240,
      minRatio: 0.8,
    },
  }
  // ...
}
```


## Development

```bash
$ git clone https://github.com/frenchrabbit/nuxt-precompress.git
$ cd nuxt-precompress
$ yarn
```

## License

## Note

This project generated by [create-nuxt-module](https://github.com/potato4d/create-nuxt-module)

---
_Source: https://npm.io/package/nuxt-precompress · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
