plugins.ts 1.7 KB

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