vite.config.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { resolve } from 'path'
  2. import { defineConfig } from 'vite'
  3. import legacyPlugin from '@vitejs/plugin-legacy'
  4. import { obfuscator } from 'rollup-obfuscator'
  5. // https://vitejs.dev/config/
  6. export default defineConfig({
  7. build: {
  8. minify: true,
  9. target: 'es2015',
  10. assetsDir: './',
  11. outDir: '../../dist/page_decrypt',
  12. emptyOutDir: true,
  13. rollupOptions: {
  14. input: {
  15. main: resolve(__dirname, 'index.html'),
  16. // decrypt: resolve(__dirname, 'decrypt-js/decrypt-js.html'),
  17. },
  18. output: {
  19. manualChunks: {
  20. 'decrypt-pre1': [
  21. 'src/decrypt-pre1.js'
  22. ],
  23. 'decrypt-pre2': [
  24. 'src/decrypt-pre2.js'
  25. ]
  26. }
  27. },
  28. plugins: [
  29. // 代码混淆
  30. // https://juejin.cn/post/7216915438297677882
  31. // https://juejin.cn/post/7292692843415109641 有更详细的配置
  32. obfuscator({
  33. compact: true,
  34. controlFlowFlattening: true,
  35. controlFlowFlatteningThreshold: 1,
  36. deadCodeInjection: true,
  37. deadCodeInjectionThreshold: 1,
  38. debugProtection: true,
  39. debugProtectionInterval: 0,
  40. disableConsoleOutput: true,
  41. identifierNamesGenerator: 'hexadecimal',
  42. log: false,
  43. renameGlobals: false,
  44. rotateStringArray: true,
  45. selfDefending: true,
  46. shuffleStringArray: true,
  47. splitStrings: true,
  48. splitStringsChunkLength: 10,
  49. stringArray: true,
  50. stringArrayEncoding: ['rc4'],
  51. stringArrayThreshold: 1,
  52. transformObjectKeys: true,
  53. unicodeEscapeSequence: false,
  54. }),
  55. ]
  56. },
  57. },
  58. plugins: [
  59. // https://juejin.cn/post/7358306245349605402
  60. legacyPlugin({
  61. // 如果不设置targets,默认值为'last 2 versions and not dead, > 0.3%, Firefox ESR'
  62. // 需要兼容的目标列表,可以设置多个
  63. targets: ['chrome 52'],
  64. }),
  65. ]
  66. })