vite.config.js 3.1 KB

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