65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
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': {
 | 
						||
        target: 'https://todou.net',
 | 
						||
        changeOrigin: true,
 | 
						||
      }
 | 
						||
    },
 | 
						||
    allowedHosts: ['localhost', 'todou.net']
 | 
						||
  },
 | 
						||
  resolve: {
 | 
						||
    preserveSymlinks: true // Иногда помогает с проблемами путей в Vite
 | 
						||
  }
 | 
						||
});
 |