Socket
Socket
Sign inDemoInstall

metalsmith-gzip

Package Overview
Dependencies
36
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    metalsmith-gzip

A Metalsmith plugin to compress build files with gzip.


Version published
Weekly downloads
48
Maintainers
1
Install size
9.26 kB
Created
Weekly downloads
 

Changelog

Source

2.0.0 ##

  • Add debug log with original and compressed file size
  • Take advantage of metalsmith's built-in match
  • Raise minimum required Node.js version to 18.12.0

Readme

Source

metalsmith-gzip

A Metalsmith plugin that creates gzipped copies of the site's content. This is useful for website hosting on Amazon S3, where on the fly compression in the server is impossible.

Installation

$ npm install metalsmith-gzip

Usage

var Metalsmith = require('metalsmith');
var compress = require('metalsmith-gzip');

var metalsmith = new Metalsmith(__dirname)
  .use(compress());

metalsmith-gzip will gzip a file if the extension matches this regular expression:

/\.[html|css|js|json|xml|svg|txt]/

The choice of files to compress is loosely based on the HTML5 Boilerplate server configuration.

Customization

Pass an options object to customize metalsmith-gzip behaviour. These are the available options keys:

src is a multimatch pattern which specifies which types of files to compress.

var metalsmith = new Metalsmith(__dirname)
  .use(compress({src: ['**/*.js', '**/*.css']})); // only compresses JavaScript and CSS

gzip is the same configuration object accepted by zlib.createGzip (http://nodejs.org/api/zlib.html#zlib_options). For example, you can set the compression level:

var metalsmith = new Metalsmith(__dirname)
  .use(compress({
    src: ['**/*.js', '**/*.css'],
    gzip: {level: 6}
}));

Add overwrite: true to replace files with the compressed version instead of creating a copy with the '.gz' extension:

var metalsmith = new Metalsmith(__dirname)
  .use(compress({overwrite: true});

Deployment

You need to create a script to upload the gzipped versions of the files to your preferred hosting provider yourself. Take care to serve the files with the correct Content-Encoding.

Acknowledgements

This plugin was inspired by the Middleman gzip extension.

Keywords

FAQs

Last updated on 08 Oct 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc