Twan07 commited on
Commit
1a6b222
·
verified ·
1 Parent(s): 28baa5c

Update vite.config.ts

Browse files
Files changed (1) hide show
  1. vite.config.ts +19 -62
vite.config.ts CHANGED
@@ -1,66 +1,23 @@
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
- });
 
1
  import { defineConfig } from 'vite';
2
  import react from '@vitejs/plugin-react';
 
3
 
4
+ export default defineConfig({
5
+ server: {
6
+ // Cho phép host cụ thể (thêm domain của bạn)
7
+ allowedHosts: [
8
+ 'twanapi-testupload.hf.space',
9
+ // Thêm các host khác nếu cần, ví dụ: '*.hf.space' để cho phép tất cả subdomain HF
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ],
11
+ // Nếu đang dev trong Docker, thêm host để accessible từ ngoài
12
+ host: '0.0.0.0',
13
+ port: 5173,
14
+ },
15
+ plugins: [react()],
16
+ esbuild: {
17
+ drop: ['console', 'debugger'], // Xóa log
18
+ },
19
+ build: {
20
+ sourcemap: false, // Ẩn code gốc
21
+ minify: 'esbuild', // Nén code nhỏ nhất có thể
22
+ },
23
+ });