From f35f60648b963b92a3dedb08083ea9e5b9308f90 Mon Sep 17 00:00:00 2001 From: Leo <98382335+gaoziman@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=92=8C=E5=B7=A5=E5=85=B7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加Vite构建配置(vite.config.ts) - 添加UnoCSS原子化CSS配置(unocss.config.ts) - 添加ESLint代码检查配置(eslint.config.js) - 添加服务接口配置(service.config.ts) --- eslint.config.js | 28 ++++++++++++++++++++++++++++ service.config.ts | 12 ++++++++++++ unocss.config.ts | 17 +++++++++++++++++ vite.config.ts | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 eslint.config.js create mode 100644 service.config.ts create mode 100644 unocss.config.ts create mode 100644 vite.config.ts diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..640395e --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,28 @@ +// eslint.config.js +import antfu from '@antfu/eslint-config' + +// https://github.com/antfu/eslint-config +export default antfu( + { + ignores: [ + 'doc/**/*.md', // 忽略文档目录下的Markdown文件 + ], + typescript: { + overrides: { + 'perfectionist/sort-exports': 'off', + 'perfectionist/sort-imports': 'off', + 'ts/no-unused-expressions': ['error', { allowShortCircuit: true }], + }, + }, + vue: { + overrides: { + 'vue/no-unused-refs': 'off', // 暂时关闭,等待vue-lint的分支合并 + 'vue/no-reserved-component-names': 'off', + 'vue/component-definition-name-casing': 'off', + 'vue/block-order': ['error', { + order: ['template', 'script', 'style'], + }], + }, + }, + }, +) diff --git a/service.config.ts b/service.config.ts new file mode 100644 index 0000000..6dadd9f --- /dev/null +++ b/service.config.ts @@ -0,0 +1,12 @@ +/** 不同请求服务的环境配置 */ +export const serviceConfig: Record> = { + dev: { + url: 'http://localhost:18099', + }, + test: { + url: 'http://localhost:18099', + }, + prod: { + url: 'http://localhost:18099', + }, +} diff --git a/unocss.config.ts b/unocss.config.ts new file mode 100644 index 0000000..2e730e6 --- /dev/null +++ b/unocss.config.ts @@ -0,0 +1,17 @@ +import { defineConfig, presetAttributify, presetUno, transformerVariantGroup } from 'unocss' + +// https://github.com/unocss/unocss + +export default defineConfig({ + presets: [presetUno({ dark: 'class' }), presetAttributify()], + shortcuts: { + 'wh-full': 'w-full h-full', + 'flex-center': 'flex justify-center items-center', + 'flex-col-center': 'flex-center flex-col', + 'flex-x-center': 'flex justify-center', + 'flex-y-center': 'flex items-center', + }, + transformers: [ + transformerVariantGroup(), + ], +}) diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..693eea0 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,38 @@ +import { resolve } from 'node:path' +import { defineConfig, loadEnv } from 'vite' +import { createVitePlugins } from './build/plugins' +import { createViteProxy } from './build/proxy' +import { serviceConfig } from './service.config' + +// https://vitejs.dev/config/ +export default defineConfig(({ mode }) => { + // 根据当前工作目录中的 `mode` 加载 .env 文件 + const env = loadEnv(mode, __dirname, '') as ImportMetaEnv + const envConfig = serviceConfig[mode as ServiceEnvType] + + return { + base: env.VITE_BASE_URL, + plugins: createVitePlugins(env), + resolve: { + alias: { + '@': resolve(__dirname, 'src'), + }, + }, + server: { + host: '0.0.0.0', + proxy: + env.VITE_HTTP_PROXY === 'Y' ? createViteProxy(envConfig) : undefined, + }, + build: { + target: 'esnext', + reportCompressedSize: false, // 启用/禁用 gzip 压缩大小报告 + }, + css: { + preprocessorOptions: { + scss: { + api: 'modern', + }, + }, + }, + } +})