perf: Use Imports Instead of Aliases
This commit is contained in:
@@ -46,13 +46,7 @@ export async function perfectionist(): Promise<Linter.FlatConfig[]> {
|
||||
'object',
|
||||
'unknown',
|
||||
],
|
||||
'internal-pattern': [
|
||||
'@/layouts/**',
|
||||
'@/apis/**',
|
||||
'@/forward/**',
|
||||
'@/router/**',
|
||||
'@/views/**',
|
||||
],
|
||||
'internal-pattern': ['#*', '#*/**'],
|
||||
'newlines-between': 'always',
|
||||
order: 'asc',
|
||||
type: 'natural',
|
||||
|
@@ -32,6 +32,7 @@
|
||||
"@manypkg/get-packages": "^2.2.1",
|
||||
"consola": "^3.2.3",
|
||||
"find-up": "^7.0.0",
|
||||
"nanoid": "^5.0.7",
|
||||
"pkg-types": "^1.1.1",
|
||||
"prettier": "^3.3.2",
|
||||
"rimraf": "^5.0.7",
|
||||
|
@@ -1,48 +0,0 @@
|
||||
import fs from 'node:fs';
|
||||
import { dirname, extname, resolve } from 'node:path';
|
||||
|
||||
import { findUpSync } from 'find-up';
|
||||
|
||||
/**
|
||||
* 查找 package.json 文件所在的目录
|
||||
* @param pathname
|
||||
*/
|
||||
function findUpPackageDir(pathname: string = '') {
|
||||
const file = findUpSync('package.json', {
|
||||
cwd: dirname(pathname),
|
||||
type: 'file',
|
||||
});
|
||||
return dirname(file || '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的扩展名数组来查找文件是否存在,并返回对应文件路径
|
||||
* @param pathname 文件路径
|
||||
* @param extensions 扩展名数组
|
||||
* @returns 对应文件路径,如果未找到则返回 null
|
||||
*/
|
||||
function findFileByExtension(
|
||||
pathname: string = '',
|
||||
extensions: string[] = ['.ts'],
|
||||
): string {
|
||||
if (extname(pathname)) {
|
||||
return pathname;
|
||||
}
|
||||
|
||||
for (const ext of extensions) {
|
||||
const fullpath = resolve(pathname);
|
||||
if (fs.existsSync(fullpath + ext) && fs.statSync(fullpath + ext).isFile()) {
|
||||
return fullpath + ext;
|
||||
}
|
||||
}
|
||||
|
||||
for (const ext of extensions) {
|
||||
const resultPath = resolve(pathname, `index${ext}`);
|
||||
if (fs.existsSync(resultPath)) {
|
||||
return resultPath;
|
||||
}
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
|
||||
export { findFileByExtension, findUpPackageDir };
|
@@ -1,5 +1,4 @@
|
||||
export { UNICODE } from './constants';
|
||||
export { findFileByExtension, findUpPackageDir } from './find';
|
||||
export * from './git';
|
||||
export { add as gitAdd, getStagedFiles } from './git';
|
||||
export { generatorContentHash } from './hash';
|
||||
|
@@ -2,8 +2,6 @@ import type { UserConfig } from 'vite';
|
||||
|
||||
import type { DefineApplicationOptions } from '../typing';
|
||||
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { defineConfig, loadEnv, mergeConfig } from 'vite';
|
||||
|
||||
import { getApplicationConditionPlugins } from '../plugins';
|
||||
@@ -57,31 +55,6 @@ function defineApplicationConfig(options: DefineApplicationOptions = {}) {
|
||||
legalComments: 'none',
|
||||
},
|
||||
plugins,
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: /@\//,
|
||||
replacement: `${resolve(root, '.', 'src')}/`,
|
||||
},
|
||||
/**
|
||||
* 确保大仓内的子包,如果通过源码方式引用,可以直接使用@别名
|
||||
*/
|
||||
// {
|
||||
// find: '@',
|
||||
// replacement: '@',
|
||||
// customResolver(source, importer) {
|
||||
// if (source[0] === '@') {
|
||||
// const realPath = source.replace(
|
||||
// /^@/,
|
||||
// resolve(findUpPackageDir(importer), 'src'),
|
||||
// );
|
||||
// return findFileByExtension(realPath);
|
||||
// }
|
||||
// return null;
|
||||
// },
|
||||
// },
|
||||
],
|
||||
},
|
||||
server: {
|
||||
host: true,
|
||||
warmup: {
|
||||
|
Reference in New Issue
Block a user