20260726225220
This commit is contained in:
1 parent
e3c7c6f8da
commit
a8478d60ed
170 files changed
+6786
-1678
No files matched your search
@@ -0,0 +1,21 @@
|
||||
// 开发期测试用的路径别名解析器:把 @/ 映射到 src/,并为 .ts/.tsx 探测扩展名
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { resolve as pathResolve } from "node:path";
|
||||
|
||||
const SRC = pathResolve(process.cwd(), "src");
|
||||
|
||||
const EXTS = [".ts", ".tsx", ".js", ".mjs", "/index.ts", "/index.tsx"];
|
||||
|
||||
export async function resolve(specifier, context, nextResolve) {
|
||||
if (specifier.startsWith("@/")) {
|
||||
const base = pathResolve(SRC, specifier.slice(2));
|
||||
for (const ext of EXTS) {
|
||||
try {
|
||||
return await nextResolve(pathToFileURL(base + ext).href, context);
|
||||
} catch {
|
||||
// 尝试下一个扩展名
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextResolve(specifier, context);
|
||||
}
|
||||
Reference in new issue
Block a user