Twan07 commited on
Commit
55d6cf8
·
verified ·
1 Parent(s): 431ee5b

Update vite.config.ts

Browse files
Files changed (1) hide show
  1. vite.config.ts +61 -45
vite.config.ts CHANGED
@@ -1,50 +1,66 @@
1
  import { defineConfig } from 'vite';
2
  import react from '@vitejs/plugin-react';
3
- import obfuscator from 'rollup-plugin-obfuscator'; // Import plugin
4
 
5
- export default defineConfig({
6
- server: {
7
- allowedHosts: ['twanapi-testupload.hf.space'],
8
- host: '0.0.0.0',
9
- port: 5173,
10
- },
11
- plugins: [
12
- react(),
13
- // Chỉ chạy obfuscator khi build production
14
- obfuscator({
15
- global: true, // Áp dụng cho tất cả file
16
- options: {
17
- // Cấu hình làm rối code cực mạnh
18
- compact: true,
19
- controlFlowFlattening: true, // Làm rối luồng logic if/else
20
- controlFlowFlatteningThreshold: 1,
21
- deadCodeInjection: true, // Chèn code giả vào để đánh lừa
22
- deadCodeInjectionThreshold: 0.4,
23
- debugProtection: true, // Chống bật F12 console debug
24
- debugProtectionInterval: 4000, // Treo trình duyệt nếu cố debug
25
- disableConsoleOutput: true, // Chặn mọi console.log
26
- identifierNamesGenerator: 'hexadecimal', // Đổi tên biến thành mã hex (0x...)
27
- log: false,
28
- renameGlobals: false,
29
- rotateStringArray: true,
30
- selfDefending: true, // Code tự bảo vệ khi bị format lại
31
- stringArray: true,
32
- stringArrayEncoding: ['rc4'], // Mã hóa chuỗi text
33
- stringArrayThreshold: 1,
34
- unicodeEscapeSequence: false
35
- },
36
- }),
37
- ],
38
- esbuild: {
39
- drop: ['console', 'debugger'],
40
- },
41
- build: {
42
- sourcemap: false,
43
- minify: 'esbuild',
44
- rollupOptions: {
45
- output: {
46
- manualChunks: undefined,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
- }
49
- },
50
  });
 
1
  import { defineConfig } from 'vite';
2
  import react from '@vitejs/plugin-react';
3
+ import obfuscator from 'rollup-plugin-obfuscator';
4
 
5
+ // Sử dụng function để kiểm tra xem đang chạy 'serve' (dev) hay 'build' (production)
6
+ export default defineConfig(({ command }) => {
7
+ // Biến kiểm tra: chỉ đúng khi đang chạy lệnh build
8
+ const isBuild = command === 'build';
9
+
10
+ return {
11
+ server: {
12
+ allowedHosts: ['twanapi-testupload.hf.space'],
13
+ host: '0.0.0.0',
14
+ port: 5173,
15
+ },
16
+ plugins: [
17
+ react(),
18
+ // Logic quan trọng: Chỉ chạy obfuscator khi đang Build Production
19
+ // Nếu chạy Dev, plugin này sẽ bị bỏ qua để máy chạy nhanh
20
+ isBuild && obfuscator({
21
+ global: true,
22
+ options: {
23
+ // --- CẤU HÌNH BẢO MẬT MẠNH ---
24
+ compact: true,
25
+ controlFlowFlattening: true,
26
+ controlFlowFlatteningThreshold: 1,
27
+ deadCodeInjection: true,
28
+ deadCodeInjectionThreshold: 0.4,
29
+
30
+ // Chống debug & Console
31
+ debugProtection: true,
32
+ debugProtectionInterval: 4000,
33
+ disableConsoleOutput: true,
34
+
35
+ // Mã hóa tên biến & chuỗi
36
+ identifierNamesGenerator: 'hexadecimal',
37
+ log: false,
38
+ renameGlobals: false,
39
+ rotateStringArray: true,
40
+ selfDefending: true,
41
+ stringArray: true,
42
+ stringArrayEncoding: ['rc4'],
43
+ stringArrayThreshold: 1,
44
+ unicodeEscapeSequence: false,
45
+
46
+ // Loại bỏ domainLock (để tránh lỗi khi đổi domain trên HF)
47
+ domainLock: [],
48
+ },
49
+ }),
50
+ ],
51
+ esbuild: {
52
+ // Xóa console.log và debugger ngay từ bước esbuild
53
+ drop: ['console', 'debugger'],
54
+ },
55
+ build: {
56
+ sourcemap: false, // Ẩn hoàn toàn map code
57
+ minify: 'esbuild', // Nén code
58
+ chunkSizeWarningLimit: 1500, // Tăng giới hạn cảnh báo size file vì obfuscate làm file nặng hơn
59
+ rollupOptions: {
60
+ output: {
61
+ manualChunks: undefined,
62
+ }
63
  }
64
+ },
65
+ };
66
  });