uno.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { presetUni } from '@uni-helper/unocss-preset-uni'
  2. import { defineConfig, transformerDirectives } from 'unocss'
  3. const remRE = /(-?[\\.\d]+)rem/g
  4. function transformUniPreset() {
  5. return {
  6. name: 'preset-transform-uni-rem-to-rpx',
  7. postprocess: (util) => {
  8. util.entries.forEach((i) => {
  9. const [, value] = i
  10. if (typeof value === 'string' && remRE.test(value)) {
  11. i[1] = value.replace(remRE, (_, p1) => `${+p1 * 4}rpx`)
  12. }
  13. if (
  14. typeof value === 'string' &&
  15. ['rgba'].some((x) => value.startsWith(x))
  16. ) {
  17. i[1] = value.replace(/,var\(.+\)\)$/, ')').replace('rgba', 'rgb')
  18. }
  19. })
  20. }
  21. }
  22. }
  23. export default defineConfig({
  24. presets: [transformUniPreset(), presetUni()],
  25. transformers: [transformerDirectives()],
  26. shortcuts: [
  27. ['wh-full', 'w-full h-full'],
  28. ['f-c-c', 'flex justify-center items-center'],
  29. ['f-s-c', 'flex justify-start items-center'],
  30. ['f-s-s', 'flex justify-start items-start'],
  31. ['flex-col', 'flex flex-col'],
  32. ['pointer-select', 'select-none cursor-pointer'],
  33. ['text-ellipsis', 'truncate']
  34. ],
  35. rules: [
  36. ['pre-wrap', { 'white-space': 'pre-wrap' }],
  37. ['no-scrollbar', { 'overflow-x': 'scroll', 'scrollbar-width': 'none' }],
  38. [/^bc-(.+)$/, ([, color]) => ({ 'border-color': `#${color}` })],
  39. [
  40. 'card-shadow',
  41. {
  42. 'box-shadow': '0 4px 10px 0 rgba(0, 0, 0, 0.14)'
  43. }
  44. ]
  45. ]
  46. })