wireguard-dashboard-admin/build/plugins.ts

83 lines
2.7 KiB
TypeScript
Raw Normal View History

import { cdn } from "./cdn";
2022-03-14 14:49:02 +08:00
import { resolve } from "path";
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";
import legacy from "@vitejs/plugin-legacy";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { viteMockServe } from "vite-plugin-mock";
import { configCompressPlugin } from "./compress";
2022-03-14 14:49:02 +08:00
import VueI18n from "@intlify/vite-plugin-vue-i18n";
2022-04-25 18:46:25 +08:00
// import ElementPlus from "unplugin-element-plus/vite";
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";
2022-03-17 15:45:11 +08:00
import themePreprocessorPlugin from "@pureadmin/theme";
2022-08-22 21:34:55 +08:00
import DefineOptions from "unplugin-vue-define-options/vite";
import { genScssMultipleScopeVars } from "../src/layout/theme";
2022-02-05 14:45:20 +08:00
export function getPluginsList(
command: string,
VITE_LEGACY: boolean,
VITE_CDN: boolean,
VITE_COMPRESSION: ViteCompression
) {
2022-02-05 14:45:20 +08:00
const prodMock = true;
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(),
2022-03-14 14:49:02 +08:00
// https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
VueI18n({
runtimeOnly: true,
compositionOnly: true,
include: [resolve("locales/**")]
}),
2022-02-05 14:45:20 +08:00
// jsx、tsx语法支持
vueJsx(),
VITE_CDN ? cdn : null,
configCompressPlugin(VITE_COMPRESSION),
2022-08-22 21:34:55 +08:00
DefineOptions(),
2022-02-05 14:45:20 +08:00
// 线上环境删除console
2022-08-22 21:34:55 +08:00
removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
2022-02-27 13:31:19 +08:00
viteBuildInfo(),
2022-02-05 14:45:20 +08:00
// 自定义主题
themePreprocessorPlugin({
scss: {
2022-04-06 13:42:49 +08:00
multipleScopeVars: genScssMultipleScopeVars(),
2022-02-05 14:45:20 +08:00
// 在生产模式是否抽取独立的主题css文件extract为true以下属性有效
extract: true,
// 会选取defaultScopeName对应的主题css文件在html添加link
themeLinkTagId: "head",
// "head"||"head-prepend" || "body" ||"body-prepend"
themeLinkTagInjectTo: "head",
// 是否对抽取的css文件内对应scopeName的权重类名移除
2022-04-25 18:46:25 +08:00
removeCssScopeName: false
2022-02-05 14:45:20 +08:00
}
}),
// svg组件化支持
svgLoader(),
2022-04-25 18:46:25 +08:00
// ElementPlus({}),
2022-02-05 14:45:20 +08:00
// mock支持
viteMockServe({
mockPath: "mock",
localEnabled: command === "serve",
prodEnabled: command !== "serve" && prodMock,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
2022-05-01 08:34:33 +08:00
logger: false
2022-02-05 14:45:20 +08:00
}),
// 是否为打包后的文件提供传统浏览器兼容性支持
VITE_LEGACY
? legacy({
targets: ["ie >= 11"],
additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
})
2022-02-05 15:32:38 +08:00
: null,
// 打包分析
lifecycle === "report"
? visualizer({ open: true, brotliSize: true, filename: "report.html" })
2022-02-05 14:45:20 +08:00
: null
];
}