vue-pure-admin2/build/plugins.ts

63 lines
2.1 KiB
TypeScript
Raw Normal View History

import { cdn } from "./cdn";
2022-02-05 17:34:01 +08:00
import vue from "@vitejs/plugin-vue";
2024-01-08 16:50:54 +08:00
import { pathResolve } from "./utils";
import { viteBuildInfo } from "./info";
2022-02-05 17:34:01 +08:00
import svgLoader from "vite-svg-loader";
2023-11-16 22:01:20 +08:00
import type { PluginOption } from "vite";
2022-02-05 17:34:01 +08:00
import vueJsx from "@vitejs/plugin-vue-jsx";
import { configCompressPlugin } from "./compress";
import removeNoMatch from "vite-plugin-router-warn";
2022-02-05 17:34:01 +08:00
import { visualizer } from "rollup-plugin-visualizer";
import removeConsole from "vite-plugin-remove-console";
import { themePreprocessorPlugin } from "@pureadmin/theme";
2022-12-19 11:58:49 +08:00
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import { genScssMultipleScopeVars } from "../src/layout/theme";
import { vitePluginFakeServer } from "vite-plugin-fake-server";
2022-02-05 17:34:01 +08:00
export function getPluginsList(
VITE_CDN: boolean,
VITE_COMPRESSION: ViteCompression
2023-11-16 22:01:20 +08:00
): PluginOption[] {
2022-02-05 17:34:01 +08:00
const lifecycle = process.env.npm_lifecycle_event;
return [
vue(),
// jsx、tsx语法支持
vueJsx(),
2022-12-19 11:58:49 +08:00
VueI18nPlugin({
jitCompilation: false,
2024-01-08 16:50:54 +08:00
include: [pathResolve("../locales/**")]
2022-03-11 21:28:43 +08:00
}),
viteBuildInfo(),
/**
* 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(),
// mock支持
vitePluginFakeServer({
logger: false,
include: "mock",
infixName: false,
enableProd: true
}),
2022-02-05 17:34:01 +08:00
// 自定义主题
themePreprocessorPlugin({
scss: {
multipleScopeVars: genScssMultipleScopeVars(),
extract: true
2022-02-05 17:34:01 +08:00
}
}),
// svg组件化支持
svgLoader(),
VITE_CDN ? cdn : null,
configCompressPlugin(VITE_COMPRESSION),
// 线上环境删除console
removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
2022-02-05 17:34:01 +08:00
// 打包分析
lifecycle === "report"
? visualizer({ open: true, brotliSize: true, filename: "report.html" })
2023-11-16 22:01:20 +08:00
: (null as any)
2022-02-05 17:34:01 +08:00
];
}