vite.config.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
  25. config: { // vconsole 配置项
  26. maxLogNumber: 1000,
  27. theme: 'light'
  28. }
  29. }),
  30. PkgConfig(),
  31. OptimizationPersist()
  32. // [svgBuilder('./src/assets/icons/')] // All svg under src/icons/svg/ have been imported here, no need to import separately
  33. ],
  34. server: {
  35. open: true,
  36. host: '0.0.0.0',
  37. port: 8080
  38. },
  39. resolve: {
  40. alias: [
  41. {
  42. find: '/@',
  43. replacement: path.resolve(__dirname, './src'),
  44. }
  45. ]
  46. },
  47. css: {
  48. preprocessorOptions: {
  49. scss: {
  50. // example : additionalData: `@import "./src/design/styles/variables";`
  51. // dont need include file extend .scss
  52. additionalData: '@import "./src/styles/variables";'
  53. },
  54. }
  55. },
  56. base: '/',
  57. build: {
  58. target: ['es2015'], // 最低支持 es2015
  59. sourcemap: true
  60. }
  61. })