Use prettier to format the HTML before saving

This commit is contained in:
pfych 2025-04-05 17:11:40 +11:00
parent 15b5236e2e
commit 6c0f9f5e7c
2 changed files with 6 additions and 3 deletions

View File

@ -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": [],

View File

@ -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(
<Root title="My App" stylePaths={stylePaths} scriptPaths={[]}>
{html}
</Root>,
{ parser: 'html' },
);
writeFileSync(outputHtmlPath, formattedHtml);
}),
);