vite.config.js 2.0 KB

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