项目作者: curbengh

项目描述 :
Yet Another Minifier. Minify and compress HTML, JS, CSS, SVG, XML and JSON.
高级语言: JavaScript
项目地址: git://github.com/curbengh/hexo-yam.git
创建时间: 2018-09-27T01:44:39Z
项目社区:https://github.com/curbengh/hexo-yam

开源协议:MIT License

下载


hexo-yam

npm version
Build Status
codecov
NPM Dependencies
Known Vulnerabilities

Yet Another Minifier for Hexo. Minify HTML, JS, CSS, SVG, XML and JSON. Compress static web assets using gzip, brotli and zstd.

Table of contents

Installation

  1. $ npm install --save hexo-yam

Options

  1. minify:
  2. enable: true
  3. previewServer: true
  4. html:
  5. css:
  6. js:
  7. svg:
  8. gzip:
  9. brotli:
  10. xml:
  11. json:
  • enable - Enable the plugin. Defaults to true.
  • previewServer - Disable the plugin when running hexo server. Defaults to true.
  • html - See HTML section
  • css - See CSS section
  • js - See JS section
  • svg - See SVG section
  • gzip - See Gzip section
  • brotli - See Brotli section
  • xml - See XML section
  • json - See JSON section

HTML

  1. minify:
  2. html:
  3. enable: true
  4. 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 wildcard pattern(s) in a string or array.
  • globOptions - See globbing section.

For more options, see HTMLMinifier.

CSS

  1. minify:
  2. css:
  3. enable: true
  4. exclude:
  5. - "*.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(s) in a string or array.
  • level - Optimization level. Defaults to 2.
  • globOptions - See globbing section.

For more options, see clean-css.

JS

  1. minify:
  2. js:
  3. enable: true
  4. exclude:
  5. - "*.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(s) in a string or array.
  • 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 globbing section.

For more options, see Terser.

SVG

  1. minify:
  2. svg:
  3. enable: true
  4. include:
  5. - "*.svg"
  6. - "!*.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(s) in a string or array.
    • Exclude *.min.svg by default.
  • plugins - Plugin options.
    • Examples:
      1. plugins:
      2. # Retain comments
      3. removeComments: false
      4. # Do not remove unused ID attributes
      5. cleanupIds: false
    • For more options, see svgo.
  • globOptions - See globbing section.

XML

Remove whitespaces in xml.

  1. minify:
  2. xml:
  3. enable: false
  4. include:
  5. - "*.xml"
  6. - "!*.min.xml"
  • enable - Enable the plugin. Defaults to false.
  • priority - Plugin’s priority. Defaults to 10.
  • verbose - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern(s) in a string or array.
    • Exclude *.min.xml by default.
  • removeComments - Remove comments in xml. Defaults to true.
  • globOptions - See globbing section.

For more options, see minify-xml.

JSON

Remove whitespaces in json.

  1. minify:
  2. json:
  3. enable: false
  4. include:
  5. - "*.json"
  6. - "!*.min.json"
  • enable - Enable the plugin. Defaults to false.
  • priority - Plugin’s priority. Defaults to 10.
  • verbose - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern(s) in a string or array.
    • Exclude *.min.json by default.
  • globOptions - See globbing section.

Gzip

  1. minify:
  2. gzip:
  3. enable: true
  4. include:
  5. - "*.html"
  6. - "*.css"
  7. - "*.js"
  8. - "*.txt"
  9. - "*.ttf"
  10. - "*.atom"
  11. - "*.stl"
  12. - "*.xml"
  13. - "*.svg"
  14. - "*.eot"
  15. - "*.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(s) in a string or array.
    • Support one-liner, include: ['*.html','*.css','*.js'].
    • Must include asterisk and single quotes. .html is invalid. '*.html' is valid.
  • globOptions - See globbing section.
  • 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

Brotli

  1. minify:
  2. brotli:
  3. enable: true
  4. include:
  5. - "*.html"
  6. - "*.css"
  7. - "*.js"
  8. - "*.txt"
  9. - "*.ttf"
  10. - "*.atom"
  11. - "*.stl"
  12. - "*.xml"
  13. - "*.svg"
  14. - "*.eot"
  15. - "*.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(s) in a string or array.
  • globOptions - See globbing section.
  • level - Compression level. Range 1-11. Defaults to 11, or the value of zlib.constants.BROTLI_MAX_QUALITY

Zstd

  1. minify:
  2. zstd:
  3. enable: false
  4. include:
  5. - "*.html"
  6. - "*.css"
  7. - "*.js"
  8. - "*.txt"
  9. - "*.ttf"
  10. - "*.atom"
  11. - "*.stl"
  12. - "*.xml"
  13. - "*.svg"
  14. - "*.eot"
  15. - "*.json"
  • enable - Enable the plugin. Defaults to false.
  • priority - Plugin’s priority. Defaults to 10.
  • verbose - Verbose output. Defaults to false.
  • include - Include files. Support wildcard pattern(s) in a string or array.
  • globOptions - See globbing section.
  • level - Compression level. Range 1-22. Defaults to 3, or the value of DEFAULT_LEVEL

Cannot find module ‘@mongodb-js/zstd-linux-x64-gnu’

npm install --save @mongodb-js/zstd-linux-x64-gnu

Globbing

Use “globOptions” to customise how glob patterns match files. Refer to micromatch for available options.

  • basename is enabled by default, unless the pattern has a slash.
  • basename is disabled depending on each pattern.
  • This means the following options would work,
  1. exclude:
  2. - "*foo.html" # basename is enabled
  3. - "**/bar/*/*.html" # basename is automatically disabled
  4. - "*baz.css" # basename is enabled
  5. globOptions:
  6. basename: true # default
  • This behaviour doesn’t apply to pattern that starts with ! (negation).
  • This limitation only applies to include: option used in svg, gzip and brotli.
  • This means the following options would not work,
  1. include:
  2. - "!foo.svg"
  3. - "!**/bar/*/*.svg"
  4. globOptions:
  5. basename: true
  • basename will stay disabled, if explicitly disabled in “globOptions”.

Credits

All credits go to the following work: