vite.config.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import vue from '@vitejs/plugin-vue'
  2. // config alias
  3. import path from 'path'
  4. import { ConfigEnv, defineConfig, UserConfigExport } from 'vite'
  5. import ViteComponents, { AntDesignVueResolver } from 'vite-plugin-components'
  6. // Introduce eslint plugin
  7. import eslintPlugin from 'vite-plugin-eslint'
  8. import OptimizationPersist from 'vite-plugin-optimize-persist'
  9. import PkgConfig from 'vite-plugin-package-config'
  10. import viteSvgIcons from 'vite-plugin-svg-icons'
  11. import { viteVConsole } from 'vite-plugin-vconsole'
  12. // https://vitejs.dev/config/
  13. export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig({
  14. plugins: [
  15. vue(),
  16. eslintPlugin({
  17. fix: true
  18. }),
  19. ViteComponents({
  20. customComponentResolvers: [AntDesignVueResolver()],
  21. }),
  22. viteSvgIcons({
  23. // 指定需要缓存的图标文件夹
  24. iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
  25. // 指定symbolId格式
  26. symbolId: 'icon-[dir]-[name]',
  27. }),
  28. viteVConsole({
  29. entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
  30. localEnabled: command === 'serve', // serve开发环境下
  31. // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
  32. config: { // vconsole 配置项
  33. maxLogNumber: 1000,
  34. theme: 'light'
  35. }
  36. }),
  37. PkgConfig(),
  38. OptimizationPersist()
  39. // [svgBuilder('./src/assets/icons/')] // All svg under src/icons/svg/ have been imported here, no need to import separately
  40. ],
  41. server: {
  42. open: true,
  43. host: '0.0.0.0',
  44. port: 8080
  45. },
  46. envDir: './env',
  47. resolve: {
  48. alias: [{
  49. // https://github.com/vitejs/vite/issues/279#issuecomment-635646269
  50. find: '/@',
  51. replacement: path.resolve(__dirname, './src'),
  52. }
  53. ]
  54. },
  55. css: {
  56. preprocessorOptions: {
  57. scss: {
  58. // example : additionalData: `@import "./src/design/styles/variables";`
  59. // dont need include file extend .scss
  60. additionalData: '@import "./src/styles/variables";'
  61. },
  62. }
  63. },
  64. base: '/',
  65. build: {
  66. target: ['es2015'], // 最低支持 es2015
  67. sourcemap: true
  68. }
  69. })