You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tailwind.config.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {readFileSync} from 'node:fs';
  2. import {env} from 'node:process';
  3. import {parse} from 'postcss';
  4. const isProduction = env.NODE_ENV !== 'development';
  5. function extractRootVars(css) {
  6. const root = parse(css);
  7. const vars = new Set();
  8. root.walkRules((rule) => {
  9. if (rule.selector !== ':root') return;
  10. rule.each((decl) => {
  11. if (decl.value && decl.prop.startsWith('--')) {
  12. vars.add(decl.prop.substring(2));
  13. }
  14. });
  15. });
  16. return Array.from(vars);
  17. }
  18. const vars = extractRootVars([
  19. readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
  20. readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
  21. ].join('\n'));
  22. export default {
  23. prefix: 'tw-',
  24. important: true, // the frameworks are mixed together, so tailwind needs to override other framework's styles
  25. content: [
  26. isProduction && '!./templates/devtest/**/*',
  27. isProduction && '!./web_src/js/standalone/devtest.js',
  28. '!./templates/swagger/v1_json.tmpl',
  29. '!./templates/user/auth/oidc_wellknown.tmpl',
  30. '!**/*_test.go',
  31. '!./modules/{public,options,templates}/bindata.go',
  32. './{build,models,modules,routers,services}/**/*.go',
  33. './templates/**/*.tmpl',
  34. './web_src/js/**/*.{js,vue}',
  35. ].filter(Boolean),
  36. blocklist: [
  37. // classes that don't work without CSS variables from "@tailwind base" which we don't use
  38. 'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter',
  39. 'backdrop-filter',
  40. // we use double-class tw-hidden defined in web_src/css/helpers.css for increased specificity
  41. 'hidden',
  42. // unneeded classes
  43. '[-a-zA-Z:0-9_.]',
  44. ],
  45. theme: {
  46. colors: {
  47. // make `tw-bg-red` etc work with our CSS variables
  48. ...Object.fromEntries(vars.filter((prop) => prop.startsWith('color-')).map((prop) => {
  49. const color = prop.substring(6);
  50. return [color, `var(--color-${color})`];
  51. })),
  52. inherit: 'inherit',
  53. current: 'currentcolor',
  54. transparent: 'transparent',
  55. },
  56. borderRadius: {
  57. 'none': '0',
  58. 'sm': '2px',
  59. 'DEFAULT': 'var(--border-radius)', // 4px
  60. 'md': 'var(--border-radius-medium)', // 6px
  61. 'lg': '8px',
  62. 'xl': '12px',
  63. '2xl': '16px',
  64. '3xl': '24px',
  65. 'full': 'var(--border-radius-circle)', // 50%
  66. },
  67. fontFamily: {
  68. sans: 'var(--fonts-regular)',
  69. mono: 'var(--fonts-monospace)',
  70. },
  71. fontWeight: {
  72. light: 'var(--font-weight-light)',
  73. normal: 'var(--font-weight-normal)',
  74. medium: 'var(--font-weight-medium)',
  75. semibold: 'var(--font-weight-semibold)',
  76. bold: 'var(--font-weight-bold)',
  77. },
  78. fontSize: { // not using `rem` units because our root is currently 14px
  79. 'xs': '12px',
  80. 'sm': '14px',
  81. 'base': '16px',
  82. 'lg': '18px',
  83. 'xl': '20px',
  84. '2xl': '24px',
  85. '3xl': '30px',
  86. '4xl': '36px',
  87. '5xl': '48px',
  88. '6xl': '60px',
  89. '7xl': '72px',
  90. '8xl': '96px',
  91. '9xl': '128px',
  92. ...Object.fromEntries(Array.from({length: 100}, (_, i) => {
  93. return [`${i}`, `${i === 0 ? '0' : `${i}px`}`];
  94. })),
  95. },
  96. },
  97. };