@xingwangzhe/stalux 1.3.7 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +20 -2
- package/src/internal/font-subset.ts +3 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -136,7 +136,7 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
|
|
|
136
136
|
return {
|
|
137
137
|
name: "stalux",
|
|
138
138
|
hooks: {
|
|
139
|
-
"astro:config:setup": ({
|
|
139
|
+
"astro:config:setup": async ({
|
|
140
140
|
injectRoute,
|
|
141
141
|
injectScript,
|
|
142
142
|
updateConfig,
|
|
@@ -188,10 +188,18 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
logger.info(`Stalux initialized (contentDir: ${opt.contentDir})`);
|
|
191
|
+
|
|
192
|
+
// 5. 字体裁剪(在 config:setup 阶段执行,保证 dev/build 都能生成)
|
|
193
|
+
try {
|
|
194
|
+
const projectRoot = process.cwd();
|
|
195
|
+
await runFontSubsetting(projectRoot, logger);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
logger.debug(`Font subsetting deferred: ${String(error)}`);
|
|
198
|
+
}
|
|
191
199
|
},
|
|
192
200
|
|
|
193
201
|
"astro:build:start": async ({ logger }) => {
|
|
194
|
-
//
|
|
202
|
+
// 6. 字体裁剪(构建时备用)
|
|
195
203
|
try {
|
|
196
204
|
const projectRoot = process.cwd();
|
|
197
205
|
await runFontSubsetting(projectRoot, logger);
|
|
@@ -200,6 +208,16 @@ export function stalux(options: StaluxOptions = {}): AstroIntegration {
|
|
|
200
208
|
}
|
|
201
209
|
},
|
|
202
210
|
|
|
211
|
+
"astro:server:setup": async ({ logger }) => {
|
|
212
|
+
// 7. 字体裁剪(开发模式备用)
|
|
213
|
+
try {
|
|
214
|
+
const projectRoot = process.cwd();
|
|
215
|
+
await runFontSubsetting(projectRoot, logger);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
logger.debug(`Font subsetting deferred in dev: ${String(error)}`);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
|
|
203
221
|
"astro:build:done": async ({ dir, logger }) => {
|
|
204
222
|
// 6. 后处理:Pagefind 搜索索引
|
|
205
223
|
if (opt.pagefind) {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createHash } from "node:crypto";
|
|
19
19
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync } from "node:fs";
|
|
20
|
-
import { resolve, basename, extname, join } from "node:path";
|
|
20
|
+
import { resolve, basename, extname, join, dirname } from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
21
22
|
|
|
22
23
|
import type { AstroIntegrationLogger } from "astro";
|
|
23
24
|
// subset-font 是 WASM 模块,需要静态导入(Vite module runner 在构建钩子中不兼容动态 import)
|
|
@@ -223,11 +224,10 @@ export async function runFontSubsetting(
|
|
|
223
224
|
logger.info("Font subsetting: scanning content...");
|
|
224
225
|
|
|
225
226
|
// 1. Locate font file (check project root first, then stalux package dir)
|
|
226
|
-
const { fileURLToPath } = await import("node:url");
|
|
227
227
|
const fontPaths = [
|
|
228
228
|
resolve(projectRoot, FONT_INPUT),
|
|
229
229
|
resolve(projectRoot, "node_modules", "@xingwangzhe", "stalux", FONT_INPUT),
|
|
230
|
-
resolve(fileURLToPath(
|
|
230
|
+
resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", FONT_INPUT),
|
|
231
231
|
];
|
|
232
232
|
|
|
233
233
|
let fontPath: string | undefined;
|