uno.config.ts 2.8 KB

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