todou-frontend/vite.config.ts

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-02-10 23:24:18 +01:00
import { defineConfig, Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import fs from 'fs';
function fixSourceMaps(): Plugin {
let currentInterval: NodeJS.Timeout | null = null;
return {
name: 'fix-source-map',
enforce: 'post',
transform(source) {
if (currentInterval) {
return source;
}
currentInterval = setInterval(() => {
const nodeModulesPath = path.join(process.cwd(), 'node_modules', '.vite', 'deps');
if (fs.existsSync(nodeModulesPath)) {
clearInterval(currentInterval!);
currentInterval = null;
const files = fs.readdirSync(nodeModulesPath);
files.forEach((file) => {
const mapFile = `${file}.map`;
const mapPath = path.join(nodeModulesPath, mapFile);
if (fs.existsSync(mapPath)) {
let mapData = JSON.parse(fs.readFileSync(mapPath, 'utf8'));
if (!mapData.sources || mapData.sources.length === 0) {
mapData.sources = [path.relative(mapPath, path.join(nodeModulesPath, file))];
fs.writeFileSync(mapPath, JSON.stringify(mapData), 'utf8');
}
}
});
}
}, 100);
return source;
}
};
}
export default defineConfig({
plugins: [
react(),
fixSourceMaps() as Plugin // Фикс source maps
],
server: {
port: 3000,
proxy: {
'/api': {
2025-02-11 10:24:22 +01:00
target: 'https://todou.net',
2025-02-10 23:24:18 +01:00
changeOrigin: true,
}
2025-02-11 01:45:21 +01:00
},
allowedHosts: ['localhost', 'todou.net']
},
2025-02-10 23:24:18 +01:00
resolve: {
2025-02-11 10:24:22 +01:00
preserveSymlinks: true // Иногда помогает с проблемами путей в Vite
2025-02-10 23:24:18 +01:00
}
});