plugins.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 { viteMockServe } from "vite-plugin-mock";
  8. import { configCompressPlugin } from "./compress";
  9. import { visualizer } from "rollup-plugin-visualizer";
  10. import removeConsole from "vite-plugin-remove-console";
  11. import themePreprocessorPlugin from "@pureadmin/theme";
  12. import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
  13. import DefineOptions from "unplugin-vue-define-options/vite";
  14. import { genScssMultipleScopeVars } from "../src/layout/theme";
  15. export function getPluginsList(
  16. command: string,
  17. VITE_CDN: boolean,
  18. VITE_COMPRESSION: ViteCompression
  19. ) {
  20. const prodMock = true;
  21. const lifecycle = process.env.npm_lifecycle_event;
  22. return [
  23. vue(),
  24. VueI18nPlugin({
  25. runtimeOnly: true,
  26. compositionOnly: true,
  27. include: [resolve("locales/**")]
  28. }),
  29. // jsx、tsx语法支持
  30. vueJsx(),
  31. VITE_CDN ? cdn : null,
  32. configCompressPlugin(VITE_COMPRESSION),
  33. DefineOptions(),
  34. // 线上环境删除console
  35. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  36. viteBuildInfo(),
  37. // 自定义主题
  38. themePreprocessorPlugin({
  39. scss: {
  40. multipleScopeVars: genScssMultipleScopeVars(),
  41. extract: true
  42. }
  43. }),
  44. // svg组件化支持
  45. svgLoader(),
  46. // mock支持
  47. viteMockServe({
  48. mockPath: "mock",
  49. localEnabled: command === "serve",
  50. prodEnabled: command !== "serve" && prodMock,
  51. injectCode: `
  52. import { setupProdMockServer } from './mockProdServer';
  53. setupProdMockServer();
  54. `,
  55. logger: false
  56. }),
  57. // 打包分析
  58. lifecycle === "report"
  59. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  60. : null
  61. ];
  62. }