tailwind.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /** @type {import('tailwindcss').Config} */
  2. function genSimilarColorsName(brandName) {
  3. return {
  4. lighter: `var(--${brandName}-lighter-color)`,
  5. light: `var(--${brandName}-light-color)`,
  6. DEFAULT: `var(--${brandName}-color)`,
  7. deep: `var(--${brandName}-deep-color)`,
  8. deeper: `var(--${brandName}-deeper-color)`
  9. };
  10. }
  11. function generateSize(size, unit) {
  12. const result = {};
  13. for (let i = 0; i <= size; i++) {
  14. result[`${i}`] = `${i}${unit}`;
  15. }
  16. return result;
  17. }
  18. function genSimpleColorsName(names) {
  19. const colors = {};
  20. names.forEach(name => {
  21. colors[name] = `var(--${name}-color)`
  22. });
  23. return colors
  24. }
  25. module.exports = {
  26. // separator: '__', // 如果是小程序项目需要设置这一项,将 : 选择器替换成 __,之后 hover:bg-red-500 将改为 hover__bg-red-500
  27. corePlugins: {
  28. // 预设样式
  29. preflight: false, // 一般uniapp都有预设样式,所以不需要tailwindcss的预设
  30. // 以下功能小程序不支持
  31. // space: false, // > 子节点选择器
  32. // divideWidth: false,
  33. // divideColor: false,
  34. // divideStyle: false,
  35. // divideOpacity: false,
  36. },
  37. content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
  38. safelist: [
  39. { pattern: /grid-cols-[1-9]/ }
  40. ],
  41. theme: {
  42. spacing(config) {
  43. let result = { 0: '0', 'px': '0.5px' }
  44. // 允许的数值大一些也无所谓,最后打包tailwindcss会摇树优化,未使用的样式并不会打包
  45. for (let i = 1; i <= 400; i++) {
  46. result[i] = `${i}rpx`
  47. }
  48. return result
  49. },
  50. extend: {
  51. // 圆角
  52. borderRadius: generateSize(50, 'px'),
  53. // 行高
  54. lineHeight: generateSize(375, 'rpx'),
  55. // 字间距
  56. letterSpacing: generateSize(20, 'rpx'),
  57. // 旋转
  58. rotate: generateSize(180, 'deg'),
  59. zIndex: generateSize(100, ''),
  60. fontSize: {
  61. "base": '15px',
  62. "sm": '14px',
  63. "xs": '13px',
  64. "2xs": '12px',
  65. "3xs": '11px',
  66. "4xs": '10px',
  67. "lg": '16px',
  68. 'xl': '18px',
  69. '2xl': '20px',
  70. '3xl': '24px',
  71. '4xl': '28px',
  72. '5xl': '32px',
  73. '6xl': '36px',
  74. '7xl': '40px',
  75. ...generateSize(70, 'rpx'),
  76. },
  77. colors: {
  78. primary: genSimilarColorsName('primary'),
  79. success: genSimilarColorsName('success'),
  80. warning: genSimilarColorsName('warning'),
  81. error: genSimilarColorsName('error'),
  82. info: genSimilarColorsName('info'),
  83. ...genSimpleColorsName(['main', 'content', 'tips', 'light', 'border', 'bg', 'disabled']),
  84. // 只添加部分颜色,防止覆盖掉老颜色
  85. fore: {
  86. title: "var(--fore-title)",
  87. subtitle: "var(--fore-subtitle)",
  88. content: "var(--fore-content)",
  89. subcontent: "var(--fore-subcontent)",
  90. tip: "var(--fore-tip)",
  91. light: "var(--fore-light)",
  92. disabled: "var(--fore-disabled)",
  93. placeholder: "var(--fore-placeholder)",
  94. },
  95. back: {
  96. DEFAULT: "var(--back)",
  97. light: "var(--back-light)",
  98. }
  99. },
  100. // borderWidth: {
  101. // DEFAULT: '0.5px',
  102. // 1: '1px'
  103. // },
  104. backgroundImage: {
  105. 'register-bright': "url('/static/personal/top_bg.png')"
  106. },
  107. boxShadow: {
  108. 'up': '0 -1px 3px 0 rgb(0 0 0 / 0.1), 0 -1px 2px -1px rgb(0 0 0 / 0.1)'
  109. },
  110. flex: {
  111. 2: '2',
  112. 3: '3',
  113. 4: '4',
  114. 5: '5',
  115. 6: '6',
  116. 7: '7',
  117. 8: '8',
  118. 9: '9',
  119. 10: '10'
  120. }
  121. },
  122. },
  123. plugins: [],
  124. }