酷炫&聚星API数据系统

vite.config.ts 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import AutoImport from 'unplugin-auto-import/vite'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  7. import Icons from 'unplugin-icons/vite'
  8. import IconsResolver from 'unplugin-icons/resolver'
  9. // 手动导入
  10. import ElementPlus from 'unplugin-element-plus/vite'
  11. // https://vitejs.dev/config/
  12. export default defineConfig(({ mode}) => {
  13. return{
  14. base: './',
  15. css: {
  16. preprocessorOptions: {
  17. scss: {
  18. // 自定义的主题色
  19. additionalData: `@use "@/assets/style/element/index.scss" as *;`,
  20. },
  21. },
  22. },
  23. plugins: [
  24. vue(),
  25. ElementPlus({
  26. useSource: true,
  27. }),
  28. AutoImport({
  29. imports: ["vue", "vue-router"],
  30. resolvers: [
  31. IconsResolver(),
  32. ElementPlusResolver({
  33. // 自动引入修改主题色添加这一行,使用预处理样式,不添加将会导致使用ElMessage,ElNotification等组件时默认的主题色会覆盖自定义的主题色
  34. importStyle: "sass",
  35. })
  36. ],
  37. }),
  38. Components({
  39. resolvers: [
  40. IconsResolver(),
  41. ElementPlusResolver({
  42. // 自动引入修改主题色添加这一行,使用预处理样式
  43. importStyle: "sass",
  44. })
  45. ],
  46. }),
  47. Icons({
  48. autoInstall: true,
  49. }),
  50. ],
  51. server: {
  52. host: '0.0.0.0', //解决“vite use `--host` to expose”
  53. port: 8080,
  54. open: false,
  55. hmr:true,
  56. cors: true, // 允许跨域
  57. proxy: {
  58. '/api': {
  59. // target: "http://39.106.149.78",
  60. target: "http://zhitou.wenxingshuju.com",
  61. changeOrigin: true,
  62. secure: false,
  63. },
  64. }
  65. },
  66. resolve:{
  67. alias:[
  68. {
  69. find:'@',
  70. replacement:resolve(__dirname,'src')
  71. }
  72. ]
  73. },
  74. build: {
  75. outDir: "dist",
  76. sourcemap: false,
  77. minify: 'terser',
  78. chunkSizeWarningLimit: 1500,
  79. terserOptions: {
  80. compress: {
  81. drop_console: true,
  82. drop_debugger: true
  83. }
  84. },
  85. rollupOptions: {
  86. output: {
  87. manualChunks(id) {
  88. if (id.includes('node_modules')) {
  89. return id
  90. .toString()
  91. .split('node_modules/')[1]
  92. .split('/')[0]
  93. .toString();
  94. }
  95. },
  96. chunkFileNames: (chunkInfo) => {
  97. const facadeModuleId = chunkInfo.facadeModuleId
  98. ? chunkInfo.facadeModuleId.split('/')
  99. : [];
  100. const fileName =
  101. facadeModuleId[facadeModuleId.length - 2] || '[name]';
  102. return `js/${fileName}/[name].[hash].js`;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. })