File size: 2,151 Bytes
16e3470
 
55d6cf8
16e3470
55d6cf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431ee5b
55d6cf8
 
431ee5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import obfuscator from 'rollup-plugin-obfuscator';

// Sử dụng function để kiểm tra xem đang chạy 'serve' (dev) hay 'build' (production)
export default defineConfig(({ command }) => {
  // Biến kiểm tra: chỉ đúng khi đang chạy lệnh build
  const isBuild = command === 'build';

  return {
    server: {
      allowedHosts: ['twanapi-testupload.hf.space'],
      host: '0.0.0.0',
      port: 5173,
    },
    plugins: [
      react(),
      // Logic quan trọng: Chỉ chạy obfuscator khi đang Build Production
      // Nếu chạy Dev, plugin này sẽ bị bỏ qua để máy chạy nhanh
      isBuild && obfuscator({
        global: true, 
        options: {
          // --- CẤU HÌNH BẢO MẬT MẠNH ---
          compact: true,
          controlFlowFlattening: true, 
          controlFlowFlatteningThreshold: 1,
          deadCodeInjection: true,
          deadCodeInjectionThreshold: 0.4,
          
          // Chống debug & Console
          debugProtection: true, 
          debugProtectionInterval: 4000, 
          disableConsoleOutput: true, 
          
          // Mã hóa tên biến & chuỗi
          identifierNamesGenerator: 'hexadecimal', 
          log: false,
          renameGlobals: false,
          rotateStringArray: true,
          selfDefending: true, 
          stringArray: true,
          stringArrayEncoding: ['rc4'], 
          stringArrayThreshold: 1,
          unicodeEscapeSequence: false,
          
          // Loại bỏ domainLock (để tránh lỗi khi đổi domain trên HF)
          domainLock: [], 
        },
      }),
    ],
    esbuild: {
      // Xóa console.log và debugger ngay từ bước esbuild
      drop: ['console', 'debugger'],
    },
    build: {
      sourcemap: false, // Ẩn hoàn toàn map code
      minify: 'esbuild', // Nén code
      chunkSizeWarningLimit: 1500, // Tăng giới hạn cảnh báo size file vì obfuscate làm file nặng hơn
      rollupOptions: {
        output: {
          manualChunks: undefined,
        }
      }
    },
  };
});