You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB

  1. import { cdn } from "./cdn";
  2. import vue from "@vitejs/plugin-vue";
  3. import { pathResolve } from "./utils";
  4. import { viteBuildInfo } from "./info";
  5. import svgLoader from "vite-svg-loader";
  6. import type { PluginOption } from "vite";
  7. import vueJsx from "@vitejs/plugin-vue-jsx";
  8. import { configCompressPlugin } from "./compress";
  9. import removeNoMatch from "vite-plugin-router-warn";
  10. import { visualizer } from "rollup-plugin-visualizer";
  11. import removeConsole from "vite-plugin-remove-console";
  12. import { themePreprocessorPlugin } from "@pureadmin/theme";
  13. import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
  14. import { genScssMultipleScopeVars } from "../src/layout/theme";
  15. import { vitePluginFakeServer } from "vite-plugin-fake-server";
  16. export function getPluginsList(
  17. VITE_CDN: boolean,
  18. VITE_COMPRESSION: ViteCompression
  19. ): PluginOption[] {
  20. const lifecycle = process.env.npm_lifecycle_event;
  21. return [
  22. vue(),
  23. // jsx、tsx语法支持
  24. vueJsx(),
  25. VueI18nPlugin({
  26. jitCompilation: false,
  27. include: [pathResolve("../locales/**")]
  28. }),
  29. viteBuildInfo(),
  30. /**
  31. * vue-router动态路由警告No match found for location with path
  32. * https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359
  33. * vite-plugin-router-warn只在开发环境下启用vue-router文件并且只在服务启动或重启时运行一次
  34. */
  35. removeNoMatch(),
  36. // mock支持
  37. vitePluginFakeServer({
  38. logger: false,
  39. include: "mock",
  40. infixName: false,
  41. enableProd: true
  42. }),
  43. // 自定义主题
  44. themePreprocessorPlugin({
  45. scss: {
  46. multipleScopeVars: genScssMultipleScopeVars(),
  47. extract: true
  48. }
  49. }),
  50. // svg组件化支持
  51. svgLoader(),
  52. VITE_CDN ? cdn : null,
  53. configCompressPlugin(VITE_COMPRESSION),
  54. // 线上环境删除console
  55. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  56. // 打包分析
  57. lifecycle === "report"
  58. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  59. : (null as any)
  60. ];
  61. }