This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
import { UserConfig, defineConfig } from "vite";
|
||||
import { createHtmlPlugin } from "vite-plugin-html";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import path, { resolve } from "path";
|
||||
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
||||
import ViteAutoImport from "unplugin-auto-import/vite";
|
||||
|
||||
import UnoCSS from "@unocss/vite";
|
||||
import presetUno from "@unocss/preset-uno";
|
||||
|
||||
import presetRemToPx from "@unocss/preset-rem-to-px";
|
||||
|
||||
export default defineConfig((): UserConfig => {
|
||||
// 构建产物直出 dist/ 根(CI 打 zip 取 dist 根,projman 校验要求 zip 根直接是 index.html)
|
||||
const outDir = "dist";
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
vue(),
|
||||
createSvgIconsPlugin({
|
||||
iconDirs: [resolve(process.cwd(), "src/assets/icons")],
|
||||
symbolId: "icon-[dir]-[name]",
|
||||
inject: "body-last",
|
||||
customDomId: "__svg__icons__dom__",
|
||||
}),
|
||||
ViteAutoImport({
|
||||
imports: [
|
||||
"vue",
|
||||
"vue-router",
|
||||
{
|
||||
"view-ui-plus": ["Button", "Input", "Message", "Avatar", "Tag", "Tooltip"],
|
||||
},
|
||||
{
|
||||
from: "alova/client",
|
||||
imports: ["useRequest", "useWatcher", "useForm"],
|
||||
},
|
||||
],
|
||||
dts: "./src/auto-imports.d.ts",
|
||||
dirs: ["src/api/module"],
|
||||
}),
|
||||
createHtmlPlugin({
|
||||
minify: true,
|
||||
pages: [
|
||||
{
|
||||
entry: "src/main.ts",
|
||||
template: "index.html",
|
||||
filename: "index.html",
|
||||
injectOptions: {
|
||||
data: {
|
||||
title: "智能助手",
|
||||
injectScript: ``,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
UnoCSS({
|
||||
presets: [
|
||||
presetUno(),
|
||||
presetRemToPx({ baseFontSize: 4 }),
|
||||
],
|
||||
shortcuts: {
|
||||
"flex-center": "flex items-center justify-center",
|
||||
card: "bg-white rounded-8px shadow-md p-16px",
|
||||
"text-ellipsis": "truncate",
|
||||
},
|
||||
theme: {
|
||||
fontSize: {
|
||||
xs: "12px",
|
||||
sm: "14px",
|
||||
base: "16px",
|
||||
lg: "18px",
|
||||
xl: "20px",
|
||||
"2xl": "24px",
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
host: "localhost",
|
||||
port: 8080,
|
||||
proxy: {
|
||||
// 同源代理:serviceHost 留空时前端走 /api/...,由这里转发到本地 AgentService(8093),
|
||||
// 规避后端 CAS 过滤器对 /api/* 不回 CORS 头导致的浏览器直连跨域拦截。
|
||||
// 如需连测试环境:target 换成 http://base.yunhaixingtong.com/agent
|
||||
"/api": {
|
||||
target: "http://localhost:8093",
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
base: "./",
|
||||
build: {
|
||||
target: "modules",
|
||||
outDir,
|
||||
assetsDir: "assets",
|
||||
sourcemap: false,
|
||||
minify: "esbuild",
|
||||
chunkSizeWarningLimit: 1000,
|
||||
cssTarget: "chrome61",
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: resolve("index.html"),
|
||||
},
|
||||
output: {
|
||||
chunkFileNames: "static/js/[name]-[hash].js",
|
||||
entryFileNames: "static/js/[name]-[hash].js",
|
||||
assetFileNames: (assetInfo: any) => {
|
||||
if (assetInfo.type === "asset" && /\.(jpe?g|png|gif|svg)$/i.test(assetInfo.name)) {
|
||||
return "static/img/[name].[hash][ext]";
|
||||
}
|
||||
if (assetInfo.type === "asset" && /\.(ttf|woff|woff2|eot)$/i.test(assetInfo.name)) {
|
||||
return "static/fonts/[name].[hash][ext]";
|
||||
}
|
||||
return "static/[ext]/[name]-[hash].[ext]";
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user