fix: cli dist/web path
This commit is contained in:
parent
3efc3b59ad
commit
04dfa77eaf
|
|
@ -2,13 +2,21 @@ import type { ServeCommandHandler } from "../types.js";
|
||||||
import { createServer, Server, IncomingMessage, ServerResponse } from "http";
|
import { createServer, Server, IncomingMessage, ServerResponse } from "http";
|
||||||
import { readdirSync, statSync, readFileSync, existsSync } from "fs";
|
import { readdirSync, statSync, readFileSync, existsSync } from "fs";
|
||||||
import { createReadStream } 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 { watch } from "chokidar";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
interface ContentIndex {
|
interface ContentIndex {
|
||||||
[path: string]: string;
|
[path: string]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 CLI 脚本文件所在目录路径(用于定位 dist 文件夹)
|
||||||
|
*/
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = dirname(__filename);
|
||||||
|
const distDir = resolve(__dirname, "..", "..", "web");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MIME 类型映射
|
* MIME 类型映射
|
||||||
*/
|
*/
|
||||||
|
|
@ -172,7 +180,6 @@ function createRequestHandler(
|
||||||
*/
|
*/
|
||||||
export const serveCommand: ServeCommandHandler = async (dir, options) => {
|
export const serveCommand: ServeCommandHandler = async (dir, options) => {
|
||||||
const contentDir = resolve(dir);
|
const contentDir = resolve(dir);
|
||||||
const distDir = resolve(process.cwd(), "dist/web");
|
|
||||||
let contentIndex: ContentIndex = {};
|
let contentIndex: ContentIndex = {};
|
||||||
|
|
||||||
// 扫描内容目录生成索引
|
// 扫描内容目录生成索引
|
||||||
|
|
@ -236,6 +243,7 @@ export const serveCommand: ServeCommandHandler = async (dir, options) => {
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`\n开发服务器已启动:http://localhost:${port}`);
|
console.log(`\n开发服务器已启动:http://localhost:${port}`);
|
||||||
console.log(`内容目录:${contentDir}`);
|
console.log(`内容目录:${contentDir}`);
|
||||||
|
console.log(`静态资源目录:${distDir}`);
|
||||||
console.log(`索引文件:http://localhost:${port}/__CONTENT_INDEX.json\n`);
|
console.log(`索引文件:http://localhost:${port}/__CONTENT_INDEX.json\n`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue