Go to file
weyusi 5fac46455c test(snyk): remove nanomatch and add lodash 2019-07-10 12:14:21 +09:30
lib feat: switch nanomatch to micromatch 2019-07-10 11:50:23 +09:30
.gitignore Remove package-lock.json 2018-10-26 13:16:08 +10:30
.npmignore Update formatting 2018-09-27 16:31:14 +09:30
.npmrc chore: ignore optional deps 2019-06-22 14:22:08 +09:30
.snyk test(snyk): remove nanomatch and add lodash 2019-07-10 12:14:21 +09:30
.travis.yml test: update package.json to snyk in every build 2018-10-30 18:37:10 +10:30
LICENSE docs: add license 2019-05-13 16:51:06 +09:30
README.md docs: tidy up readme 2019-07-10 12:04:37 +09:30
index.js feat: switch nanomatch to micromatch 2019-07-10 11:50:23 +09:30
package.json feat: switch nanomatch to micromatch 2019-07-10 11:50:23 +09:30

README.md

Hexo-yam

npm version Build Status NPM Dependencies Known Vulnerabilities Greenkeeper badge


Yet Another Minifier for Hexo. Minify and compress HTML, JS, CSS and SVG. XML, JSON and many more are also compressed. Support gzip and brotli compressions.

This project is based on hexo-neat. Existing options are the same, so you can use this as a drop-in replacement.

Note: See HTTP Compression section below for more info on using brotli.

Installation

$ npm install hexo-yam --save

Usage

To enable this plugin, insert the following to _config.yml:

neat_enable: true

For further customization, see below.

Options

neat_html:
  enable: true
  exclude:
  • enable - Enable the plugin. Defaults to true.
  • logger - Verbose output. Defaults to false.
  • exclude - Exclude files.
    • Support one-liner, exclude: [*.min.html, *.note.html].
    • To exclude a file, double asterisk and the full path must be specified, **/themes/typing/source/js/source.js.
    • *source.js also works, but it also excludes resource.js.
    • Test glob pattern on the web using Globtester.
  • globOptions - micromatch options to customise how glob patterns match files. Defaults to { matchBase: true }.

For more options, see HTMLMinifier.


neat_css:
  enable: true
  exclude:
    - '*.min.css'
  • enable - Enable the plugin. Defaults to true.
  • logger - Verbose output. Defaults to false.
  • exclude - Exclude files. Support wildcard pattern.
  • level - Optimization level. Defaults to 2.
  • globOptions - micromatch options to customise how glob patterns match files. Defaults to { matchBase: true }.

For more options, see clean-css.


neat_js:
  enable: true
  exclude:
    - '*.min.js'
  • enable - Enable the plugin. Defaults to true.
  • logger - Verbose output. Defaults to false.
  • exclude - Exclude files. Support wildcard pattern.
  • compress - Compress options.
  • mangle - Mangle variable names. Defaults to true. Pass an object to specify mangle options.
  • output - Output options.
    • To retain comments, output: {comments: true}.
  • globOptions - micromatch options to customise how glob patterns match files. Defaults to { matchBase: true }.

For more options, see Terser.


neat_svg:
  enable: true
  include:
    - '*.svg'
    - '!*.min.svg'
  • enable - Enable the plugin. Defaults to true.
  • logger - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern.
    • Exclude *.min.svg by default.
  • plugins - Plugin options.
    • To retain comments, plugins: [{removeComments: false}].
  • globOptions - micromatch options to customise how glob patterns match files. Defaults to { matchBase: true }.

For more options, see svgo.


neat_gzip:
  enable: true
  include:
    - '*.html'
    - '*.css'
    - '*.js'
    - '*.txt'
    - '*.ttf'
    - '*.atom'
    - '*.stl'
    - '*.xml'
    - '*.svg'
    - '*.eot'
    - '*.json'
  • enable - Enable the plugin. Defaults to true.
  • logger - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern.
    • Support one-liner, include: ['*.html','*.css','*.js'].
    • Must include asterisk and single quotes. .html is invalid. '*.html' is valid.
  • globOptions - micromatch options to customise how glob patterns match files. Defaults to { matchBase: true }.

neat_brotli:
  enable: true
  include:
    - '*.html'
    - '*.css'
    - '*.js'
    - '*.txt'
    - '*.ttf'
    - '*.atom'
    - '*.stl'
    - '*.xml'
    - '*.svg'
    - '*.eot'
    - '*.json'
  • enable - Enable the plugin. Defaults to true.
  • logger - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern.
  • globOptions - micromatch options to customise how glob patterns match files. Defaults to { matchBase: true }.

HTTP Compression

While most modern web browsers support 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 May 2019, GitHub Pages, GitLab Pages and Netlify do not support brotli yet. You can generate .br files, but they won't serve those files.

Name Status (May 8, 2019)
GitHub Pages In consideration
GitLab Pages In progress
Netlify In consideration

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),

  • nginx: 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: See 'Serving pre-compressed content' section of mod_brotli.
  • Caddy: 0.9.4+ by default support pre-compressed .gz .br files and on-the-fly gzip compress dynamic files.
  • express/connect: Use pre-compressed-assets. You still can continue to use compression/shrink-ray-current for dynamic files.

Credits

All credits go to the following work: