feat: 减少渲染阻塞并压缩静态资源

- 移除首页副标题固定 Quicksand 外链字体,改为跟随全站字体变量
- 字体配置新增 fonts.preload(preload+onload 非阻塞加载,含 noscript 回退)
- Font Awesome CSS 改为 preload+onload 非阻塞加载,降低 render-blocking
- 构建阶段使用 esbuild 压缩 dist 的 style/script/pinyin-match(无 esbuild 时回退为直接复制)
- 同步更新文档说明与更新日志
This commit is contained in:
rbetree
2026-01-04 17:03:16 +08:00
parent 2bebefbfe8
commit 4cc10dd2b2
8 changed files with 518 additions and 22 deletions

View File

@@ -43,6 +43,15 @@
<details> <details>
<summary>点击查看/隐藏更新日志</summary> <summary>点击查看/隐藏更新日志</summary>
### 2026/01/04
**1. PageSpeed 首屏性能优化**
- 移除首页副标题固定 Quicksand 外链字体,改为跟随全站字体
- 字体外链 CSS 支持 `fonts.preload: true``preload + onload` 非阻塞加载,含 `<noscript>` 回退)
- Font Awesome CSS 改为 `preload + onload` 非阻塞加载,降低 render-blocking 影响
- 构建阶段压缩 `style.css` / `script.js` / `pinyin-match.js`,减少传输体积
### 2026/01/03 ### 2026/01/03
关联 Issue[#31](https://github.com/rbetree/menav/issues/31) 关联 Issue[#31](https://github.com/rbetree/menav/issues/31)

View File

@@ -1093,7 +1093,7 @@ body .content.expanded {
} }
.welcome-section h3 { .welcome-section h3 {
font-family: "Quicksand", var(--font-body, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif); font-family: var(--font-body, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif);
font-weight: 500; font-weight: 500;
font-size: 2rem; font-size: 2rem;
margin-bottom: 1rem; margin-bottom: 1rem;
@@ -3008,4 +3008,4 @@ body .content.expanded {
background-color: var(--accent-color); background-color: var(--accent-color);
z-index: 1000; z-index: 1000;
transition: width 0.1s ease-out; transition: width 0.1s ease-out;
} }

View File

@@ -129,7 +129,8 @@ MeNav 配置系统采用“完全替换”策略(不合并),按以下优
3. **字体** 3. **字体**
- `fonts`:单一字体配置项,用于设置全站基础字体(`body` 等) - `fonts`:单一字体配置项,用于设置全站基础字体(`body` 等)
- 支持 `source: css | google | system`(分别表示第三方 CSS、Google Fonts、系统字体 - 支持 `source: css | google | system`(分别表示第三方 CSS、Google Fonts、系统字体
- 首页副标题(渐变发光样式)字体固定为 `Quicksand`,不通过配置项控制 - 可选 `fonts.preload: true`:用 `preload + onload` 的方式非阻塞加载外链字体 CSS更利于首屏性能
- 首页副标题(渐变发光样式)使用全站基础字体(跟随 `fonts` 配置)
4. **顶部欢迎信息与社交链接** 4. **顶部欢迎信息与社交链接**
- `profile`:首页顶部欢迎信息 - `profile`:首页顶部欢迎信息
@@ -261,10 +262,10 @@ profile:
fonts: fonts:
source: css source: css
cssUrl: "https://fontsapi.zeoseven.com/292/main/result.css" cssUrl: "https://fontsapi.zeoseven.com/292/main/result.css"
preload: true
family: "LXGW WenKai" family: "LXGW WenKai"
weight: normal weight: normal
# 社交媒体链接 # 社交媒体链接
social: social:
- name: "GitHub" - name: "GitHub"

View File

@@ -29,6 +29,7 @@ icons:
fonts: fonts:
source: css source: css
cssUrl: "https://fontsapi.zeoseven.com/292/main/result.css" cssUrl: "https://fontsapi.zeoseven.com/292/main/result.css"
preload: true # 可选:使用 preload+onload 的方式非阻塞加载字体 CSS更利于首屏性能
family: LXGW WenKai family: LXGW WenKai
weight: normal weight: normal

431
package-lock.json generated
View File

@@ -21,10 +21,402 @@
"supports-color": "^9.4.0" "supports-color": "^9.4.0"
}, },
"devDependencies": { "devDependencies": {
"esbuild": "^0.20.2",
"prettier": "^3.4.2", "prettier": "^3.4.2",
"serve": "^14.2.5" "serve": "^14.2.5"
} }
}, },
"node_modules/@esbuild/aix-ppc64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz",
"integrity": "sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"aix"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/android-arm": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.2.tgz",
"integrity": "sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==",
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/android-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.2.tgz",
"integrity": "sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/android-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.2.tgz",
"integrity": "sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/darwin-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.2.tgz",
"integrity": "sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/darwin-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz",
"integrity": "sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/freebsd-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.2.tgz",
"integrity": "sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/freebsd-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.2.tgz",
"integrity": "sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-arm": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.2.tgz",
"integrity": "sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==",
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.2.tgz",
"integrity": "sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-ia32": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.2.tgz",
"integrity": "sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==",
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-loong64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.2.tgz",
"integrity": "sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==",
"cpu": [
"loong64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-mips64el": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.2.tgz",
"integrity": "sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==",
"cpu": [
"mips64el"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-ppc64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.2.tgz",
"integrity": "sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-riscv64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.2.tgz",
"integrity": "sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==",
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-s390x": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.2.tgz",
"integrity": "sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==",
"cpu": [
"s390x"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/linux-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz",
"integrity": "sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/netbsd-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.2.tgz",
"integrity": "sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/openbsd-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.2.tgz",
"integrity": "sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/sunos-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.2.tgz",
"integrity": "sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"sunos"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/win32-arm64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.2.tgz",
"integrity": "sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/win32-ia32": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.2.tgz",
"integrity": "sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==",
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/win32-x64": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz",
"integrity": "sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@zeit/schemas": { "node_modules/@zeit/schemas": {
"version": "2.36.0", "version": "2.36.0",
"resolved": "https://registry.npmjs.org/@zeit/schemas/-/schemas-2.36.0.tgz", "resolved": "https://registry.npmjs.org/@zeit/schemas/-/schemas-2.36.0.tgz",
@@ -486,6 +878,45 @@
"url": "https://github.com/fb55/entities?sponsor=1" "url": "https://github.com/fb55/entities?sponsor=1"
} }
}, },
"node_modules/esbuild": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz",
"integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"bin": {
"esbuild": "bin/esbuild"
},
"engines": {
"node": ">=12"
},
"optionalDependencies": {
"@esbuild/aix-ppc64": "0.20.2",
"@esbuild/android-arm": "0.20.2",
"@esbuild/android-arm64": "0.20.2",
"@esbuild/android-x64": "0.20.2",
"@esbuild/darwin-arm64": "0.20.2",
"@esbuild/darwin-x64": "0.20.2",
"@esbuild/freebsd-arm64": "0.20.2",
"@esbuild/freebsd-x64": "0.20.2",
"@esbuild/linux-arm": "0.20.2",
"@esbuild/linux-arm64": "0.20.2",
"@esbuild/linux-ia32": "0.20.2",
"@esbuild/linux-loong64": "0.20.2",
"@esbuild/linux-mips64el": "0.20.2",
"@esbuild/linux-ppc64": "0.20.2",
"@esbuild/linux-riscv64": "0.20.2",
"@esbuild/linux-s390x": "0.20.2",
"@esbuild/linux-x64": "0.20.2",
"@esbuild/netbsd-x64": "0.20.2",
"@esbuild/openbsd-x64": "0.20.2",
"@esbuild/sunos-x64": "0.20.2",
"@esbuild/win32-arm64": "0.20.2",
"@esbuild/win32-ia32": "0.20.2",
"@esbuild/win32-x64": "0.20.2"
}
},
"node_modules/execa": { "node_modules/execa": {
"version": "5.1.1", "version": "5.1.1",
"resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz",

View File

@@ -39,6 +39,7 @@
"rss-parser": "^3.13.0" "rss-parser": "^3.13.0"
}, },
"devDependencies": { "devDependencies": {
"esbuild": "^0.20.2",
"prettier": "^3.4.2", "prettier": "^3.4.2",
"serve": "^14.2.5" "serve": "^14.2.5"
} }

