diff --git a/lib/server/watch.js b/lib/server/watch.js index c801260..d0dae67 100644 --- a/lib/server/watch.js +++ b/lib/server/watch.js @@ -280,11 +280,12 @@ const createCompiler = async (projectPath, options, projectReferences, treatFile }; const compileTask = async (task) => { const { filePath, changeType } = task; + const modulePath = path_1.default.resolve(filePath); // 判断文件类型 if (!filePath.endsWith(".ts")) { // 处理非TypeScript文件 (如JSON文件) if (filePath.endsWith(".json")) { - const targetPath = filePath.replace(path_1.default.join(projectPath, "src"), path_1.default.join(projectPath, "lib")); + const targetPath = modulePath.replace(path_1.default.join(projectPath, "src"), path_1.default.join(projectPath, "lib")); try { if (changeType === "remove") { if (fs_1.default.existsSync(targetPath)) { @@ -331,7 +332,6 @@ const createCompiler = async (projectPath, options, projectReferences, treatFile // 处理TypeScript文件 console.clear(); console.warn(`File ${filePath} has been ${changeType}d`); - const modulePath = path_1.default.resolve(filePath); const libPath = modulePath .replace(path_1.default.join(projectPath, "src"), path_1.default.join(projectPath, "lib")) .replace(/\.ts$/, ".js"); diff --git a/src/server/watch.ts b/src/server/watch.ts index 61ad4a0..dfed001 100644 --- a/src/server/watch.ts +++ b/src/server/watch.ts @@ -477,11 +477,12 @@ const createCompiler = async ( const compileTask = async (task: CompileTask): Promise => { const { filePath, changeType } = task; + const modulePath = pathLib.resolve(filePath); // 判断文件类型 if (!filePath.endsWith(".ts")) { // 处理非TypeScript文件 (如JSON文件) if (filePath.endsWith(".json")) { - const targetPath = filePath.replace( + const targetPath = modulePath.replace( pathLib.join(projectPath, "src"), pathLib.join(projectPath, "lib") ); @@ -533,7 +534,6 @@ const createCompiler = async ( console.clear(); console.warn(`File ${filePath} has been ${changeType}d`); - const modulePath = pathLib.resolve(filePath); const libPath = modulePath .replace(pathLib.join(projectPath, "src"), pathLib.join(projectPath, "lib")) .replace(/\.ts$/, ".js");