eslint 10、eslint-plugin-vue 10、stylelint 17、commitlint 21 eslint 配置改为 flat config,去掉自动导入 globals 文件 环境变量改成 VITE_API_BASE 与 VITE_API_URL 函数注释改成多行 JSDoc,去掉行末句号 列表项 id 改为必填,去掉非空断言 新增 useFormDialog 统一表单弹窗流程 菜单表单在小程序端改由 flex 派生滚动区高度 声明 packageManager 为 pnpm@10.34.5
126 lines
3.6 KiB
TypeScript
126 lines
3.6 KiB
TypeScript
import { defineConfig, type UserConfig, type ConfigEnv, loadEnv } from "vite";
|
|
import uni from "@dcloudio/vite-plugin-uni";
|
|
import AutoImport from "unplugin-auto-import/vite";
|
|
import UniLayouts from "@uni-helper/vite-plugin-uni-layouts";
|
|
import UniPages from "@uni-helper/vite-plugin-uni-pages";
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
import Components from "@uni-helper/vite-plugin-uni-components";
|
|
import type { ComponentResolver } from "@uni-helper/vite-plugin-uni-components";
|
|
import { kebabCase } from "@uni-helper/vite-plugin-uni-components";
|
|
|
|
/**
|
|
* 自定义 Wot UI v2 组件解析器
|
|
*
|
|
* 由于 @wot-ui/ui v2 的包名和路径发生了变化,需要自定义 resolver
|
|
* 官方迁移文档: https://wot-ui.cn/guide/migration-v2.html#vite-插件自动导入
|
|
*
|
|
* @returns ComponentResolver
|
|
*/
|
|
function WotUIResolver(): ComponentResolver {
|
|
return {
|
|
type: "component",
|
|
resolve: (name: string) => {
|
|
if (name.match(/^Wd[A-Z]/)) {
|
|
const compName = kebabCase(name);
|
|
return {
|
|
name,
|
|
from: `@wot-ui/ui/components/${compName}/${compName}.vue`,
|
|
};
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig(async ({ mode }: ConfigEnv): Promise<UserConfig> => {
|
|
const UnoCss = await import("unocss/vite").then((i) => i.default);
|
|
const env = loadEnv(mode, process.cwd());
|
|
const isProd = mode === "production";
|
|
// 接口地址,开发服务器的代理转发目标
|
|
const proxyTarget = env.VITE_API_URL;
|
|
|
|
const pkg = JSON.parse(readFileSync(resolve(process.cwd(), "package.json"), "utf-8")) as {
|
|
version?: string;
|
|
};
|
|
|
|
return {
|
|
// H5 部署在子路径时用 VITE_BASE_URL 覆盖,缺省为站点根
|
|
base: env.VITE_BASE_URL || "/",
|
|
define: {
|
|
"import.meta.env.VITE_APP_VERSION": JSON.stringify(pkg.version ?? ""),
|
|
},
|
|
server: {
|
|
host: "0.0.0.0",
|
|
port: +env.VITE_APP_PORT,
|
|
open: true,
|
|
proxy: {
|
|
[env.VITE_API_BASE]: {
|
|
changeOrigin: true,
|
|
target: proxyTarget,
|
|
rewrite: (path) => path.slice(env.VITE_API_BASE.length),
|
|
},
|
|
// 实时推送的 WebSocket 握手,单独代理并改写 Origin 供后端校验来源
|
|
"/api/v1/realtime/ws": {
|
|
changeOrigin: true,
|
|
rewriteWsOrigin: true,
|
|
target: proxyTarget,
|
|
ws: true,
|
|
},
|
|
},
|
|
},
|
|
build: {
|
|
target: "es6",
|
|
cssTarget: "chrome61",
|
|
// 微信小程序单文件上传限制 2MB,生产构建关闭 sourcemap 并尽量减少调试输出
|
|
sourcemap: false,
|
|
},
|
|
esbuild: isProd
|
|
? {
|
|
drop: ["console", "debugger"],
|
|
}
|
|
: undefined,
|
|
optimizeDeps: {
|
|
include: ["@wot-ui/ui"],
|
|
exclude: ["vue-demi"],
|
|
},
|
|
plugins: [
|
|
// make sure put it before `Uni()`
|
|
UnoCss(),
|
|
UniLayouts(),
|
|
UniPages({
|
|
dts: "src/types/uni-pages.d.ts",
|
|
subPackages: ["src/subPages"],
|
|
/**
|
|
* 排除的页面,相对于 dir 和 subPackages
|
|
* @default []
|
|
*/
|
|
exclude: ["**/components/**/*.*"],
|
|
}),
|
|
Components({
|
|
resolvers: [WotUIResolver()],
|
|
dirs: ["src/components"],
|
|
dts: "src/types/components.d.ts",
|
|
}),
|
|
|
|
AutoImport({
|
|
imports: [
|
|
"vue",
|
|
"uni-app",
|
|
"pinia",
|
|
{
|
|
from: "@wot-ui/ui",
|
|
imports: ["useToast", "useDialog", "useNotify", "CommonUtil"],
|
|
},
|
|
],
|
|
dts: "src/types/auto-imports.d.ts", // 自动生成的类型声明文件
|
|
dirs: ["src/composables", "src/store", "src/utils", "src/api"],
|
|
vueTemplate: true,
|
|
}),
|
|
|
|
uni(),
|
|
],
|
|
};
|
|
});
|