专刊
This commit is contained in:
15
scripts/alias-hooks.mjs
Normal file
15
scripts/alias-hooks.mjs
Normal file
@@ -0,0 +1,15 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { pathToFileURL } from 'url';
|
||||
|
||||
export async function resolve(specifier, context, nextResolve) {
|
||||
if (specifier.startsWith('@/')) {
|
||||
let abs = path.join(process.cwd(), 'src', specifier.slice(2));
|
||||
if (!fs.existsSync(abs) && !path.extname(abs)) {
|
||||
if (fs.existsSync(abs + '.js')) abs += '.js';
|
||||
else if (fs.existsSync(path.join(abs, 'index.js'))) abs = path.join(abs, 'index.js');
|
||||
}
|
||||
return { shortCircuit: true, url: pathToFileURL(abs).href };
|
||||
}
|
||||
return nextResolve(specifier, context);
|
||||
}
|
||||
Reference in New Issue
Block a user