From 6c0f9f5e7c158a651ee635a92eefaa112f878155 Mon Sep 17 00:00:00 2001 From: pfych Date: Sat, 5 Apr 2025 17:11:40 +1100 Subject: [PATCH] Use prettier to format the HTML before saving --- package.json | 2 +- ssg/build.tsx | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6019cab..555a2a3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "compile": "esbuild ssg/build.tsx --bundle --outfile=.tmp/ssg/build.js --jsx-import-source=@kitajs/html --minify --sourcemap --platform=node --external:esbuild", + "compile": "esbuild ssg/build.tsx --bundle --outfile=.tmp/ssg/build.js --jsx-import-source=@kitajs/html --minify --sourcemap --platform=node --external:esbuild --external:prettier", "buld": "npm run compile && node .tmp/ssg/build.js" }, "keywords": [], diff --git a/ssg/build.tsx b/ssg/build.tsx index 78a757a..3693d49 100644 --- a/ssg/build.tsx +++ b/ssg/build.tsx @@ -4,6 +4,7 @@ import { mkdirSync, writeFileSync, rmSync } from 'node:fs'; import { sassPlugin } from 'esbuild-sass-plugin'; import Root from './root'; import { getPaths, getStylePath, outDir } from './utils'; +import { format } from 'prettier'; mkdirSync(outDir, { recursive: true }); @@ -38,12 +39,14 @@ void (async () => { const html = Page.default(); let stylePaths: string[] = getStylePath(tmpJsPath, outputHtmlPath); - writeFileSync( - outputHtmlPath, + const formattedHtml = await format( {html} , + { parser: 'html' }, ); + + writeFileSync(outputHtmlPath, formattedHtml); }), );