2022-10-26 19:51:06 +08:00
|
|
|
|
import { cdn } from "./cdn";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
import vue from "@vitejs/plugin-vue";
|
2022-02-27 13:31:19 +08:00
|
|
|
|
import { viteBuildInfo } from "./info";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
import svgLoader from "vite-svg-loader";
|
2024-03-09 16:27:52 +08:00
|
|
|
|
import type { PluginOption } from "vite";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
2022-10-27 02:19:23 +08:00
|
|
|
|
import { configCompressPlugin } from "./compress";
|
2024-03-09 16:27:52 +08:00
|
|
|
|
import removeNoMatch from "vite-plugin-router-warn";
|
2022-02-05 15:32:38 +08:00
|
|
|
|
import { visualizer } from "rollup-plugin-visualizer";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
import removeConsole from "vite-plugin-remove-console";
|
2024-03-09 16:27:52 +08:00
|
|
|
|
import { themePreprocessorPlugin } from "@pureadmin/theme";
|
2022-10-27 13:17:56 +08:00
|
|
|
|
import { genScssMultipleScopeVars } from "../src/layout/theme";
|
2024-03-09 16:27:52 +08:00
|
|
|
|
import { vitePluginFakeServer } from "vite-plugin-fake-server";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
|
2022-10-26 19:51:06 +08:00
|
|
|
|
export function getPluginsList(
|
2022-10-27 02:19:23 +08:00
|
|
|
|
VITE_CDN: boolean,
|
|
|
|
|
VITE_COMPRESSION: ViteCompression
|
2024-03-09 16:27:52 +08:00
|
|
|
|
): PluginOption[] {
|
2022-02-05 15:32:38 +08:00
|
|
|
|
const lifecycle = process.env.npm_lifecycle_event;
|
2022-02-05 14:45:20 +08:00
|
|
|
|
return [
|
|
|
|
|
vue(),
|
|
|
|
|
// jsx、tsx语法支持
|
|
|
|
|
vueJsx(),
|
2022-02-27 13:31:19 +08:00
|
|
|
|
viteBuildInfo(),
|
2024-03-09 16:27:52 +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(),
|
|
|
|
|
// mock支持
|
|
|
|
|
vitePluginFakeServer({
|
|
|
|
|
logger: false,
|
|
|
|
|
include: "mock",
|
|
|
|
|
infixName: false,
|
|
|
|
|
enableProd: true
|
|
|
|
|
}),
|
2022-02-05 14:45:20 +08:00
|
|
|
|
// 自定义主题
|
|
|
|
|
themePreprocessorPlugin({
|
|
|
|
|
scss: {
|
2022-04-06 13:42:49 +08:00
|
|
|
|
multipleScopeVars: genScssMultipleScopeVars(),
|
2022-12-15 12:41:02 +08:00
|
|
|
|
extract: true
|
2022-02-05 14:45:20 +08:00
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
// svg组件化支持
|
|
|
|
|
svgLoader(),
|
2024-03-09 16:27:52 +08:00
|
|
|
|
VITE_CDN ? cdn : null,
|
|
|
|
|
configCompressPlugin(VITE_COMPRESSION),
|
|
|
|
|
// 线上环境删除console
|
|
|
|
|
removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
|
2022-02-05 15:32:38 +08:00
|
|
|
|
// 打包分析
|
|
|
|
|
lifecycle === "report"
|
|
|
|
|
? visualizer({ open: true, brotliSize: true, filename: "report.html" })
|
2024-03-09 16:27:52 +08:00
|
|
|
|
: (null as any)
|
2022-02-05 14:45:20 +08:00
|
|
|
|
];
|
|
|
|
|
}
|