Files
ycc-proxy-webview/vite.config.js

82 lines
2.9 KiB
JavaScript
Raw Normal View History

2025-11-27 13:19:45 +08:00
import { fileURLToPath, URL } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "@vant/auto-import-resolver";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import vueDevTools from "vite-plugin-vue-devtools";
// https://vite.dev/config/
export default defineConfig({
server: {
host: "0.0.0.0", // 设置为 0.0.0.0 允许局域网访问
port: 5678, // 自定义端口号,可选
strictPort: true, // 如果端口被占用则抛出错误而不是使用下一个可用端口
proxy: {
"/api/v1": {
target: "http://127.0.0.1:8888", // 本地接口地址
2025-12-16 19:27:20 +08:00
// target: "https://onecha.cn", // 本地接口地址
2025-11-27 13:19:45 +08:00
changeOrigin: true,
},
},
},
build: {
// 构建优化
2025-12-16 19:27:20 +08:00
target: "es2015", // 支持更多浏览器
minify: "terser", // 使用terser进行压缩
2025-11-27 13:19:45 +08:00
terserOptions: {
compress: {
drop_console: true, // 移除console.log
drop_debugger: true, // 移除debugger
},
},
rollupOptions: {
output: {
// 代码分割策略
manualChunks: {
2025-12-16 19:27:20 +08:00
vendor: ["vue", "vue-router", "pinia"],
vant: ["vant"],
utils: ["axios", "lodash", "crypto-js"],
charts: ["echarts", "vue-echarts"],
2025-11-27 13:19:45 +08:00
},
// 文件名策略
2025-12-16 19:27:20 +08:00
chunkFileNames: "assets/js/[name]-[hash].js",
entryFileNames: "assets/js/[name]-[hash].js",
assetFileNames: "assets/[ext]/[name]-[hash].[ext]",
2025-11-27 13:19:45 +08:00
},
},
// 启用CSS代码分割
cssCodeSplit: true,
// 设置资源内联阈值
assetsInlineLimit: 4096,
},
plugins: [
vue(),
AutoImport({
imports: [
"vue", // 自动引入 Vue Composition API如 ref、computed、onMounted 等
"vue-router", // 自动引入 vue-router 中的方法,如 useRoute、useRouter 等(可选)
"@vueuse/core", // 自动引入 VueUse 中的工具函数(可选)
],
dts: "src/auto-imports.d.ts", // 生成类型定义文件(可选)
2025-12-16 19:27:20 +08:00
dirs: ["src/composables", "src/stores", "src/components"],
2025-11-27 13:19:45 +08:00
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
vueJsx(),
// vueDevTools(),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
// 优化依赖预构建
optimizeDeps: {
2025-12-16 19:27:20 +08:00
include: ["vue", "vue-router", "pinia", "vant", "axios"],
2025-11-27 13:19:45 +08:00
},
});