mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-15 18:08:23 -07:00
72b213b00f
Tailwind content is not going to appear in `web_src/css`, `web_src/fomantic` or `web_src/svg` or the JSON templates, so we don't need to have tailwind scan these directories which will speed up the build. --------- Co-authored-by: delvh <dev.lh@web.de>
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
import {readFileSync} from 'node:fs';
|
|
import {env} from 'node:process';
|
|
import {parse} from 'postcss';
|
|
|
|
const isProduction = env.NODE_ENV !== 'development';
|
|
|
|
function extractRootVars(css) {
|
|
const root = parse(css);
|
|
const vars = new Set();
|
|
root.walkRules((rule) => {
|
|
if (rule.selector !== ':root') return;
|
|
rule.each((decl) => {
|
|
if (decl.value && decl.prop.startsWith('--')) {
|
|
vars.add(decl.prop.substring(2));
|
|
}
|
|
});
|
|
});
|
|
return Array.from(vars);
|
|
}
|
|
|
|
const vars = extractRootVars([
|
|
readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
|
|
readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
|
|
].join('\n'));
|
|
|
|
export default {
|
|
prefix: 'tw-',
|
|
important: true, // the frameworks are mixed together, so tailwind needs to override other framework's styles
|
|
content: [
|
|
isProduction && '!./templates/devtest/**/*',
|
|
isProduction && '!./web_src/js/standalone/devtest.js',
|
|
'!./templates/swagger/v1_json.tmpl',
|
|
'!./templates/user/auth/oidc_wellknown.tmpl',
|
|
'./templates/**/*.tmpl',
|
|
'./web_src/js/**/*.{js,vue}',
|
|
].filter(Boolean),
|
|
blocklist: [
|
|
// classes that don't work without CSS variables from "@tailwind base" which we don't use
|
|
'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter',
|
|
'backdrop-filter',
|
|
// unneeded classes
|
|
'[-a-zA-Z:0-9_.]',
|
|
],
|
|
theme: {
|
|
colors: {
|
|
// make `tw-bg-red` etc work with our CSS variables
|
|
...Object.fromEntries(vars.filter((prop) => prop.startsWith('color-')).map((prop) => {
|
|
const color = prop.substring(6);
|
|
return [color, `var(--color-${color})`];
|
|
})),
|
|
inherit: 'inherit',
|
|
current: 'currentcolor',
|
|
transparent: 'transparent',
|
|
},
|
|
},
|
|
};
|