Skip to content

Conversation

@stevenjoezhang
Copy link
Member

@stevenjoezhang stevenjoezhang commented Oct 12, 2025

Check list

  • Add test cases for the changes.
  • Passed the CI test.

Description

Issue resolved: #84
Issue resolved: #148

I managed to complete the migration, and the configuration options were almost entirely unaffected. Users can upgrade seamlessly without any noticeable changes.

Additional information

@tomap
Copy link
Contributor

tomap commented Oct 12, 2025

Looks good

@stevenjoezhang stevenjoezhang requested review from a team and Copilot November 5, 2025 06:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the package from using html-minifier to htmlnano as the HTML minification library. The change updates the minification engine while attempting to maintain compatibility with existing configuration options.

  • Replaced html-minifier with htmlnano and its dependencies (cssnano, postcss, svgo, terser)
  • Updated configuration options to match htmlnano's API (e.g., minifyJSminifyJs, minifyCSSminifyCss)
  • Converted the filter function to async and updated all tests accordingly

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
package.json Updated dependencies from html-minifier to htmlnano and added required peer dependencies
lib/filter.js Migrated from html-minifier to htmlnano, converted function to async, added custom comment filtering logic
index.js Updated default configuration options to match htmlnano's API
test/index.js Updated all tests to handle async filter function and adjusted expectations for htmlnano behavior
README.md Updated documentation to reflect new configuration options and removed trailing whitespace
.gitignore Added package-lock.json to ignore list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +16
delete options.exclude;
delete options.ignoreCustomComments;
delete options.removeComments;
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutating the config options object is dangerous. Since options is a reference to this.config.html_minifier, these deletions will permanently modify the configuration for subsequent calls. This will cause issues if the filter is invoked multiple times. Create a shallow copy of options before mutation: const options = { ...this.config.html_minifier };

Copilot uses AI. Check for mistakes.
stevenjoezhang and others added 2 commits November 5, 2025 14:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mimi <stevenjoezhang@gmail.com>
[![Build Status](https://github.com/hexojs/hexo-html-minifier/workflows/Tester/badge.svg)](https://github.com/hexojs/hexo-html-minifier/actions?query=workflow%3ATester)
[![NPM version](https://badge.fury.io/js/hexo-html-minifier.svg)](https://www.npmjs.com/package/hexo-html-minifier)

Minify HTML files with [HTMLMinifier](https://github.com/kangax/html-minifier).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to fix this link.

Copy link
Member

@yoshinorin yoshinorin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation appears to be slower compared to the current one. I tested with the following configuration (there should be no difference between the two):

# Current
html_minifier:  
  collapseBooleanAttributes: true
  collapseWhitespace: true
  ignoreCustomComments: [ !!js/regexp /^\s*more/]
  removeComments: true
  removeEmptyAttributes: true
  removeScriptTypeAttributes: true
  removeStyleLinkTypeAttributes: true
  minifyJS: true
  minifyCSS: true

# This PR
html_minifier:
  collapseBooleanAttributes: true
  collapseWhitespace: true
  ignoreCustomComments: [ !!js/regexp /^\s*more/]
  removeComments: true
  removeEmptyAttributes: true
  removeRedundantAttributes: true
  removeAttributeQuotes: true
  minifyJs: true
  minifyCss: true

I only tested with Cold Processing on Hexo 8.1.1, but when generating around 2000 articles, this PR seems to be approximately 1 to 1.5 minutes slower than the current implementation.

It's unclear whether the slowdown is caused by htmlnano itself or by something in this implementation, but this performance difference might not be acceptable for some users.

- **ignoreCustomComments**: Array of regex'es that allow to ignore certain comments, when matched. Need to prepend [`!!js/regexp`](https://github.com/nodeca/js-yaml#supported-yaml-types) to support regex.

Description of the above options and other available options, see [HTMLMinifier](https://github.com/kangax/html-minifier#options-quick-reference)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here.

removeRedundantAttributes: true
removeAttributeQuotes: true
minifyJs: true
minifyCss: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO:

We should provide a migration guide since the configuration has changed.

removeRedundantAttributes: true
removeAttributeQuotes: true
minifyJs: true
minifyCss: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should provide a migration guide since the configuration has changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maybe Replace html-minifier with htmlnano or html-minifier-terser due to security vulnerabilities [Proposal] Replace html-minifier with htmlnano

5 participants