vite.config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import eslint from 'vite-plugin-eslint'
  4. import { resolve } from 'path'
  5. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  6. import electron from 'vite-electron-plugin'
  7. import obfuscatorPlugin from "vite-plugin-javascript-obfuscator"
  8. export default () => defineConfig({
  9. base: './',
  10. resolve: {
  11. alias: {
  12. '@': resolve(__dirname, './src')
  13. }
  14. },
  15. plugins: [
  16. vue(),
  17. eslint({ fix: true, include: ['**/*.ts', '**/*.vue'] }),
  18. createSvgIconsPlugin({
  19. iconDirs: [resolve(__dirname, './src/assets/icons')],
  20. // Specify symbolId format
  21. symbolId: 'icon-[dir]-[name]'
  22. }),
  23. electron({
  24. include: ['electron/main.js'],
  25. outDir: 'dist/electron/'
  26. }),
  27. obfuscatorPlugin({
  28. debugger: false,
  29. apply: "build",
  30. options: {
  31. compact: true,
  32. deadCodeInjection: true,
  33. debugProtection: true,
  34. disableConsoleOutput: true,
  35. renameGlobals: true,
  36. splitStrings: true,
  37. unicodeEscapeSequence: true
  38. }
  39. })
  40. ],
  41. server: {
  42. host: '0.0.0.0',
  43. port: 6547,
  44. open: false,
  45. strictPort: false,
  46. https: false,
  47. },
  48. build: {
  49. rollupOptions: {
  50. input: {
  51. index: resolve(__dirname, 'index.html')
  52. },
  53. output: { // 静态资源分类打包
  54. chunkFileNames: 'js/[hash].js',
  55. entryFileNames: 'js/[hash].js',
  56. assetFileNames: 'assets/[ext]/[hash].[ext]',
  57. // 拆分node_modules包
  58. manualChunks: (id) => {
  59. if (id.includes('node_modules')) {
  60. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  61. }
  62. return ''
  63. }
  64. }
  65. },
  66. outDir: 'dist/electron/'
  67. },
  68. define: {
  69. __VUE_OPTIONS_API__: false
  70. }
  71. })