uno.config.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { defineConfig, toEscapedSelector as e, presetUno, presetIcons } from 'unocss'
  2. import transformerVariantGroup from '@unocss/transformer-variant-group'
  3. import { loadEnv } from 'vite'
  4. const root = process.cwd()
  5. const createPresetIcons = () => {
  6. const isBuild = !!process.argv[4]
  7. let env = {} as any
  8. if (!isBuild) {
  9. env = loadEnv(process.argv[3], root)
  10. } else {
  11. env = loadEnv(process.argv[4], root)
  12. }
  13. // @ts-ignore
  14. if (env.VITE_USE_ONLINE_ICON === 'true') {
  15. return []
  16. } else {
  17. return [
  18. presetIcons({
  19. prefix: ''
  20. // 由于默认加载的是所有的图标,启动会非常慢,可以在这里去加载需要的图标,确保启动速度
  21. // collections: {
  22. // carbon: () => import('@iconify-json/carbon/icons.json').then(i => i.default),
  23. // mdi: () => import('@iconify-json/mdi/icons.json').then(i => i.default),
  24. // logos: () => import('@iconify-json/logos/icons.json').then(i => i.default),
  25. // }
  26. })
  27. ]
  28. }
  29. }
  30. export default defineConfig({
  31. // ...UnoCSS options
  32. rules: [
  33. [
  34. /^overflow-ellipsis$/,
  35. ([], { rawSelector }) => {
  36. const selector = e(rawSelector)
  37. return `
  38. ${selector} {
  39. text-overflow: ellipsis;
  40. }
  41. `
  42. }
  43. ],
  44. [
  45. /^custom-hover$/,
  46. ([], { rawSelector }) => {
  47. const selector = e(rawSelector)
  48. return `
  49. ${selector} {
  50. display: flex;
  51. height: 100%;
  52. padding: 1px 10px 0;
  53. cursor: pointer;
  54. align-items: center;
  55. transition: background var(--transition-time-02);
  56. }
  57. /* you can have multiple rules */
  58. ${selector}:hover {
  59. background-color: var(--top-header-hover-color);
  60. }
  61. .dark ${selector}:hover {
  62. background-color: var(--el-bg-color-overlay);
  63. }
  64. `
  65. }
  66. ],
  67. [
  68. /^layout-border__left$/,
  69. ([], { rawSelector }) => {
  70. const selector = e(rawSelector)
  71. return `
  72. ${selector}:before {
  73. content: "";
  74. position: absolute;
  75. top: 0;
  76. left: 0;
  77. width: 1px;
  78. height: 100%;
  79. background-color: var(--el-border-color);
  80. z-index: 3;
  81. }
  82. `
  83. }
  84. ],
  85. [
  86. /^layout-border__right$/,
  87. ([], { rawSelector }) => {
  88. const selector = e(rawSelector)
  89. return `
  90. ${selector}:after {
  91. content: "";
  92. position: absolute;
  93. top: 0;
  94. right: 0;
  95. width: 1px;
  96. height: 100%;
  97. background-color: var(--el-border-color);
  98. z-index: 3;
  99. }
  100. `
  101. }
  102. ],
  103. [
  104. /^layout-border__top$/,
  105. ([], { rawSelector }) => {
  106. const selector = e(rawSelector)
  107. return `
  108. ${selector}:before {
  109. content: "";
  110. position: absolute;
  111. top: 0;
  112. left: 0;
  113. width: 100%;
  114. height: 1px;
  115. background-color: var(--el-border-color);
  116. z-index: 3;
  117. }
  118. `
  119. }
  120. ],
  121. [
  122. /^layout-border__bottom$/,
  123. ([], { rawSelector }) => {
  124. const selector = e(rawSelector)
  125. return `
  126. ${selector}:after {
  127. content: "";
  128. position: absolute;
  129. bottom: 0;
  130. left: 0;
  131. width: 100%;
  132. height: 1px;
  133. background-color: var(--el-border-color);
  134. z-index: 3;
  135. }
  136. `
  137. }
  138. ]
  139. ],
  140. presets: [presetUno({ dark: 'class', attributify: false }), ...createPresetIcons()],
  141. transformers: [transformerVariantGroup()],
  142. content: {
  143. pipeline: {
  144. include: [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html|ts)($|\?)/]
  145. }
  146. }
  147. })