import { resolve } from 'path' import { defineConfig } from 'vite' import legacyPlugin from '@vitejs/plugin-legacy' import { obfuscator } from 'rollup-obfuscator' // https://vitejs.dev/config/ export default defineConfig({ base: '/page_decrypt/', build: { minify: true, target: 'es2015', assetsDir: './', outDir: '../../dist/page_decrypt', emptyOutDir: true, rollupOptions: { input: { main: resolve(__dirname, 'index.html'), // decrypt: resolve(__dirname, 'decrypt-js/decrypt-js.html'), }, output: { manualChunks: { 'decrypt-pre1': [ 'src/decrypt-pre1.js' ], 'decrypt-pre2': [ 'src/decrypt-pre2.js' ] } }, plugins: [ // 代码混淆 // https://juejin.cn/post/7216915438297677882 // https://juejin.cn/post/7292692843415109641 有更详细的配置 obfuscator({ compact: true, controlFlowFlattening: true, controlFlowFlatteningThreshold: 1, deadCodeInjection: true, deadCodeInjectionThreshold: 1, debugProtection: true, debugProtectionInterval: 0, disableConsoleOutput: true, identifierNamesGenerator: 'hexadecimal', log: false, renameGlobals: false, rotateStringArray: true, selfDefending: true, shuffleStringArray: true, splitStrings: true, splitStringsChunkLength: 10, stringArray: true, stringArrayEncoding: ['rc4'], stringArrayThreshold: 1, transformObjectKeys: true, unicodeEscapeSequence: false, }), ] }, }, plugins: [ // https://juejin.cn/post/7358306245349605402 legacyPlugin({ // 如果不设置targets,默认值为'last 2 versions and not dead, > 0.3%, Firefox ESR' // 需要兼容的目标列表,可以设置多个 targets: ['chrome 52'], }), ] })