vite.config.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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-plugin-electron'
  7. export default () => defineConfig({
  8. base: './',
  9. resolve: {
  10. alias: {
  11. '@': resolve(__dirname, './src')
  12. }
  13. },
  14. plugins: [
  15. vue(),
  16. eslint({ fix: true, include: ['**/*.ts', '**/*.vue'] }),
  17. createSvgIconsPlugin({
  18. iconDirs: [resolve(__dirname, './src/assets/icons')],
  19. // Specify symbolId format
  20. symbolId: 'icon-[dir]-[name]'
  21. }),
  22. electron({
  23. entry: 'electron/main.js',
  24. vite: { build: { outDir: 'dist/electron/' } }
  25. }),
  26. ],
  27. server: {
  28. host: '0.0.0.0',
  29. port: 6547,
  30. open: false,
  31. strictPort: false,
  32. https: false,
  33. },
  34. // esbuild: {
  35. // drop: ['console', 'debugger'] // build 移除打印
  36. // },
  37. build: {
  38. rollupOptions: {
  39. input: {
  40. index: resolve(__dirname, 'index.html')
  41. },
  42. output: { // 静态资源分类打包
  43. chunkFileNames: 'js/[hash].js',
  44. entryFileNames: 'js/[hash].js',
  45. assetFileNames: 'assets/[ext]/[hash].[ext]',
  46. // 拆分node_modules包
  47. manualChunks: (id) => {
  48. if (id.includes('node_modules')) {
  49. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  50. }
  51. return ''
  52. }
  53. }
  54. },
  55. outDir: 'dist/electron/'
  56. },
  57. define: {
  58. __VUE_OPTIONS_API__: false
  59. }
  60. })