fix: cli dist/web path

This commit is contained in:
2026-02-26 16:11:56 +08:00
parent 3efc3b59ad
commit 04dfa77eaf
+10 -2
View File
@@ -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`);
});
};