vite.config.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { defineConfig } from "vite"
  2. import { fileURLToPath, URL } from "node:url"
  3. import vue from "@vitejs/plugin-vue"
  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 path from "path"
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. plugins: [
  11. vue(),
  12. //引入vue 插件
  13. AutoImport({
  14. imports: ["vue"],
  15. //dts: "src/auto-import.d.ts",
  16. }),
  17. //plus按需引入
  18. AutoImport({
  19. resolvers: [ElementPlusResolver()],
  20. }),
  21. //plus按需引入
  22. Components({
  23. resolvers: [ElementPlusResolver()],
  24. }),
  25. ],
  26. resolve: {
  27. alias: {
  28. "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
  29. "@": fileURLToPath(new URL("./src", import.meta.url)),
  30. comp: fileURLToPath(new URL("./src/components", import.meta.url)),
  31. },
  32. },
  33. base: "/",
  34. build: {
  35. chunkSizeWarningLimit: 3000,
  36. minify: "terser", // 必须启用:terserOptions配置才会有效
  37. terserOptions: {
  38. compress: {
  39. // 生产环境时移除console.log调试代码
  40. drop_console: true,
  41. drop_debugger: true,
  42. },
  43. },
  44. rollupOptions: {
  45. output: {
  46. manualChunks(id) {
  47. // 将pinia的全局库实例打包进vendor,避免和页面一起打包造成资源重复引入
  48. if (id.includes(path.resolve(__dirname, "/src/store/index.ts"))) {
  49. return "vendor"
  50. }
  51. },
  52. },
  53. },
  54. },
  55. server: {
  56. //使用IP能访问
  57. host: "0.0.0.0",
  58. // 热更新
  59. hmr: true,
  60. //设为 true 时若端口已被占用则会直接退出,而不是尝试下一个可用端口
  61. strictPort: true,
  62. port: 8290,
  63. open: false,
  64. proxy: {
  65. // 接口地址代理
  66. "/api": {
  67. target: "http://shvber.com:8290", // 接口的域名
  68. secure: false, // 如果是https接口,需要配置这个参数
  69. changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
  70. rewrite: (path) => path.replace(/^\/api/, "/api"),
  71. },
  72. },
  73. },
  74. })