chore: detail optimization

This commit is contained in:
vben
2020-10-14 21:08:07 +08:00
parent 7437896034
commit 31e2715e67
27 changed files with 304 additions and 93 deletions

View File

@@ -74,9 +74,7 @@ function injectCdnjs(html: string) {
export async function runUpdateHtml() {
const outDir = viteConfig.outDir || 'dist';
const indexPath = getCwdPath(outDir, 'index.html');
if (!existsSync(`${indexPath}`)) {
return;
}
if (!existsSync(indexPath)) return;
try {
let processedHtml = '';
const rawHtml = readFileSync(indexPath, 'utf-8');
@@ -92,7 +90,9 @@ export async function runUpdateHtml() {
}
if (minify) {
const { enable, ...miniOpt } = minify;
processedHtml = HtmlMinifier.minify(processedHtml, miniOpt);
if (enable) {
processedHtml = HtmlMinifier.minify(processedHtml, miniOpt);
}
}
writeFileSync(indexPath, processedHtml);