Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions npm-shrinkwrap.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@orama/orama": "^3.1.18",
"@orama/ui": "^1.5.4",
"@rollup/plugin-virtual": "^3.0.2",
"@swc/html-wasm": "^1.15.18",
"acorn": "^8.16.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
26 changes: 7 additions & 19 deletions src/utils/html-minifier.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import { minify } from '@minify-html/wasm';

const DEFAULT_HTML_MINIFIER_OPTIONS = {
minify_css: true,
minify_js: true,
};

const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
import { minify } from '@swc/html-wasm';

/**
* 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;
Comment thread
avivkeller marked this conversation as resolved.
Resolved
Loading