vite.config.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import vue from '@vitejs/plugin-vue'
  2. import path from 'path'
  3. import { ConfigEnv, defineConfig, UserConfigExport } from 'vite'
  4. import { viteVConsole } from 'vite-plugin-vconsole'
  5. export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig({
  6. base: '/',
  7. css: {
  8. preprocessorOptions: {
  9. scss: {
  10. additionalData: '@import "./src/styles/variables";'
  11. },
  12. }
  13. },
  14. resolve: {
  15. alias: [
  16. {
  17. find: '/@',
  18. replacement: path.resolve(__dirname, './src'),
  19. }
  20. ]
  21. },
  22. server: {
  23. open: true,
  24. host: '0.0.0.0',
  25. port: 8080,
  26. proxy: {
  27. '/api': {
  28. // 开启跨域
  29. changeOrigin: true,
  30. // 转发地址
  31. target: 'http://192.168.3.42:6789',
  32. // 路径重写
  33. rewrite: (path) => path.replace(/^\/api/, ''),
  34. }
  35. }
  36. },
  37. build: {
  38. target: ['es2015'], // 最低支持 es2015
  39. sourcemap: true
  40. },
  41. plugins: [
  42. vue(),
  43. viteVConsole({
  44. entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
  45. localEnabled: command === 'serve', // serve开发环境下
  46. // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
  47. config: { // vconsole 配置项
  48. maxLogNumber: 1000,
  49. theme: 'light'
  50. }
  51. }),
  52. ],
  53. })