vite.config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 styleImport from 'vite-plugin-style-import'
  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. plugins: [
  18. vue(),
  19. vueJsx(),
  20. vueSetupExtend(),
  21. styleImport({
  22. libs: [{
  23. libraryName: 'element-plus',
  24. resolveStyle: (name) => {
  25. return `element-plus/es/components/${name.split('el-')[1]}/style/css`
  26. }
  27. }]
  28. }),
  29. Components({
  30. dts: true,
  31. resolvers: [ElementPlusResolver()]
  32. }),
  33. eslintPlugin({
  34. cache: false,
  35. include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件
  36. }),
  37. viteSvgIcons({
  38. // 指定需要缓存的图标文件夹
  39. iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
  40. // 指定symbolId格式
  41. symbolId: 'icon-[dir]-[name]',
  42. // 压缩
  43. svgoOptions: true
  44. }),
  45. commonjsExternals({
  46. externals: ['path']
  47. })
  48. ],
  49. css: {
  50. preprocessorOptions: {
  51. less: {
  52. additionalData: '@import "./src/styles/variables.less";',
  53. javascriptEnabled: true
  54. }
  55. }
  56. },
  57. resolve: {
  58. alias: [
  59. {
  60. find: /\@\//,
  61. replacement: pathResolve('src') + '/'
  62. },
  63. {
  64. find: /\_v\//,
  65. replacement: pathResolve('src/views') + '/'
  66. },
  67. {
  68. find: /\_c\//,
  69. replacement: pathResolve('src/components') + '/'
  70. }
  71. ]
  72. }
  73. })