Files
tauri-meeting/vite/optimizeDeps.ts
O昵称重要吗O 78af453fe1 chore: 初始化项目基础结构和资源文件
- 添加项目图标文件(app-icon.png、各平台图标)
- 配置开发环境文件(.env、.nvmrc、.npmrc)
- 添加静态资源文件(背景图片、字体、音频)
- 初始化Tauri后端结构(build.rs、main.rs、模块文件)
- 配置前端项目结构(TypeScript、Vue组件、样式)
- 添加Node.js API服务基础结构
- 配置构建和开发工具(vite、prettier、gitignore)
2026-03-13 10:03:05 +08:00

75 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'fs';
/** 预构建的依赖 */
export async function elementPlusStyleOptimizeIncludes(type: 'css' | 'scss'): Promise<string[]> {
try {
const elementPlusStylePath: string[] = [];
// 得到 'element-plus/es/components' 目录下的所有目录名称
const dirnames = fs.readdirSync('node_modules/element-plus/es/components');
//得到需要检测的路径,防止导入不存在的路径
const accessPaths = dirnames.map((dirname) => {
const returnPath = `element-plus/es/components/${dirname}/style/${type === 'css' ? 'css' : 'index'}`; // 需要返回的路径
const checkPath = `node_modules/${returnPath}.mjs`; // 需要检测的路径
return getAccessPath(checkPath, returnPath);
});
// 得到所有路径包含null
const paths = await Promise.all(accessPaths);
// 去除null
paths.forEach((path) => {
// oxlint-disable-next-line no-unused-expressions
path && elementPlusStylePath.push(path);
});
return Promise.resolve(elementPlusStylePath);
// oxlint-disable-next-line no-unused-vars
} catch (error: any) {
return Promise.resolve([]);
}
}
/** 预构建的依赖 */
export async function optimizeIncludes(packages: string[]): Promise<string[]> {
const includesPaths: string[] = [];
//得到需要检测的路径,防止导入不存在的路径
const accessPaths = packages.map((dirname) => {
return getAccessPath(`node_modules/${dirname}`, dirname);
});
// 得到所有路径包含null
const paths = await Promise.all(accessPaths);
// 去除null
paths.forEach((path) => {
// oxlint-disable-next-line no-unused-expressions
path && includesPaths.push(path);
});
if (includesPaths.length !== packages.length) {
const notPath = packages.filter((v) => includesPaths.indexOf(v) === -1);
console.log('以下依赖没有被预构建:', notPath);
}
return Promise.resolve(includesPaths);
}
/**
* 检测文件是否存在如存在则返回对应路径如不存在则返回null
* @param checkPath - 需要检测的路径
* @param returnPath - 需要返回的路径
*/
function getAccessPath(checkPath: string, returnPath: string): Promise<string | null> {
return new Promise((resolve) => {
fs.access(checkPath, (err) => {
if (!err) {
resolve(returnPath);
} else {
fs.access(`${checkPath}.js`, (err2) => {
if (!err2) {
resolve(returnPath);
} else {
resolve(null);
}
});
}
});
});
}