猎羽广告

vite.config.ts 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // target: "http://39.106.149.78:8001",
  71. changeOrigin: true,
  72. secure: false,
  73. },
  74. }
  75. },
  76. resolve:{
  77. alias:[
  78. {
  79. find:'@',
  80. replacement:resolve(__dirname,'src')
  81. }
  82. ]
  83. },
  84. build: {
  85. outDir: "dist",
  86. // outDir:'../',
  87. // /** 打包后静态资源目录 */
  88. // assetsDir: "./static",
  89. sourcemap: false,
  90. minify: 'terser',
  91. chunkSizeWarningLimit: 1500,
  92. terserOptions: {
  93. compress: {
  94. drop_console: false,
  95. drop_debugger: true
  96. }
  97. },
  98. rollupOptions: {
  99. output: {
  100. manualChunks(id) {
  101. if (id.includes('node_modules')) {
  102. return id
  103. .toString()
  104. .split('node_modules/')[1]
  105. .split('/')[0]
  106. .toString();
  107. }
  108. },
  109. chunkFileNames: (chunkInfo) => {
  110. const facadeModuleId = chunkInfo.facadeModuleId
  111. ? chunkInfo.facadeModuleId.split('/')
  112. : [];
  113. const fileName =
  114. facadeModuleId[facadeModuleId.length - 2] || '[name]';
  115. return `js/${fileName}/[name].[hash].js`;
  116. }
  117. }
  118. }
  119. },
  120. }
  121. })