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 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/**/*.tmpl',
  29. './web_src/**/*.{js,vue}',
  30. ].filter(Boolean),
  31. blocklist: [
  32. // classes that don't work without CSS variables from "@tailwind base" which we don't use
  33. 'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter',
  34. 'backdrop-filter',
  35. // unneeded classes
  36. '[-a-zA-Z:0-9_.]',
  37. ],
  38. theme: {
  39. colors: {
  40. // make `tw-bg-red` etc work with our CSS variables
  41. ...Object.fromEntries(vars.filter((prop) => prop.startsWith('color-')).map((prop) => {
  42. const color = prop.substring(6);
  43. return [color, `var(--color-${color})`];
  44. })),
  45. inherit: 'inherit',
  46. current: 'currentcolor',
  47. transparent: 'transparent',
  48. },
  49. },
  50. };