auth-web/build/plugins.ts

78 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-04-29 18:18:07 +08:00
import { cdn } from "./cdn";
import vue from "@vitejs/plugin-vue";
import { pathResolve } from "./utils";
import { viteBuildInfo } from "./info";
import svgLoader from "vite-svg-loader";
import Icons from "unplugin-icons/vite";
import type { PluginOption } from "vite";
import vueJsx from "@vitejs/plugin-vue-jsx";
import tailwindcss from "@tailwindcss/vite";
import { configCompressPlugin } from "./compress";
import removeNoMatch from "vite-plugin-router-warn";
import { visualizer } from "rollup-plugin-visualizer";
import removeConsole from "vite-plugin-remove-console";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import { codeInspectorPlugin } from "code-inspector-plugin";
import { vitePluginFakeServer } from "vite-plugin-fake-server";
2024-09-26 09:38:02 +08:00
2025-04-25 16:21:15 +08:00
export function getPluginsList(
VITE_CDN: boolean,
2025-04-29 18:18:07 +08:00
VITE_COMPRESSION: ViteCompression
2025-04-25 16:21:15 +08:00
): PluginOption[] {
const lifecycle = process.env.npm_lifecycle_event;
return [
2025-04-29 18:18:07 +08:00
tailwindcss(),
vue({
template: {
compilerOptions: {
isCustomElement: tag => tag === "deep-chat"
}
}
}),
2025-04-25 16:21:15 +08:00
// jsx、tsx语法支持
vueJsx(),
VueI18nPlugin({
2025-04-29 18:18:07 +08:00
// include: [pathResolve("../locales/**")]
2025-04-25 16:21:15 +08:00
}),
2025-04-29 18:18:07 +08:00
/**
* DOM IDE
* Mac Option + Shift
* Windows Alt + Shift
* https://inspector.fe-dev.cn/guide/start.html
*/
codeInspectorPlugin({
bundler: "vite",
hideConsole: true
}),
viteBuildInfo(),
2025-04-25 16:21:15 +08:00
/**
* vue-router动态路由警告No match found for location with path
* https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359
* vite-plugin-router-warn只在开发环境下启用vue-router文件并且只在服务启动或重启时运行一次
*/
removeNoMatch(),
2025-04-29 18:18:07 +08:00
// mock支持
2025-04-25 16:21:15 +08:00
// vitePluginFakeServer({
2025-04-29 18:18:07 +08:00
// logger: false,
// include: "mock",
// infixName: false,
// enableProd: true
2025-04-25 16:21:15 +08:00
// }),
// svg组件化支持
svgLoader(),
2025-04-29 18:18:07 +08:00
// 自动按需加载图标
Icons({
compiler: "vue3",
scale: 1
}),
2025-04-25 16:21:15 +08:00
VITE_CDN ? cdn : null,
configCompressPlugin(VITE_COMPRESSION),
// 线上环境删除console
2025-04-29 18:18:07 +08:00
removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
2025-04-25 16:21:15 +08:00
// 打包分析
2025-04-29 18:18:07 +08:00
lifecycle === "report"
? visualizer({ open: true, brotliSize: true, filename: "report.html" })
: (null as any)
2025-04-25 16:21:15 +08:00
];
2024-09-26 09:38:02 +08:00
}