import vue from '@vitejs/plugin-vue' import { resolve } from 'path' import { defineConfig } from 'vite' // Less 全局变量文件(Windows 下需统一为 / 分隔符,否则 less 无法解析) const lessVariables = resolve(import.meta.dirname, 'src/styles/variables.less').replace( /\\/g, '/', ) // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], resolve: { alias: { "@": resolve(import.meta.dirname, "src"), "@c": resolve(import.meta.dirname, "src/components"), "/images": "src/assets/images/", }, }, server: { open: true, host: '127.0.0.1', port: 4402, strictPort: true, hmr: true, proxy: { '/api': { target: 'http://127.0.0.1:9000', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), } } }, css: { // 全局变量+全局引入less+配置主题色 preprocessorOptions: { less: { javascriptEnabled: true, // 全局注入设计变量,组件内无需重复 @import additionalData: `@import "${lessVariables}";`, // 全局变量使用:@primary-color modifyVars: { "primary-color": "#1890ff", // 全局主色 "link-color": " #1890ff", // 链接色 "success-color": " #52c41a", // 成功色 "warning-color": " #faad14", // 警告色 "error-color": " #ff4d4f", // 错误色 "font-size-base": " 14px", // 主字号 /*light浅色背景下*/ "light-headline": "#262626", // 标题色 "light-text": "#595959", // 主要文字 "light-text-secondary": "#8c8c8c", // 次要文字 "light-disabled": "#bfbfbf", // 禁用 "light-border": " #d9d9d9", // 边框色 "light-cut-off-rule": " #f0f0f0", // 分割线 "light-bg": " #f5f5f5", // 背景 "light-table-headline": " #fafafa", // 表格标题 /*dark深色背景下*/ "dark-headline": "#262626", // 标题色 "dark-text": "#595959", // 主要文字 "dark-text-secondary": "#8c8c8c", // 次要文字 "dark-disabled": "#bfbfbf", // 禁用 "dark-border": " #d9d9d9", // 边框色 "dark-cut-off-rule": " #f0f0f0", // 分割线 "dark-bg": " #f5f5f5", // 背景 "dark-table-headline": " #fafafa", // 表格标题 /*边框配置*/ "border-radius-base": " 2px", // 组件/浮层圆角 "box-shadow-base": " 0 2px 8px rgba(0, 0, 0, 0.15)", // 浮层阴影 }, }, }, }, })