Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ updates:
- 'recma-*'
compiling:
patterns:
- '@minify-html/wasm'
- '@swc/html-wasm'
- '@rollup/*'
- 'rolldown'
- 'lightningcss-wasm'
Expand Down
33 changes: 17 additions & 16 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"dependencies": {
"@actions/core": "^3.0.0",
"@heroicons/react": "^2.2.0",
"@minify-html/wasm": "^0.18.1",
"@node-core/rehype-shiki": "^1.4.0",
"@node-core/ui-components": "^1.6.0",
"@orama/orama": "^3.1.18",
"@orama/ui": "^1.5.4",
"@rollup/plugin-virtual": "^3.0.2",
"@swc/html-wasm": "^1.15.17",
"acorn": "^8.15.0",
"commander": "^14.0.3",
"dedent": "^1.7.1",
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-html-all/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function generate(input) {
});

if (config.minify) {
result = Buffer.from(await minifyHTML(result));
result = await minifyHTML(result);
}

if (config.output) {
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-html/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function* generate(input, worker) {
let result = replaceTemplateValues(apiTemplate, template, config);

if (config.minify) {
result = Buffer.from(await minifyHTML(result));
result = await minifyHTML(result);
}

await writeFile(join(config.output, `${template.api}.html`), result);
Expand Down
5 changes: 1 addition & 4 deletions src/generators/web/utils/processing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ export async function processJSXEntries(
.replace('{{speculationRules}}', SPECULATION_RULES)
.replace('{{ogTitle}}', title);

const minifiedHtml = await minifyHTML(renderedHtml);
const html = Buffer.from(minifiedHtml);

return { html, api };
return { html: await minifyHTML(renderedHtml), api };
})
);

Expand Down
30 changes: 13 additions & 17 deletions src/utils/html-minifier.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { minify } from '@minify-html/wasm';
import { readFile } from 'node:fs/promises';

const DEFAULT_HTML_MINIFIER_OPTIONS = {
minify_css: true,
minify_js: true,
};
import { minify, default as initSync } from '@swc/html-wasm';

const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
// See https://github.com/swc-project/swc/issues/11599 for why we need to load
// the WASM file in this way
await initSync(
Copy link
Member

Choose a reason for hiding this comment

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

Let's lock this PR till upstream gets fixed

readFile(new URL(import.meta.resolve('@swc/html-wasm/wasm_bg.wasm')))
);
Comment on lines +5 to +9
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

This module performs filesystem I/O and WASM initialization at import time via top-level await initSync(...). Since minifyHTML is imported unconditionally in generators even when config.minify is false, this can add startup latency and introduce failure modes in code paths that never actually minify. Consider lazy-initializing on the first minifyHTML() call (cache an init promise/flag) so the cost is only paid when minification is enabled.

Copilot uses AI. Check for mistakes.

/**
* Minifies HTML with project defaults and optional overrides.
* Minifies HTML with project defaults and optional overrides. At the moment,
* swc's defaults are suitable for our needs, but in the event that this changes,
* allowing project defaults is beneficial.
*
* @param {string} html
* @param {Record<string, boolean | number | string | string[]>} [overrides]
* @param {import('@swc/html-wasm').Options} [options]
*/
export const minifyHTML = async (html, overrides = {}) => {
const minified = minify(textEncoder.encode(html), {
...DEFAULT_HTML_MINIFIER_OPTIONS,
...overrides,
});

return textDecoder.decode(minified);
};
export const minifyHTML = async (html, options = {}) =>
(await minify(html, options)).code;
Loading