plugins.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 VueI18n from "@intlify/vite-plugin-vue-i18n";
  10. import { visualizer } from "rollup-plugin-visualizer";
  11. import removeConsole from "vite-plugin-remove-console";
  12. import themePreprocessorPlugin from "@pureadmin/theme";
  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. // https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
  25. VueI18n({
  26. runtimeOnly: true,
  27. compositionOnly: true,
  28. include: [resolve("locales/**")]
  29. }),
  30. // jsx、tsx语法支持
  31. vueJsx(),
  32. VITE_CDN ? cdn : null,
  33. configCompressPlugin(VITE_COMPRESSION),
  34. DefineOptions(),
  35. // 线上环境删除console
  36. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  37. viteBuildInfo(),
  38. // 自定义主题
  39. themePreprocessorPlugin({
  40. scss: {
  41. multipleScopeVars: genScssMultipleScopeVars(),
  42. extract: true
  43. }
  44. }),
  45. // svg组件化支持
  46. svgLoader(),
  47. // mock支持
  48. viteMockServe({
  49. mockPath: "mock",
  50. localEnabled: command === "serve",
  51. prodEnabled: command !== "serve" && prodMock,
  52. injectCode: `
  53. import { setupProdMockServer } from './mockProdServer';
  54. setupProdMockServer();
  55. `,
  56. logger: false
  57. }),
  58. // 打包分析
  59. lifecycle === "report"
  60. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  61. : null
  62. ];
  63. }