猎羽广告

vite.config.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import fs from 'fs';
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import Components from 'unplugin-vue-components/vite'
  7. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  8. import Icons from 'unplugin-icons/vite'
  9. import IconsResolver from 'unplugin-icons/resolver'
  10. import topLevelAwait from 'vite-plugin-top-level-await'
  11. // 手动导入
  12. import ElementPlus from 'unplugin-element-plus/vite'
  13. // https://vitejs.dev/config/
  14. export default defineConfig(({ mode}) => {
  15. return{
  16. base: './',
  17. css: {
  18. preprocessorOptions: {
  19. scss: {
  20. // 自定义的主题色
  21. additionalData: `@use "@/assets/style/element/index.scss" as *;`,
  22. },
  23. },
  24. },
  25. plugins: [
  26. vue(),
  27. ElementPlus({
  28. useSource: true,
  29. }),
  30. AutoImport({
  31. imports: ["vue", "vue-router"],
  32. resolvers: [
  33. IconsResolver(),
  34. ElementPlusResolver({
  35. // 自动引入修改主题色添加这一行,使用预处理样式,不添加将会导致使用ElMessage,ElNotification等组件时默认的主题色会覆盖自定义的主题色
  36. // importStyle: "sass",
  37. importStyle: mode === "development" ? false : "sass",
  38. })
  39. ],
  40. }),
  41. Components({
  42. resolvers: [
  43. IconsResolver(),
  44. ElementPlusResolver({
  45. // 自动引入修改主题色添加这一行,使用预处理样式
  46. // importStyle: "sass",
  47. importStyle: mode === "development" ? false : "sass",
  48. })
  49. ],
  50. }),
  51. Icons({
  52. autoInstall: true,
  53. }),
  54. topLevelAwait({
  55. // The export name of top-level await promise for each chunk module
  56. promiseExportName: '__tla',
  57. // The function to generate import names of top-level await promise in each chunk module
  58. promiseImportName: i => `__tla_${i}`
  59. })
  60. ],
  61. server: {
  62. host: '0.0.0.0', //解决“vite use `--host` to expose”
  63. port: 8080,
  64. open: false,
  65. hmr:true,
  66. cors: true, // 允许跨域
  67. proxy: {
  68. '/api': {
  69. target: "http://idea-ad.wenxingshuju.com",
  70. changeOrigin: true,
  71. secure: false,
  72. },
  73. }
  74. },
  75. resolve:{
  76. alias:[
  77. {
  78. find:'@',
  79. replacement:resolve(__dirname,'src')
  80. }
  81. ]
  82. },
  83. build: {
  84. outDir: "dist",
  85. // outDir:'../',
  86. // /** 打包后静态资源目录 */
  87. // assetsDir: "./static",
  88. sourcemap: false,
  89. minify: 'terser',
  90. chunkSizeWarningLimit: 1500,
  91. terserOptions: {
  92. compress: {
  93. drop_console: false,
  94. drop_debugger: false
  95. }
  96. },
  97. rollupOptions: {
  98. output: {
  99. manualChunks(id) {
  100. if (id.includes('node_modules')) {
  101. return id
  102. .toString()
  103. .split('node_modules/')[1]
  104. .split('/')[0]
  105. .toString();
  106. }
  107. },
  108. chunkFileNames: (chunkInfo) => {
  109. const facadeModuleId = chunkInfo.facadeModuleId
  110. ? chunkInfo.facadeModuleId.split('/')
  111. : [];
  112. const fileName =
  113. facadeModuleId[facadeModuleId.length - 2] || '[name]';
  114. return `js/${fileName}/[name].[hash].js`;
  115. }
  116. }
  117. }
  118. },
  119. }
  120. })