vite.config.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import vue from '@vitejs/plugin-vue';
  2. import path from 'path';
  3. import { ConfigEnv, defineConfig, UserConfigExport } from 'vite';
  4. import ViteComponents, { AntDesignVueResolver } from 'vite-plugin-components';
  5. import OptimizationPersist from 'vite-plugin-optimize-persist';
  6. import PkgConfig from 'vite-plugin-package-config';
  7. import viteSvgIcons from 'vite-plugin-svg-icons';
  8. import { viteVConsole } from 'vite-plugin-vconsole';
  9. export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig({
  10. plugins: [
  11. vue(),
  12. ViteComponents({
  13. customComponentResolvers: [AntDesignVueResolver()],
  14. }),
  15. viteSvgIcons({
  16. // 指定需要缓存的图标文件夹
  17. iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
  18. // 指定symbolId格式
  19. symbolId: 'icon-[dir]-[name]',
  20. }),
  21. viteVConsole({
  22. entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
  23. localEnabled: command === 'serve', // serve开发环境下
  24. config: { // vconsole 配置项
  25. maxLogNumber: 1000,
  26. theme: 'light'
  27. }
  28. }),
  29. PkgConfig(),
  30. OptimizationPersist()
  31. ],
  32. server: {
  33. open: true,
  34. host: '0.0.0.0',
  35. port: 8080,
  36. // proxy: {
  37. // '/api': {
  38. // target: 'http://192.168.3.42:6789',
  39. // changeOrigin: true,
  40. // rewrite: (path) => path.replace(/^\/api/, '')
  41. // }
  42. // }
  43. },
  44. envDir: './env',
  45. resolve: {
  46. alias: [{
  47. find: '/@',
  48. replacement: path.resolve(__dirname, './src'),
  49. }
  50. ]
  51. },
  52. css: {
  53. preprocessorOptions: {
  54. scss: {
  55. additionalData: '@import "./src/styles/variables";'
  56. },
  57. }
  58. },
  59. base: '/',
  60. build: {
  61. target: ['es2015'], // 最低支持 es2015
  62. sourcemap: true
  63. }
  64. })