重构vite.config.json

主要是添加了一个组件的按需引入。对buid打包命令进行了优化。代理也是在这里彻底学会的 。

应该有很多值得学习和改进的地方。

javascript 复制代码
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: 'less', 
        }),
      ],
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  server: {
    host: '0.0.0.0', // 允许外部访问
    port: 8081, // 自定义端口
    open: true, // 自动打开浏览器
    // 只有是开发环境才生效
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
      },
      // // 添加图片代理配置!
      // '/avatars':{
      //   target: 'http://localhost:3000',
      //   changeOrigin: true,
      // }
    },
  },
  build: {
    target: 'esnext', // 构建目标
    chunkSizeWarningLimit: 1000, // 分块大小警告限制(KB)
    rollupOptions: {
      output: {
        // 手动分割代码
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        },
      },
    }
  },
})
相关推荐
高工智能汽车1 天前
CES2026丨中科创达发布滴水OS 2.0 Pre 以AI原生重构智能汽车交互体验
重构·汽车·ai-native
GIS 数据栈1 天前
【Seggis遥感系统升级】用C++高性能服务Drogon重构软件服务架构|QPS提升300%,性能再升级!
java·开发语言·c++·重构·架构
元智启1 天前
企业 AI 应用进入 “能力解耦时代”:模块化重构 AI 落地新范式
大数据·人工智能·重构
Van_captain1 天前
React Native for OpenHarmony Toast 轻提示组件:自动消失的操作反馈
javascript·开源·harmonyos
Van_captain1 天前
React Native for OpenHarmony Modal 模态框组件:阻断式交互的设计与实现
javascript·开源·harmonyos
xkxnq1 天前
第一阶段:Vue 基础入门(第 14天)
前端·javascript·vue.js
前端小臻1 天前
列举react中类组件和函数组件常用到的方法
前端·javascript·react.js
研☆香1 天前
html css js文件开发规范
javascript·css·html
小北方城市网1 天前
GEO 全场景智能生态:自适应架构重构与极限算力协同落地
开发语言·人工智能·python·重构·架构·量子计算
科技小E1 天前
EasyGBS算法算力平台重构服务业视频监控AI应用
人工智能·重构·音视频