Go to file
curbengh 9d6b72422b
refactor(test): utilize Buffer.equals
- instead of binary-base64 conversion
- https://jestjs.io/docs/en/expect#toequalvalue
2019-12-28 08:42:14 +00:00
lib feat: rename 'logger:' option to 'verbose:' 2019-12-27 22:54:09 +00:00
test refactor(test): utilize Buffer.equals 2019-12-28 08:42:14 +00:00
.gitignore test: add tests for html, js, css minifiers 2019-12-26 13:19:39 +00:00
.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 ci: avoid running snyk in PR 2019-12-26 13:32:14 +00:00
LICENSE chore: update username 2019-07-18 17:34:26 +09:30
README.md docs: 'logger:', compression level, 'basename' globOptions 2019-12-28 01:12:40 +00:00
index.js feat: rename 'logger:' option to 'verbose:' 2019-12-27 22:54:09 +00:00
package.json chore: requires at least Node 10.18 2019-12-27 08:00:16 +00:00

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.

Version 4

In v4, logger: option has been renamed to verbose:

Example:

minify:
  html:
    logger: true

needs to be updated to

minify:
  html:
    verbose: true

Installation

$ npm install hexo-yam --save

Options

minify:
  enable: true
  • enable - Enable the plugin. Defaults to true.

minify:
  html:
    enable: true
    exclude:
  • enable - Enable the plugin. Defaults to true.
  • priority - Plugin's priority. Defaults to 10. Set lower value to set higher priority and vice versa.
  • verbose - Verbose output. Defaults to false.
  • exclude - Exclude files.
    • Support one-liner, exclude: [*.min.html, *.note.html].
    • Test glob pattern on the web using Globtester.
  • globOptions - micromatch options to customise how glob patterns match files.
    • Defaults to { basename: true }, unless the pattern has a slash.
      • basename is disabled depending on each pattern.
      • When specifying an array of patterns, e.g. exclude: ['*foo.html', '**/bar.html'], basename applies to '*foo.html', but not '**/bar.html'.
      • basename would stay disabled, if explicitly disabled in globOptions:.
      • However, basename option applies to all patterns in include:

For more options, see HTMLMinifier.


minify:
  css:
    enable: true
    exclude:
      - '*.min.css'
  • enable - Enable the plugin. Defaults to true.
  • priority - Plugin's priority. Defaults to 10.
  • verbose - Verbose output. Defaults to false.
  • exclude - Exclude files. Support wildcard pattern.
  • level - Optimization level. Defaults to 2.
  • globOptions - See html:.

For more options, see clean-css.


minify:
  js:
    enable: true
    exclude:
      - '*.min.js'
  • enable - Enable the plugin. Defaults to true.
  • priority - Plugin's priority. Defaults to 10.
  • verbose - 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 - See html:.

For more options, see Terser.


minify:
  svg:
    enable: true
    include:
      - '*.svg'
      - '!*.min.svg'
  • enable - Enable the plugin. Defaults to true.
  • priority - Plugin's priority. Defaults to 10.
  • verbose - 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}].
    • For more options, see svgo.
  • globOptions - See html:.

minify:
  gzip:
    enable: true
    include:
      - '*.html'
      - '*.css'
      - '*.js'
      - '*.txt'
      - '*.ttf'
      - '*.atom'
      - '*.stl'
      - '*.xml'
      - '*.svg'
      - '*.eot'
      - '*.json'
  • enable - Enable the plugin. Defaults to true.
  • priority - Plugin's priority. Defaults to 10.
  • verbose - 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 - See html:.
  • level - Compression level; lower value may results in faster compression but slightly larger (compressed) file. Range 1-9. Defaults to 9, or the value of zlib.constants.Z_BEST_COMPRESSION

minify:
  brotli:
    enable: true
    include:
      - '*.html'
      - '*.css'
      - '*.js'
      - '*.txt'
      - '*.ttf'
      - '*.atom'
      - '*.stl'
      - '*.xml'
      - '*.svg'
      - '*.eot'
      - '*.json'
  • enable - Enable the plugin. Defaults to true.
  • priority - Plugin's priority. Defaults to 10.
  • verbose - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern.
  • globOptions - See html:.
  • level - Compression level. Range 1-11. Defaults to 11, or the value of zlib.constants.BROTLI_MAX_QUALITY

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
Hexo Server In progress

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: