vite.config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import VueDevTools from 'vite-plugin-vue-devtools'
  5. import VueSetupExtend from 'vite-plugin-vue-setup-extend'
  6. import autoImport from 'unplugin-auto-import/vite'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. import Components from 'unplugin-vue-components/vite'
  9. import { VantResolver } from '@vant/auto-import-resolver'
  10. const createAutoImport = () => {
  11. return autoImport({
  12. imports: ['vue', 'vue-router', 'pinia'],
  13. dts: false
  14. })
  15. }
  16. // https://vitejs.dev/config/
  17. export default defineConfig(({ mode }) => {
  18. const env = loadEnv(mode, process.cwd())
  19. console.log(mode, env)
  20. const plugins = [
  21. vue(),
  22. VueSetupExtend(),
  23. createAutoImport(),
  24. AutoImport({
  25. resolvers: [VantResolver()]
  26. }),
  27. Components({
  28. resolvers: [VantResolver()]
  29. })
  30. ]
  31. if (mode === 'development') {
  32. plugins.push(VueDevTools())
  33. }
  34. return {
  35. plugins: plugins,
  36. resolve: {
  37. alias: {
  38. '@': fileURLToPath(new URL('./src', import.meta.url))
  39. }
  40. },
  41. server: {
  42. host: true,
  43. proxy: {
  44. '/dev-api': {
  45. target: 'http://172.16.10.61:8080/prod-api',
  46. // target: 'https://vue.ruoyi.vip/prod-api',
  47. changeOrigin: true,
  48. rewrite: (p) => p.replace(/^\/dev-api/, '')
  49. }
  50. }
  51. },
  52. //配置sass
  53. css: {
  54. preprocessorOptions: {
  55. scss: {
  56. additionalData:
  57. '@import "./src/assets/scss/globalVar.scss";@import "./src/assets/scss/globalMixin.scss";'
  58. }
  59. }
  60. }
  61. }
  62. })