hexo-yam/README.md

109 lines
4.7 KiB
Markdown
Raw Normal View History

# Hexo-yam
2016-06-23 05:27:24 +00:00
2018-09-27 07:13:18 +00:00
[![npm version](https://badge.fury.io/js/hexo-yam.svg)](https://www.npmjs.com/package/hexo-yam)
2018-09-27 07:49:26 +00:00
[![Build Status](https://travis-ci.com/weyusi/hexo-yam.svg?branch=master)](https://travis-ci.com/weyusi/hexo-yam)
2018-09-27 07:13:18 +00:00
[![NPM Dependencies](https://david-dm.org/weyusi/hexo-yam.svg)](https://david-dm.org/weyusi/hexo-yam)
2018-09-28 02:24:17 +00:00
[![Known Vulnerabilities](https://snyk.io/test/npm/hexo-yam/badge.svg)](https://snyk.io/test/npm/hexo-yam)
[![Greenkeeper badge](https://badges.greenkeeper.io/weyusi/hexo-yam.svg)](https://greenkeeper.io/)
2018-09-27 07:13:18 +00:00
> This project is based on [hexo-neat](https://github.com/rozbo/hexo-neat)
2019-04-22 09:12:30 +00:00
Yet Another Minifier for Hexo. Minify and compress html, js and css. xml, json and [many more](https://github.com/weyusi/hexo-yam/blob/master/lib/filter.js#L105) are also compressed. Support gzip and [brotli](https://en.wikipedia.org/wiki/Brotli) [compressions](https://en.wikipedia.org/wiki/HTTP_compression).
The original package has not been [updated](https://www.npmjs.com/package/hexo-neat) for a while. I update the [dependencies](https://github.com/weyusi/hexo-yam/blob/master/package.json) and add compression support.
2016-05-26 11:09:41 +00:00
All the options are the same, so you can use this as a drop-in replacement.
2016-05-26 11:09:41 +00:00
2018-11-02 10:29:00 +00:00
*Note:* See [HTTP Compression](#http-compression) section below for more info on using brotli.
2016-05-26 11:09:41 +00:00
## Installation
``` bash
$ npm install hexo-yam --save
2016-05-26 11:09:41 +00:00
```
## Usage
To enable this plugin, insert the following to `_config.yml`:
2016-05-26 11:09:41 +00:00
``` yaml
2016-05-26 11:23:57 +00:00
neat_enable: true
```
For further customization, see below.
2016-05-26 11:23:57 +00:00
## Options
2016-05-26 11:23:57 +00:00
``` yaml
neat_html:
2016-05-26 11:09:41 +00:00
enable: true
2016-06-23 05:27:24 +00:00
exclude:
2016-05-26 11:09:41 +00:00
```
- **enable** - Enable the plugin. Defaults to `true`.
2018-10-25 10:14:33 +00:00
- **logger** - Verbose output. Defaults to `false`.
- **exclude** - Exclude files
2018-10-26 05:06:58 +00:00
For more options, see [HTMLMinifier](https://github.com/kangax/html-minifier).
2016-05-26 11:09:41 +00:00
----------
``` yaml
2016-05-26 11:23:57 +00:00
neat_css:
2016-05-26 11:09:41 +00:00
enable: true
2016-06-23 05:27:24 +00:00
exclude:
2016-05-26 11:09:41 +00:00
- '*.min.css'
```
- **enable** - Enable the plugin. Defaults to `true`.
2018-10-25 10:14:33 +00:00
- **logger** - Verbose output. Defaults to `false`.
- **exclude** - Exclude files
2016-05-26 11:09:41 +00:00
----------
``` yaml
2016-05-26 11:23:57 +00:00
neat_js:
2016-05-26 11:09:41 +00:00
enable: true
2016-06-23 05:27:24 +00:00
exclude:
2016-05-26 11:09:41 +00:00
- '*.min.js'
```
- **enable** - Enable the plugin. Defaults to `true`.
2018-10-25 10:14:33 +00:00
- **mangle** - Mangle file names. Defaults to `true`.
- **logger** - Verbose output. Defaults to `false`.
- **output** - Output options
- **compress** - Compress options
- **exclude** - Exclude files
2018-10-26 05:06:58 +00:00
For more options, see [UglifyJS](https://github.com/mishoo/UglifyJS2).
2016-05-26 11:09:41 +00:00
2018-09-28 07:43:54 +00:00
----------
``` yaml
2018-09-29 05:58:43 +00:00
neat_gzip:
2018-09-28 07:43:54 +00:00
enable: true
```
- **enable** - Enable the plugin. Defaults to `true`.
2018-10-25 10:14:33 +00:00
- **logger** - Verbose output. Defaults to `false`.
2016-05-26 11:09:41 +00:00
2018-09-30 07:30:32 +00:00
----------
``` yaml
neat_brotli:
enable: true
```
- **enable** - Enable the plugin. Defaults to `true`.
2018-10-25 10:14:33 +00:00
- **logger** - Verbose output. Defaults to `false`.
2018-09-30 07:30:32 +00:00
2018-11-02 10:29:00 +00:00
## HTTP Compression
2018-11-02 10:40:36 +00:00
While most modern web browsers [support](https://www.caniuse.com/#feat=brotli) Brotli, you also need to consider whether the web/app server, hosting platform, reverse proxy or CDN (whichever relevant to you) support it.
As of 2018, GitHub/GitLab Pages and Netlify *do not* support brotli. You can generate `.br` files, but they won't be serving those files.
2018-11-02 10:29:00 +00:00
If you have access to the web server config, you should disable on-the-fly compression for static files (that are already compressed by this plugin), e.g.
- [nginx](https://github.com/google/ngx_brotli): Make sure both filter and static modules are enabled. This way pre-compressed `.br` files will be served while dynamic content can be compressed on-the-fly. Protip: `brotli_types text/plain text/css application/javascript application/json image/svg+xml application/xml+rss;` to prevent compressing media files (which are already compressed anyway).
- [Apache](https://httpd.apache.org/docs/2.4/en/mod/mod_brotli.html): See 'Serving pre-compressed content' section of [mod_brotli](https://httpd.apache.org/docs/2.4/en/mod/mod_brotli.html).
- [Caddy](https://caddyserver.com/features): [0.9.4+](https://caddyserver.com/blog/caddy-0_9_4-released) by default support pre-compressed `.gz` `.br` files and on-the-fly gzip compress dynamic files.
- [express](https://github.com/expressjs/express)/[connect](https://github.com/senchalabs/connect): Use [pre-compressed-assets](https://github.com/domadams/pre-compressed-assets). You still can continue to use [compression](https://github.com/expressjs/compression)/[shrink-ray-current](https://github.com/Alorel/shrink-ray) for dynamic files.
## Credits
All credits go to the following work:
- [hexo-neat](https://github.com/rozbo/hexo-neat) by rozbo
2016-05-26 11:23:57 +00:00
- neat html by [HTMLMinifier](https://github.com/kangax/html-minifier)
- neat css by [clean-css](https://github.com/jakubpawlowicz/clean-css)
2019-04-10 10:04:43 +00:00
- neat js by [terser](https://github.com/terser-js/terser)
- gzip feature is inspired by [hexo-generator-optimize](https://github.com/JackyRen/hexo-generator-optimize)