vite.config.js 6.7 KB

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