import { fileURLToPath, URL } from 'node:url'; import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; import checker from 'vite-plugin-checker'; import Components from 'unplugin-vue-components/vite'; import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'; import fs from 'node:fs'; import path from 'node:path'; export default defineConfig(() => ({ plugins: [ vue(), vueJsx(), checker({ vueTsc: { tsconfigPath: './tsconfig.app.json' }, typescript: true }), Components({ dirs: ['src'], include: [/\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.[tj]sx?$/], dts: true, resolvers: [ElementPlusResolver()] }) ], resolve: { alias: { '@': resolvePath('./src'), ...getModuleAliases() } }, build: { outDir: 'target/dist', assetsDir: 'static' }, server: { proxy: { '/api': { target: 'http://localhost:9001', ws: true, changeOrigin: true }, '/websocket': { target: 'ws://localhost:9001', ws: true, changeOrigin: true } } }, define: { global: 'globalThis' } })); const resolvePath = (p: string) => fileURLToPath(new URL(p, import.meta.url)); /** * Автоматически генерирует алиасы для модулей. * Ищет папки в src/modules и создает маппинг: * @itprom/ -> src/modules//src/index.ts */ function getModuleAliases() { const modulesDir = resolvePath('./src/modules'); const aliases: Record = {}; if (fs.existsSync(modulesDir)) { const folders = fs.readdirSync(modulesDir); folders.forEach((folder) => { // Проверяем, что это папка и внутри есть src/index.ts const moduleSrcPath = path.join(modulesDir, folder, 'src', 'index.ts'); if (fs.existsSync(moduleSrcPath)) { aliases[`@itprom/${folder}`] = moduleSrcPath; } }); } return aliases; }