vite.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from "path"
  4. import AutoImport from 'unplugin-auto-import/vite'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  7. import ElementPlus from "unplugin-element-plus/vite"
  8. import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
  9. // import vitePluginImagemin from 'vite-plugin-imagemin'
  10. // Element-plus 图标按需引入和自动引入
  11. // import Icons from "unplugin-icons/vite"
  12. // import IconsResolver from "unplugin-icons/resolver"
  13. const pathSrc = path.resolve(__dirname, 'src')
  14. // https://vitejs.dev/config/
  15. export default defineConfig({
  16. plugins: [
  17. vue(),
  18. // 自动导入
  19. AutoImport({
  20. imports:['vue'],
  21. resolvers: [
  22. ElementPlusResolver(),
  23. // IconsResolver({
  24. // prefix: "Icon",
  25. // }),
  26. ],
  27. dts: path.resolve(pathSrc, "auto-imports.d.ts")
  28. }),
  29. // Element-plus 按需引入
  30. Components({
  31. resolvers: [
  32. ElementPlusResolver(),
  33. // IconsResolver({
  34. // enabledCollections: ["ep"],
  35. // })
  36. ],
  37. dts: path.resolve(pathSrc, "components.d.ts"),
  38. }),
  39. // Icons({
  40. // autoInstall: true,
  41. // }),
  42. // 样式问题
  43. ElementPlus({
  44. importStyle: "sass",
  45. useSource: true
  46. }),
  47. // //图片压缩
  48. // vitePluginImagemin({
  49. // gifsicle: {
  50. // optimizationLevel: 7,
  51. // interlaced: false
  52. // }
  53. // }),
  54. createSvgIconsPlugin({
  55. // 指定需要缓存的图标文件夹
  56. iconDirs: [path.resolve(process.cwd(), 'src/assets/svg-icons')],
  57. // 指定symbolId格式
  58. symbolId: 'svgIcon-[dir]-[name]',
  59. /**
  60. * 自定义插入位置
  61. * @default: body-last
  62. */
  63. // inject?: 'body-last' | 'body-first'
  64. /**
  65. * custom dom id
  66. * @default: __svg__icons__dom__
  67. */
  68. // customDomId: '__svg__icons__dom__'
  69. })
  70. ],
  71. resolve:{
  72. alias:{
  73. "@":path.resolve(__dirname,"./src")
  74. }
  75. },
  76. css: {
  77. preprocessorOptions: {
  78. scss: {
  79. additionalData: `@use "@/styles/element.scss" as *; @use "@/styles/theme.scss" as *;`
  80. }
  81. }
  82. },
  83. server:{
  84. host:true
  85. },
  86. build:{
  87. outDir: 'hongze_fsms_web',
  88. minify:'terser',
  89. terserOptions:{
  90. compress:{
  91. drop_console:true,
  92. drop_debugger:true
  93. },
  94. output:{
  95. comments:true
  96. }
  97. },
  98. rollupOptions:{
  99. output:{
  100. manualChunks(id){
  101. if(id.includes('node_modules')){
  102. if(id.includes('element-plus')){
  103. // element-plus 单独打包
  104. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  105. }
  106. // tinymce富文本编辑器单独打包
  107. if(id.includes('tinymce')){
  108. // tinymce富文本的themes比较大,单独打包成一个js
  109. if(id.toString().split('node_modules/')[1].split('/')[1]=='themes'){
  110. return id.toString().split('node_modules/')[1].split('/')[0].toString()+'-'+id.toString().split('node_modules/')[1].split('/')[1].toString()
  111. }else{
  112. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  113. }
  114. }
  115. }
  116. },
  117. chunkFileNames:'assets/js/[name]-[hash].js',
  118. entryFileNames:'assets/js/[name]-[hash].js',
  119. assetFileNames:(file)=>{
  120. if(file.name.endsWith('.css')){
  121. return 'assets/css/[name]-[hash].css'
  122. }else{
  123. return 'assets/media/[name]-[hash].[ext]'
  124. }
  125. }
  126. }
  127. }
  128. }
  129. })