From 04dfa77eaf8324b3d72f0b0fc77e0876d181e3e8 Mon Sep 17 00:00:00 2001 From: hypercross Date: Thu, 26 Feb 2026 16:11:56 +0800 Subject: [PATCH] fix: cli dist/web path --- src/cli/commands/serve.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/serve.ts b/src/cli/commands/serve.ts index 01489b5..edeb4fd 100644 --- a/src/cli/commands/serve.ts +++ b/src/cli/commands/serve.ts @@ -2,13 +2,21 @@ import type { ServeCommandHandler } from "../types.js"; import { createServer, Server, IncomingMessage, ServerResponse } from "http"; import { readdirSync, statSync, readFileSync, existsSync } from "fs"; import { createReadStream } from "fs"; -import { join, resolve, extname, sep, relative } from "path"; +import { join, resolve, extname, sep, relative, dirname } from "path"; import { watch } from "chokidar"; +import { fileURLToPath } from "url"; interface ContentIndex { [path: string]: string; } +/** + * 获取 CLI 脚本文件所在目录路径(用于定位 dist 文件夹) + */ +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const distDir = resolve(__dirname, "..", "..", "web"); + /** * MIME 类型映射 */ @@ -172,7 +180,6 @@ function createRequestHandler( */ export const serveCommand: ServeCommandHandler = async (dir, options) => { const contentDir = resolve(dir); - const distDir = resolve(process.cwd(), "dist/web"); let contentIndex: ContentIndex = {}; // 扫描内容目录生成索引 @@ -236,6 +243,7 @@ export const serveCommand: ServeCommandHandler = async (dir, options) => { server.listen(port, () => { console.log(`\n开发服务器已启动:http://localhost:${port}`); console.log(`内容目录:${contentDir}`); + console.log(`静态资源目录:${distDir}`); console.log(`索引文件:http://localhost:${port}/__CONTENT_INDEX.json\n`); }); };