From 7703659f81effecaac71c70ef6100c55ce9f890b Mon Sep 17 00:00:00 2001 From: Hellings Date: Fri, 23 Oct 2026 09:12:49 -0400 Subject: [PATCH] better formatting --- README.md | 2 +- index.ts | 44 +++++++++++++++++++++++++++++++++++--------- package.json | 30 +++++++++++++++--------------- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index da43184..93515bf 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# Build optimization \ No newline at end of file +# Build optimization diff --git a/index.ts b/index.ts index 6e42db8..69a093c 100644 --- a/index.ts +++ b/index.ts @@ -19,9 +19,11 @@ export async function minifyHtml(source: string): Promise { }); } - export async function minifyJavaScript(source: string): Promise { - return (await terser.minify(source, { format: { comments: false } })).code ?? source; + return ( + (await terser.minify(source, { format: { comments: false } })).code ?? + source + ); } export function optimizeSvg(source: string): string { @@ -36,16 +38,29 @@ export function imageOptimization(optimizer: ImageOptimizer): ImageOptimizer { return optimizer; } -function loaderIntegration(name: string, extension: string, transform: (source: string) => string | Promise): Integration { +function loaderIntegration( + name: string, + extension: string, + transform: (source: string) => string | Promise, +): Integration { return { name, async transform(asset) { if (!asset.path.endsWith(extension)) return asset; - const source = typeof asset.content === "string" ? asset.content : new TextDecoder().decode(asset.content); + const source = + typeof asset.content === "string" + ? asset.content + : new TextDecoder().decode(asset.content); return { ...asset, content: await transform(source) }; }, setup(context: IntegrationContext) { - context.loader(name, { name, extensions: [extension], async load(file) { return { data: {}, content: await transform(file.source) }; } }); + context.loader(name, { + name, + extensions: [extension], + async load(file) { + return { data: {}, content: await transform(file.source) }; + }, + }); }, }; } @@ -66,20 +81,31 @@ export function svgoIntegration(): Integration { return loaderIntegration("svgo", ".svg", optimizeSvg); } -export function imageOptimizationIntegration(optimizer: ImageOptimizer): Integration { +export function imageOptimizationIntegration( + optimizer: ImageOptimizer, +): Integration { return { name: "image-optimization", async transform(asset) { if (!/\.(png|jpe?g|webp|avif)$/i.test(asset.path)) return asset; - const input = typeof asset.content === "string" ? new TextEncoder().encode(asset.content) : asset.content; - return { ...asset, content: await optimizer.optimize(input, asset.contentType) }; + const input = + typeof asset.content === "string" + ? new TextEncoder().encode(asset.content) + : asset.content; + return { + ...asset, + content: await optimizer.optimize(input, asset.contentType), + }; }, setup(context: IntegrationContext) { context.loader("image", { name: "image", extensions: [".png", ".jpg", ".jpeg", ".webp", ".avif"], async load(file) { - const optimized = await optimizer.optimize(new TextEncoder().encode(file.source), "image/*"); + const optimized = await optimizer.optimize( + new TextEncoder().encode(file.source), + "image/*", + ); return { data: { optimized }, content: file.source }; }, }); diff --git a/package.json b/package.json index 175d648..e36f9de 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ { - "name": "@muddle/optimize", - "version": "0.1.0", - "type": "module", - "exports": "./index.ts", - "dependencies": { - "terser": "^5.51.2", - "svgo": "^4.1.0", - "csso": "^5.0.5", - "html-minifier-terser": "^7.2.0", - "@types/csso": "^5.0.5", - "@types/html-minifier-terser": "^7.0.2" - }, - "peerDependencies": { - "muddle": "*" - } + "name": "@muddle/optimize", + "version": "0.1.0", + "type": "module", + "exports": "./index.ts", + "dependencies": { + "terser": "^5.51.2", + "svgo": "^4.1.0", + "csso": "^5.0.5", + "html-minifier-terser": "^7.2.0", + "@types/csso": "^5.0.5", + "@types/html-minifier-terser": "^7.0.2" + }, + "peerDependencies": { + "muddle": "*" + } }