vite.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import AutoImport from 'unplugin-auto-import/vite'
  2. import Components from 'unplugin-vue-components/vite'
  3. import Icons from 'unplugin-icons/vite'
  4. import IconsResolver from 'unplugin-icons/resolver'
  5. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  6. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  7. import { defineConfig, loadEnv } from 'vite'
  8. import vue from '@vitejs/plugin-vue'
  9. import Inspect from 'vite-plugin-inspect'
  10. import path from 'path'
  11. // eslint-disable-next-line no-undef
  12. const pathSrc = path.resolve(__dirname, 'src')
  13. // https://vitejs.dev/config/
  14. export default defineConfig(({ mode }) => {
  15. // eslint-disable-next-line no-undef
  16. const env = loadEnv(mode, process.cwd())
  17. return {
  18. base: `/${env.VITE_OUT_DIR}`,
  19. build: {
  20. outDir: 'admin'
  21. },
  22. server: {
  23. // 允许IP访问
  24. host: '0.0.0.0',
  25. // 应用端口 (默认:3000)
  26. port: Number(env.VITE_APP_PORT),
  27. // 运行是否自动打开浏览器
  28. open: true,
  29. proxy: {
  30. '/files': {
  31. target: [env.VITE_APP_BASE_API_PROXY], // https://broadcast.waityou24.cn
  32. changeOrigin: true
  33. },
  34. /**
  35. * env.VITE_APP_BASE_API: /dev-api
  36. */
  37. [env.VITE_APP_BASE_API]: {
  38. changeOrigin: true,
  39. target: 'http://127.0.0.1:9001'
  40. }
  41. }
  42. },
  43. resolve: {
  44. alias: {
  45. '@': pathSrc
  46. }
  47. },
  48. css: {
  49. // CSS 预处理器
  50. preprocessorOptions: {
  51. // 定义全局 SCSS 变量
  52. scss: {
  53. javascriptEnabled: true
  54. // additionalData: `
  55. // @use "@/styles/variables.scss" as *;
  56. // `
  57. }
  58. }
  59. },
  60. plugins: [
  61. vue(),
  62. // // 自动导入参考: https://github.com/sxzz/element-plus-best-practices/blob/main/vite.config.ts
  63. AutoImport({
  64. // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
  65. imports: ['vue', '@vueuse/core', 'pinia', 'vue-router', 'vue-i18n'],
  66. // 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
  67. resolvers: [ElementPlusResolver(), IconsResolver({})],
  68. eslintrc: {
  69. enabled: false,
  70. filepath: './.eslintrc-auto-import.json',
  71. globalsPropValue: true
  72. },
  73. vueTemplate: true
  74. // 配置文件生成位置(false:关闭自动生成)
  75. //dts: false,
  76. // dts: path.resolve(pathSrc, 'auto-imports.d.ts')
  77. }),
  78. Components({
  79. resolvers: [
  80. // 自动导入 Element Plus 组件
  81. ElementPlusResolver(),
  82. // 自动注册图标组件
  83. IconsResolver({ enabledCollections: ['ep'] })
  84. ],
  85. // 指定自定义组件位置(默认:src/components)
  86. dirs: ['src/components', 'src/**/components']
  87. // 配置文件位置 (false:关闭自动生成)
  88. //dts: false,
  89. // dts: path.resolve(pathSrc, 'components.d.ts')
  90. }),
  91. Icons({
  92. autoInstall: true
  93. }),
  94. createSvgIconsPlugin({
  95. // 指定需要缓存的图标文件夹
  96. iconDirs: [path.resolve(pathSrc, 'assets/icons')],
  97. // 指定symbolId格式
  98. symbolId: 'icon-[dir]-[name]'
  99. }),
  100. Inspect()
  101. ],
  102. // 预加载项目必需的组件
  103. optimizeDeps: {
  104. include: [
  105. 'vue',
  106. 'vue-router',
  107. 'pinia',
  108. 'axios',
  109. 'element-plus/es/components/form/style/css',
  110. 'element-plus/es/components/form-item/style/css',
  111. 'element-plus/es/components/button/style/css',
  112. 'element-plus/es/components/input/style/css',
  113. 'element-plus/es/components/input-number/style/css',
  114. 'element-plus/es/components/switch/style/css',
  115. 'element-plus/es/components/upload/style/css',
  116. 'element-plus/es/components/menu/style/css',
  117. 'element-plus/es/components/col/style/css',
  118. 'element-plus/es/components/icon/style/css',
  119. 'element-plus/es/components/row/style/css',
  120. 'element-plus/es/components/tag/style/css',
  121. 'element-plus/es/components/dialog/style/css',
  122. 'element-plus/es/components/loading/style/css',
  123. 'element-plus/es/components/radio/style/css',
  124. 'element-plus/es/components/radio-group/style/css',
  125. 'element-plus/es/components/popover/style/css',
  126. 'element-plus/es/components/scrollbar/style/css',
  127. 'element-plus/es/components/tooltip/style/css',
  128. 'element-plus/es/components/dropdown/style/css',
  129. 'element-plus/es/components/dropdown-menu/style/css',
  130. 'element-plus/es/components/dropdown-item/style/css',
  131. 'element-plus/es/components/sub-menu/style/css',
  132. 'element-plus/es/components/menu-item/style/css',
  133. 'element-plus/es/components/divider/style/css',
  134. 'element-plus/es/components/card/style/css',
  135. 'element-plus/es/components/link/style/css',
  136. 'element-plus/es/components/breadcrumb/style/css',
  137. 'element-plus/es/components/breadcrumb-item/style/css',
  138. 'element-plus/es/components/table/style/css',
  139. 'element-plus/es/components/tree-select/style/css',
  140. 'element-plus/es/components/table-column/style/css',
  141. 'element-plus/es/components/select/style/css',
  142. 'element-plus/es/components/option/style/css',
  143. 'element-plus/es/components/pagination/style/css',
  144. 'element-plus/es/components/tree/style/css',
  145. 'element-plus/es/components/alert/style/css',
  146. 'element-plus/es/components/radio-button/style/css',
  147. 'element-plus/es/components/checkbox-group/style/css',
  148. 'element-plus/es/components/checkbox/style/css',
  149. 'element-plus/es/components/tabs/style/css',
  150. 'element-plus/es/components/tab-pane/style/css',
  151. 'element-plus/es/components/rate/style/css',
  152. 'element-plus/es/components/date-picker/style/css',
  153. 'element-plus/es/components/notification/style/css',
  154. 'element-plus/es/components/image/style/css',
  155. 'element-plus/es/components/statistic/style/css',
  156. 'element-plus/es/components/watermark/style/css',
  157. 'element-plus/es/components/config-provider/style/css',
  158. 'vue-i18n',
  159. 'element-plus/es/components/text/style/css',
  160. '@vueuse/core'
  161. // 'sortablejs',
  162. // 'path-to-regexp',
  163. // 'echarts',
  164. // '@wangeditor/editor',
  165. // '@wangeditor/editor-for-vue',
  166. // 'path-browserify'
  167. ]
  168. }
  169. }
  170. })