vite.config.ts 2.1 KB

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