0.1.5 • Published 3 months ago

hexo-lightning-minify v0.1.5

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
-
Last release
3 months ago

hexo-lightning-minify

WIP 中文版本

Introduction

This plugin is a minifier module split from hexo-renderer-multi-next-markdown-it. Based on more modern minifiers (such as lightningcss and minify-html), it significantly improves speed compared to the older version.

If you need more comprehensive optimization, you can try hexo-optimize. This project is more inclined to exist as a supporting package for ShokaX, thus it only provides basic minification and optimization functions.

Installation

pnpm add hexo-lightning-minify # Recommended to use pnpm
npm install hexo-lightning-minify

Configuration

minify:
  js:
    enable: true # ShokaX comes with esbuild optimization, not recommended to enable. Recommended for other themes.
    exclude: # Exclude files, accept string[], must match micromatch format
  css:
    enable: true # Enable CSS optimization
    options:
      targets: ">= 0.5%" # browserslist format target
    exclude: # Exclude files, accept string[], must match micromatch format
  html:
    minifier: html-minifier # minify-html(faster) or html-minifier(more stable)
    enable: true # Enable HTML optimization
    options:
      comments: false # Whether to preserve comment content
    exclude: # Exclude files, accept string[], must match micromatch format
  image:
    enable: true # Enable image preprocessing and automatic WebP conversion(hexo d)
    options:
      avif: false
      webp: true # Reserved configuration item, no effect in the current version
      quality: 80 # Quality, supports integers from 1-100, lossless, or nearLossless
      effort: 2 # CPU effort, an integer between 0 and 6 (lower for faster)
      replaceSrc: true # Automatically replace local image links in generated HTML with WebP links
      # We recommend using a Service Worker to implement the replaceSrc functionality on the user side, which will enable link replacement in a less intrusive manner.
    exclude:

Features

  • Automatically minify js, css, and html
  • Automatically handle CSS prefix compatibility based on targets
  • Automatic webp conversion and image preprocessing
  • Automatic pre-connection optimization (long term)

Comparison

On ShokaX v0.3.9: \ When run hexo ghexo-lightning-minify runs ~1.88x faster than HRMNMI(HRMMIR),~1.3x faster than hexo-neat

based on hexo-many-posts test:

with Hexo 6.3.0, only test the compression of html, css and js.

basehexo-neathexo-minifyhexo-all-minifierhexo-lightning-minify
landscape10.529s37.918s36.844s38.572s16.304s
next27.275s36.124s42.854s37.063s29.880s
butterfly13.853s26.641s26.736s35.973s16.796s
particlex24.422s200.641s193.981s201.601s40.478s
reimu17.631s52.432s48.524s51.835s23.938s
shokax(hexo-renderer-marked)13.189s20.618s19.658s22.448s14.619s

chart1

basehexo-neathexo-minifyhexo-all-minifierhexo-lightning-minify
landscape99,617,529B97,186,156B92,010,232B97,184,707B88,175,339B
next32,469,157B30,087,003B28,744,583B30,059,443B28,020,740B
butterfly37,593,633B37,237,074B33,485,597B34,897,171B35,504,670B
particlex540,876,348B226,997,833B214,050,994B226,990,791B221,896,130B
reimu110,252,086B95,756,049B91,074,639B95,715,486B88,088,009B
shokax(hexo-renderer-marked)142,585,026B142,404,138B140,988,094B142,011,849B140,457,331B

The hexo-theme-particlex has been removed from the chart for a clearer comparison.

chart2