vite.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(env)
  20. return {
  21. base: mode === 'development' ? '/' : '/web',
  22. build: {
  23. outDir: 'web'
  24. },
  25. plugins: [
  26. vue(),
  27. // VueDevTools(),
  28. VueSetupExtend(),
  29. createAutoImport(),
  30. AutoImport({
  31. resolvers: [VantResolver()]
  32. }),
  33. Components({
  34. resolvers: [VantResolver()]
  35. })
  36. ],
  37. resolve: {
  38. alias: {
  39. '@': fileURLToPath(new URL('./src', import.meta.url))
  40. }
  41. },
  42. server: {
  43. host: true,
  44. proxy: {
  45. '/dev-api': {
  46. target: 'http://172.16.10.61:8080',
  47. // target: 'https://vue.ruoyi.vip/prod-api',
  48. changeOrigin: true,
  49. rewrite: (p) => p.replace(/^\/dev-api/, '')
  50. }
  51. }
  52. },
  53. //配置sass
  54. css: {
  55. preprocessorOptions: {
  56. scss: {
  57. additionalData:
  58. '@import "./src/assets/scss/globalVar.scss";@import "./src/assets/scss/globalMixin.scss";'
  59. }
  60. }
  61. }
  62. }
  63. })