vite.config.ts 2.3 KB

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