vite.config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import Components from 'unplugin-vue-components/vite'
  4. import { resolve } from 'path'
  5. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  6. import vueJsx from '@vitejs/plugin-vue-jsx'
  7. import vueSetupExtend from 'vite-plugin-vue-setup-extend'
  8. import eslintPlugin from 'vite-plugin-eslint'
  9. import ElementPlus from 'unplugin-element-plus/vite'
  10. import viteSvgIcons from 'vite-plugin-svg-icons'
  11. import commonjsExternals from 'vite-plugin-commonjs-externals'
  12. function pathResolve(dir: string) {
  13. return resolve(process.cwd(), '.', dir)
  14. }
  15. // https://vitejs.dev/config/
  16. export default defineConfig({
  17. // base: '/dist-pro/',
  18. plugins: [
  19. vue(),
  20. vueJsx(),
  21. vueSetupExtend(),
  22. ElementPlus({
  23. useSource: false
  24. }),
  25. Components({
  26. dts: true,
  27. resolvers: [ElementPlusResolver()]
  28. }),
  29. eslintPlugin({
  30. cache: false,
  31. include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件
  32. }),
  33. viteSvgIcons({
  34. // 指定需要缓存的图标文件夹
  35. iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
  36. // 指定symbolId格式
  37. symbolId: 'icon-[dir]-[name]',
  38. // 压缩
  39. svgoOptions: true
  40. }),
  41. commonjsExternals({
  42. externals: ['path']
  43. })
  44. ],
  45. css: {
  46. preprocessorOptions: {
  47. less: {
  48. additionalData: '@import "./src/styles/variables.less";',
  49. javascriptEnabled: true
  50. }
  51. }
  52. },
  53. resolve: {
  54. alias: [
  55. {
  56. find: /\@\//,
  57. replacement: pathResolve('src') + '/'
  58. },
  59. {
  60. find: /\_v\//,
  61. replacement: pathResolve('src/views') + '/'
  62. },
  63. {
  64. find: /\_c\//,
  65. replacement: pathResolve('src/components') + '/'
  66. }
  67. ]
  68. },
  69. build: {
  70. sourcemap: true
  71. }
  72. })