vite.config.js 3.0 KB

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