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.

63 lines
2.2 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. runtimeOnly: true,
  27. compositionOnly: true,
  28. include: [pathResolve("../locales/**")]
  29. }),
  30. viteBuildInfo(),
  31. /**
  32. * vue-router动态路由警告No match found for location with path
  33. * https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359
  34. * vite-plugin-router-warn只在开发环境下启用vue-router文件并且只在服务启动或重启时运行一次
  35. */
  36. removeNoMatch(),
  37. // mock支持
  38. vitePluginFakeServer({
  39. logger: false,
  40. include: "mock",
  41. infixName: false,
  42. enableProd: true
  43. }),
  44. // 自定义主题
  45. themePreprocessorPlugin({
  46. scss: {
  47. multipleScopeVars: genScssMultipleScopeVars(),
  48. extract: true
  49. }
  50. }),
  51. // svg组件化支持
  52. svgLoader(),
  53. VITE_CDN ? cdn : null,
  54. configCompressPlugin(VITE_COMPRESSION),
  55. // 线上环境删除console
  56. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  57. // 打包分析
  58. lifecycle === "report"
  59. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  60. : (null as any)
  61. ];
  62. }