View File

@@ -1154,34 +1154,56 @@ function getNormalizedFontsConfig(config) {
family: normalizeFontFamilyForCss(fonts.family), family: normalizeFontFamilyForCss(fonts.family),
weight: normalizeFontWeight(fonts.weight), weight: normalizeFontWeight(fonts.weight),
cssUrl: String(fonts.cssUrl || fonts.href || '').trim(), cssUrl: String(fonts.cssUrl || fonts.href || '').trim(),
preload: Boolean(fonts.preload),
}; };
} }
// 生成字体相关 <link>(包含固定的首页特殊样式字体) function tryGetUrlOrigin(input) {
const raw = String(input || '').trim();
if (!raw) return '';
try {
return new URL(raw).origin;
} catch {
return '';
}
}
function buildStylesheetLinkTag(href, preload) {
const safeHref = escapeHtml(href);
if (!preload) return `<link rel="stylesheet" href="${safeHref}">`;
return [
`<link rel="preload" href="${safeHref}" as="style" onload="this.onload=null;this.rel='stylesheet'">`,
`<noscript><link rel="stylesheet" href="${safeHref}"></noscript>`,
].join('\n');
}
// 生成字体相关 <link>
function generateFontLinks(config) { function generateFontLinks(config) {
const fonts = getNormalizedFontsConfig(config); const fonts = getNormalizedFontsConfig(config);
const links = []; const links = [];
// 首页特殊样式字体:固定为 Quicksand不通过配置控制
links.push('<link rel="preconnect" href="https://fonts.googleapis.com">');
links.push('<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>');
links.push(
'<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&display=swap">'
);
// 全站基础字体:按配置加载 // 全站基础字体:按配置加载
if (fonts.source === 'css' && fonts.cssUrl) { if (fonts.source === 'css' && fonts.cssUrl) {
links.push( const origin = tryGetUrlOrigin(fonts.cssUrl);
`<link rel="stylesheet" href="${escapeHtml(fonts.cssUrl)}">` if (origin) {
); links.push(`<link rel="preconnect" href="${escapeHtml(origin)}" crossorigin>`);
}
links.push(buildStylesheetLinkTag(fonts.cssUrl, fonts.preload));
} }
if (fonts.source === 'google' && fonts.family) { if (fonts.source === 'google' && fonts.family) {
links.push('<link rel="preconnect" href="https://fonts.googleapis.com">');
links.push('<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>');
const familyNoQuotes = fonts.family.replace(/["']/g, '').split(',')[0].trim(); const familyNoQuotes = fonts.family.replace(/["']/g, '').split(',')[0].trim();
const weight = /^[1-9]00$/.test(fonts.weight) ? fonts.weight : '400'; const weight = /^[1-9]00$/.test(fonts.weight) ? fonts.weight : '400';
const familyParam = encodeURIComponent(familyNoQuotes).replace(/%20/g, '+'); const familyParam = encodeURIComponent(familyNoQuotes).replace(/%20/g, '+');
links.push( links.push(
`<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=${familyParam}:wght@${weight}&display=swap">` buildStylesheetLinkTag(
`https://fonts.googleapis.com/css2?family=${familyParam}:wght@${weight}&display=swap`,
fonts.preload
)
); );
} }
@@ -1455,6 +1477,29 @@ function generateHTML(config) {
} }
} }
function tryMinifyStaticAsset(srcPath, destPath, loader) {
let esbuild;
try {
esbuild = require('esbuild');
} catch {
return false;
}
try {
const source = fs.readFileSync(srcPath, 'utf8');
const result = esbuild.transformSync(source, {
loader,
minify: true,
charset: 'utf8',
});
fs.writeFileSync(destPath, result.code);
return true;
} catch (error) {
console.error(`Error minifying ${srcPath}:`, error);
return false;
}
}
// 复制静态文件 // 复制静态文件
function copyStaticFiles(config) { function copyStaticFiles(config) {
// 确保dist目录存在 // 确保dist目录存在
@@ -1464,20 +1509,26 @@ function copyStaticFiles(config) {
// 复制CSS文件 // 复制CSS文件
try { try {
fs.copyFileSync('assets/style.css', 'dist/style.css'); if (!tryMinifyStaticAsset('assets/style.css', 'dist/style.css', 'css')) {
fs.copyFileSync('assets/style.css', 'dist/style.css');
}
} catch (e) { } catch (e) {
console.error('Error copying style.css:', e); console.error('Error copying style.css:', e);
} }
try { try {
fs.copyFileSync('assets/pinyin-match.js', 'dist/pinyin-match.js'); if (!tryMinifyStaticAsset('assets/pinyin-match.js', 'dist/pinyin-match.js', 'js')) {
fs.copyFileSync('assets/pinyin-match.js', 'dist/pinyin-match.js');
}
} catch (e) { } catch (e) {
console.error('Error copying pinyin-match.js:', e); console.error('Error copying pinyin-match.js:', e);
} }
// 复制JavaScript文件 // 复制JavaScript文件
try { try {
fs.copyFileSync('src/script.js', 'dist/script.js'); if (!tryMinifyStaticAsset('src/script.js', 'dist/script.js', 'js')) {
fs.copyFileSync('src/script.js', 'dist/script.js');
}
} catch (e) { } catch (e) {
console.error('Error copying script.js:', e); console.error('Error copying script.js:', e);
} }

View File

@@ -34,8 +34,10 @@
})(); })();
</script> </script>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"> <link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin>
</head> <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"></noscript>
</head>
<body class="loading"> <body class="loading">
<!-- 滚动进度指示条 --> <!-- 滚动进度指示条 -->
<div class="scroll-progress"></div> <div class="scroll-progress"></div>