专刊
This commit is contained in:
19
scripts/alias-loader.mjs
Normal file
19
scripts/alias-loader.mjs
Normal file
@@ -0,0 +1,19 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { pathToFileURL } from 'url';
|
||||
|
||||
export async function resolve(specifier, context, nextResolve) {
|
||||
if (specifier.startsWith('@/')) {
|
||||
let rel = specifier.slice(2);
|
||||
let abs = path.join(process.cwd(), 'src', rel);
|
||||
if (!fs.existsSync(abs) && !path.extname(abs)) {
|
||||
if (fs.existsSync(abs + '.js')) abs = 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