feat: 前端生产构建添加代码混淆
- 集成 vite-plugin-javascript-obfuscator 插件 - 配置中等偏高强度混淆策略(变量名、字符串、对象键、数字) - 仅生产构建时启用,不影响开发体验 - 仅混淆业务代码,排除第三方库 - 不生成 Source Map - 新增 frontend-obfuscation 规范
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator'
|
||||
import path from 'node:path'
|
||||
|
||||
const vendorChunks: Record<string, string[]> = {
|
||||
@@ -10,7 +11,42 @@ const vendorChunks: Record<string, string[]> = {
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
plugins: [
|
||||
react(),
|
||||
obfuscatorPlugin({
|
||||
apply: 'build',
|
||||
include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', 'src/**/*.jsx'],
|
||||
exclude: [/node_modules/],
|
||||
options: {
|
||||
compact: true,
|
||||
simplify: true,
|
||||
identifierNamesGenerator: 'mangled-shuffled',
|
||||
stringArray: true,
|
||||
stringArrayCallsTransform: true,
|
||||
stringArrayCallsTransformThreshold: 0.5,
|
||||
stringArrayEncoding: ['base64'],
|
||||
stringArrayIndexShift: true,
|
||||
stringArrayRotate: true,
|
||||
stringArrayShuffle: true,
|
||||
stringArrayWrappersCount: 2,
|
||||
stringArrayWrappersChainedCalls: true,
|
||||
stringArrayThreshold: 0.75,
|
||||
splitStrings: true,
|
||||
splitStringsChunkLength: 10,
|
||||
numbersToExpressions: true,
|
||||
transformObjectKeys: true,
|
||||
unicodeEscapeSequence: true,
|
||||
debugProtection: true,
|
||||
debugProtectionInterval: 2000,
|
||||
disableConsoleOutput: true,
|
||||
ignoreImports: true,
|
||||
controlFlowFlattening: false,
|
||||
deadCodeInjection: false,
|
||||
selfDefending: false,
|
||||
log: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
@@ -26,6 +62,7 @@ export default defineConfig({
|
||||
},
|
||||
build: {
|
||||
chunkSizeWarningLimit: 700,
|
||||
sourcemap: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
|
||||
Reference in New Issue
Block a user