metalsmith-gzip
A Metalsmith plugin to compress build files with gzip.
Last updated 5 years ago by ludovicofischer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metalsmith-gzip 
SYNC missed versions from official npm registry.

metalsmith-gzip Build Status

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}
  })); // only compresses JavaScript and CSS

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.

Current Tags

  • 1.1.0                                ...           latest (5 years ago)

5 Versions

  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |