plugins.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { cdn } from "./cdn";
  2. import { resolve } from "path";
  3. import vue from "@vitejs/plugin-vue";
  4. import { viteBuildInfo } from "./info";
  5. import svgLoader from "vite-svg-loader";
  6. import vueJsx from "@vitejs/plugin-vue-jsx";
  7. import { configCompressPlugin } from "./compress";
  8. import { visualizer } from "rollup-plugin-visualizer";
  9. import removeConsole from "vite-plugin-remove-console";
  10. import { themePreprocessorPlugin } from "@pureadmin/theme";
  11. import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
  12. import { genScssMultipleScopeVars } from "../src/layout/theme";
  13. import { vitePluginFakeServer } from "vite-plugin-fake-server";
  14. export function getPluginsList(
  15. command: string,
  16. VITE_CDN: boolean,
  17. VITE_COMPRESSION: ViteCompression
  18. ) {
  19. const lifecycle = process.env.npm_lifecycle_event;
  20. return [
  21. vue(),
  22. VueI18nPlugin({
  23. runtimeOnly: true,
  24. compositionOnly: true,
  25. include: [resolve("locales/**")]
  26. }),
  27. // jsx、tsx语法支持
  28. vueJsx(),
  29. VITE_CDN ? cdn : null,
  30. configCompressPlugin(VITE_COMPRESSION),
  31. // 线上环境删除console
  32. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  33. viteBuildInfo(),
  34. // 自定义主题
  35. themePreprocessorPlugin({
  36. scss: {
  37. multipleScopeVars: genScssMultipleScopeVars(),
  38. extract: true
  39. }
  40. }),
  41. // svg组件化支持
  42. svgLoader(),
  43. // mock支持
  44. vitePluginFakeServer({
  45. logger: false,
  46. include: "mock",
  47. infixName: false,
  48. enableProd: true
  49. }),
  50. // 打包分析
  51. lifecycle === "report"
  52. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  53. : null
  54. ];
  55. }