Skip to content

Change html-minify package#48

Merged
danielsitek merged 3 commits intomasterfrom
feature/ds-change-html-minify-package
Dec 8, 2025
Merged

Change html-minify package#48
danielsitek merged 3 commits intomasterfrom
feature/ds-change-html-minify-package

Conversation

@danielsitek
Copy link
Copy Markdown
Owner

@danielsitek danielsitek commented Dec 8, 2025

This pull request updates the HTML minification logic to use a new library and adapts the code to match the new API. The main change is switching from html-minifier-next to @minify-html/node, which requires updates to both the dependency list and the minification function implementation.

Dependency update:

  • Replaced the html-minifier-next dependency with @minify-html/node in package.json.

Minification logic refactor:

  • Updated the import and usage in src/minify/minifyContents.ts to use @minify-html/node's API, including converting the input to a Buffer and adjusting option names to match the new library.
  • Renamed the minification function from minifyHtml to minifyContentsHtml and updated its usage in the main minifyContents function.

Summary by CodeRabbit

  • Chores
    • Updated HTML minification library to the latest version.

✏️ Tip: You can customize this high-level summary in your review settings.

@danielsitek danielsitek self-assigned this Dec 8, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 8, 2025

Walkthrough

The pull request replaces the HTML minifier dependency from html-minifier-next to @minify-html/node and updates the minification implementation to use a new internal helper function that handles the library's API requirements, maintaining the same public interface.

Changes

Cohort / File(s) Summary
Dependency update
package.json
Replaces html-minifier-next@4.7.0 with @minify-html/node@0.18.1 in dependencies.
Minification implementation
src/minify/minifyContents.ts
Introduces minifyContentsHtml internal helper to adapt to the new minifier's API (kebab-case options, Buffer input, string output conversion). Updates HTML path handling to route through the new helper while preserving the public minifyContents API.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the new minifier (@minify-html/node@0.18.1) produces equivalent or improved output quality compared to the previous implementation
  • Confirm the kebab-case option names (minify_css, minify_js) are correct for the new library
  • Check Buffer-to-string conversion handling to ensure no encoding issues

Possibly related PRs

  • Update dependencies #46: Both PRs modify src/minify/minifyContents.ts to replace the HTML minifier library and update minification implementation with adapted API calls.

Poem

🐰 A minifier hops to a swifter stride,
Trading old tools for new ones tried,
Buffer to string, kebab-case leads,
Leaner HTML is all we need! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Change html-minify package' directly describes the main change: replacing the HTML minification dependency from html-minifier-next to @minify-html/node.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/ds-change-html-minify-package

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package.json (1)

58-63: New minifier dependency looks good; remove stale html-minifier-next types

@minify-html/node@0.18.1 is correctly integrated—verified usage at src/minify/minifyContents.ts with the documented Node API (minifyHtml.minify(Buffer.from(...), { ... })).

@types/html-minifier-next is stale and can be safely removed from devDependencies. No references to the old html-minifier-next package remain anywhere in the codebase.

🧹 Nitpick comments (2)
src/minify/minifyContents.ts (2)

1-9: Helper wraps @minify-html/node correctly; a couple of optional cleanups

The switch to @minify-html/node looks correct: using the default import, passing a Buffer plus snake_case options, and then converting the result back to a string all match the library’s documented pattern. (github.com)

Two small, non-blocking tweaks you might consider:

  • minifyHtml.minify is synchronous, so you don’t strictly need async/await in minifyContentsHtml; a plain sync helper keeps the types a bit simpler.
  • Importing Buffer explicitly (import { Buffer } from "node:buffer";) avoids relying on the global and makes the dependency on Node’s Buffer API clearer.

For example:

-import minifyHtml from "@minify-html/node";
-
-const minifyContentsHtml = async (contents: string): Promise<string> => {
-    const minified = await minifyHtml.minify(Buffer.from(contents), {
+import { Buffer } from "node:buffer";
+import minifyHtml from "@minify-html/node";
+
+const minifyContentsHtml = (contents: string): string => {
+    const minified = minifyHtml.minify(Buffer.from(contents), {
         minify_css: true,
         minify_js: true,
     });
-
-    return minified.toString();
-};
+    return minified.toString();
+};

18-22: Confirm new minifier’s defaults (whitespace, comments, templates) match expectations

@minify-html/node has different defaults and a more aggressive minification strategy than html-minifier-next (especially around whitespace and comment handling), and you’re currently only tweaking minify_css and minify_js while leaving other options at their defaults. (github.com)

I’d recommend running a build (e.g. your example project) and diffing the generated HTML against the previous version to catch any regressions in whitespace‑sensitive or templated files; if needed, you can adjust options such as keep_comments, keep_spaces_between_attributes, or the various preserve_*_template_syntax flags to better mirror prior behaviour. (github.com)

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4228271 and 0f2fd0d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/minify/minifyContents.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

@danielsitek danielsitek merged commit bff4d2f into master Dec 8, 2025
11 checks passed
@danielsitek danielsitek deleted the feature/ds-change-html-minify-package branch December 8, 2025 12:24
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.

1 participant