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.

73 lines
2.4 KiB

  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 VueMacros from "unplugin-vue-macros/vite";
  8. import { viteMockServe } from "vite-plugin-mock";
  9. import { configCompressPlugin } from "./compress";
  10. import VueI18n from "@intlify/vite-plugin-vue-i18n";
  11. // import ElementPlus from "unplugin-element-plus/vite";
  12. import { visualizer } from "rollup-plugin-visualizer";
  13. import removeConsole from "vite-plugin-remove-console";
  14. import themePreprocessorPlugin from "@pureadmin/theme";
  15. import { genScssMultipleScopeVars } from "../src/layout/theme";
  16. export function getPluginsList(
  17. command: string,
  18. VITE_CDN: boolean,
  19. VITE_COMPRESSION: ViteCompression
  20. ) {
  21. const prodMock = true;
  22. const lifecycle = process.env.npm_lifecycle_event;
  23. return [
  24. vue(),
  25. // https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
  26. VueI18n({
  27. runtimeOnly: true,
  28. compositionOnly: true,
  29. include: [resolve("locales/**")]
  30. }),
  31. // jsx、tsx语法支持
  32. vueJsx(),
  33. VITE_CDN ? cdn : null,
  34. configCompressPlugin(VITE_COMPRESSION),
  35. VueMacros(),
  36. // 线上环境删除console
  37. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  38. viteBuildInfo(),
  39. // 自定义主题
  40. themePreprocessorPlugin({
  41. scss: {
  42. multipleScopeVars: genScssMultipleScopeVars(),
  43. // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
  44. extract: true,
  45. // 会选取defaultScopeName对应的主题css文件在html添加link
  46. themeLinkTagId: "head",
  47. // "head"||"head-prepend" || "body" ||"body-prepend"
  48. themeLinkTagInjectTo: "head",
  49. // 是否对抽取的css文件内对应scopeName的权重类名移除
  50. removeCssScopeName: false
  51. }
  52. }),
  53. // svg组件化支持
  54. svgLoader(),
  55. // ElementPlus({}),
  56. // mock支持
  57. viteMockServe({
  58. mockPath: "mock",
  59. localEnabled: command === "serve",
  60. prodEnabled: command !== "serve" && prodMock,
  61. injectCode: `
  62. import { setupProdMockServer } from './mockProdServer';
  63. setupProdMockServer();
  64. `,
  65. logger: false
  66. }),
  67. // 打包分析
  68. lifecycle === "report"
  69. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  70. : null
  71. ];
  72. }