From a50af1422297015b2fd606953fa8b01fc1225461 Mon Sep 17 00:00:00 2001 From: minglipro Date: Wed, 20 Aug 2025 14:16:47 +0800 Subject: [PATCH] =?UTF-8?q?build(vite):=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9E=84=E5=BB=BA=E5=B9=B6=E6=B7=BB=E5=8A=A0=E6=B7=B7?= =?UTF-8?q?=E6=B7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 .gitignore 文件,更新 lock 文件忽略规则 - 在 package.json 中添加新的脚本命令 - 更新 vite.config.ts,增加代码混淆和优化配置 --- .gitignore | 2 +- package.json | 3 +++ vite.config.ts | 29 ++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ce8c118..d419b9f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,4 @@ coverage *.tsbuildinfo -*.lock* +*lock* diff --git a/package.json b/package.json index 574c6d5..4461769 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,11 @@ }, "scripts": { "dev": "vite", + "d": "vite", "build": "run-p type-check \"build-only {@}\" --", "preview": "vite preview", "build-only": "vite build", + "b": "vite build", "type-check": "vue-tsc --build", "format": "prettier --write src/" }, @@ -29,6 +31,7 @@ "pinia": "^3.0.3", "pinia-plugin-persistedstate": "^4.5.0", "sass-embedded": "^1.90.0", + "vite-plugin-bundle-obfuscator": "^1.8.0", "vue": "^3.5.18", "vue-router": "^4.5.1" }, diff --git a/vite.config.ts b/vite.config.ts index 848fdf3..70e61b3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,9 @@ import { fileURLToPath, URL } from 'node:url'; import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueDevTools from 'vite-plugin-vue-devtools'; +import Obfuscator from 'vite-plugin-bundle-obfuscator'; +const date = new Date().getTime(); // https://vite.dev/config/ export default defineConfig({ server: { @@ -12,7 +14,32 @@ export default defineConfig({ '/api': 'http://localhost:7546', }, }, - plugins: [vue(), vueDevTools()], + + build: { + rollupOptions: { + output: { + chunkFileNames: `assets/data/js/[hash].${date}.js`, + entryFileNames: `assets/data/js/[hash].${date}.js`, + assetFileNames: `assets/data/[ext]/[hash].${date}.[ext]`, + }, + }, + terserOptions: { + compress: { + drop_console: true, + drop_debugger: true, + }, + }, + }, + plugins: [ + vue(), + vueDevTools(), + Obfuscator({ + enable: true, + log: true, + autoExcludeNodeModules: true, + threadPool: true, + }), + ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)),