uno.config.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // uno.config.ts
  2. import {
  3. Preset,
  4. defineConfig,
  5. presetAttributify,
  6. presetIcons,
  7. transformerDirectives,
  8. transformerVariantGroup,
  9. } from 'unocss'
  10. import {
  11. presetApplet,
  12. presetRemRpx,
  13. transformerApplet,
  14. transformerAttributify,
  15. } from 'unocss-applet'
  16. const isH5 = process.env?.UNI_PLATFORM === 'h5'
  17. const isMp = process.env?.UNI_PLATFORM?.startsWith('mp') ?? false
  18. const presets: Preset[] = []
  19. if (!isMp) {
  20. /**
  21. * you can add `presetAttributify()` here to enable unocss attributify mode prompt
  22. * although preset is not working for applet, but will generate useless css
  23. * 为了不生产无用的css,要过滤掉 applet
  24. */
  25. // 支持css class属性化,eg: `<button bg="blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600" text="sm white">attributify Button</button>`
  26. presets.push(presetAttributify())
  27. }
  28. export default defineConfig({
  29. presets: [
  30. presetApplet({ enable: !isH5 }),
  31. presetRemRpx(),
  32. ...presets,
  33. // 支持图标,需要搭配图标库,eg: @iconify-json/carbon, 使用 `<button class="i-carbon-sun dark:i-carbon-moon" />`
  34. presetIcons({
  35. scale: 1.2,
  36. warn: true,
  37. extraProperties: {
  38. display: 'inline-block',
  39. 'vertical-align': 'middle',
  40. },
  41. }),
  42. ],
  43. /**
  44. * 自定义快捷语句
  45. * @see https://github.com/unocss/unocss#shortcuts
  46. */
  47. shortcuts: [['center', 'flex justify-center items-center']],
  48. transformers: [
  49. // 启用 @apply 功能
  50. transformerDirectives(),
  51. // 启用 () 分组功能
  52. // 支持css class组合,eg: `<div class="hover:(bg-gray-400 font-medium) font-(light mono)">测试 unocss</div>`
  53. transformerVariantGroup(),
  54. // Don't change the following order
  55. transformerAttributify(),
  56. transformerApplet(),
  57. ],
  58. rules: [
  59. [
  60. 'p-safe',
  61. {
  62. padding:
  63. 'env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)',
  64. },
  65. ],
  66. ['pt-safe', { 'padding-top': 'env(safe-area-inset-top)' }],
  67. ['pb-safe', { 'padding-bottom': 'env(safe-area-inset-bottom)' }],
  68. ],
  69. })