Skip to content

Commit f4b9257

Browse files
silverwindGiteaBot
andauthored
Add tailwindcss (#29357)
This will get tailwindcss working on a basic level. It provides only the utility classes, e.g. no tailwind base which we don't need because we have our own CSS reset. Without the base, we also do not have their CSS variables so a small amount of features do not work and I removed the generated classes for them. ***Note for future developers: This currently uses a `tw-` prefix, so we use it like `tw-p-3`.*** <details> <summary>Currently added CSS, all false-positives</summary> ``` .\!visible{ visibility: visible !important } .visible{ visibility: visible } .invisible{ visibility: hidden } .collapse{ visibility: collapse } .static{ position: static } .\!fixed{ position: fixed !important } .absolute{ position: absolute } .relative{ position: relative } .sticky{ position: sticky } .left-10{ left: 2.5rem } .isolate{ isolation: isolate } .float-right{ float: right } .float-left{ float: left } .mr-2{ margin-right: 0.5rem } .mr-3{ margin-right: 0.75rem } .\!block{ display: block !important } .block{ display: block } .inline-block{ display: inline-block } .inline{ display: inline } .flex{ display: flex } .inline-flex{ display: inline-flex } .\!table{ display: table !important } .inline-table{ display: inline-table } .table-caption{ display: table-caption } .table-cell{ display: table-cell } .table-column{ display: table-column } .table-column-group{ display: table-column-group } .table-footer-group{ display: table-footer-group } .table-header-group{ display: table-header-group } .table-row-group{ display: table-row-group } .table-row{ display: table-row } .flow-root{ display: flow-root } .inline-grid{ display: inline-grid } .contents{ display: contents } .list-item{ display: list-item } .\!hidden{ display: none !important } .hidden{ display: none } .flex-shrink{ flex-shrink: 1 } .shrink{ flex-shrink: 1 } .flex-grow{ flex-grow: 1 } .grow{ flex-grow: 1 } .border-collapse{ border-collapse: collapse } .select-all{ user-select: all } .resize{ resize: both } .flex-wrap{ flex-wrap: wrap } .overflow-visible{ overflow: visible } .rounded{ border-radius: 0.25rem } .border{ border-width: 1px } .text-justify{ text-align: justify } .uppercase{ text-transform: uppercase } .lowercase{ text-transform: lowercase } .capitalize{ text-transform: capitalize } .italic{ font-style: italic } .text-red{ color: var(--color-red) } .text-shadow{ color: var(--color-shadow) } .underline{ text-decoration-line: underline } .overline{ text-decoration-line: overline } .line-through{ text-decoration-line: line-through } .outline{ outline-style: solid } .ease-in{ transition-timing-function: cubic-bezier(0.4, 0, 1, 1) } .ease-in-out{ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) } .ease-out{ transition-timing-function: cubic-bezier(0, 0, 0.2, 1) } ``` </details> --------- Co-authored-by: Giteabot <[email protected]>
1 parent 4ccf5ab commit f4b9257

File tree

9 files changed

+530
-58
lines changed

9 files changed

+530
-58
lines changed

.stylelintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ rules:
9898
at-rule-allowed-list: null
9999
at-rule-disallowed-list: null
100100
at-rule-empty-line-before: null
101-
at-rule-no-unknown: true
101+
at-rule-no-unknown: [true, {ignoreAtRules: [tailwind]}]
102102
at-rule-no-vendor-prefix: true
103103
at-rule-property-required-list: null
104104
block-no-empty: true

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/m
119119
FOMANTIC_WORK_DIR := web_src/fomantic
120120

121121
WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
122-
WEBPACK_CONFIGS := webpack.config.js
122+
WEBPACK_CONFIGS := webpack.config.js tailwind.config.js
123123
WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
124124
WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts public/assets/img/webpack
125125

package-lock.json

Lines changed: 458 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"chartjs-plugin-zoom": "2.0.1",
2424
"clippie": "4.0.6",
2525
"css-loader": "6.10.0",
26+
"css-variables-parser": "1.0.1",
2627
"dayjs": "1.11.10",
2728
"dropzone": "6.0.0-beta.2",
2829
"easymde": "2.18.0",
@@ -40,9 +41,12 @@
4041
"monaco-editor": "0.46.0",
4142
"monaco-editor-webpack-plugin": "7.1.0",
4243
"pdfobject": "2.3.0",
44+
"postcss": "8.4.35",
45+
"postcss-loader": "8.1.0",
4346
"pretty-ms": "9.0.0",
4447
"sortablejs": "1.15.2",
4548
"swagger-ui-dist": "5.11.6",
49+
"tailwindcss": "3.4.1",
4650
"throttle-debounce": "5.0.0",
4751
"tinycolor2": "1.6.0",
4852
"tippy.js": "6.3.7",

tailwind.config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {readFileSync} from 'node:fs';
2+
import {env} from 'node:process';
3+
import {parse} from 'css-variables-parser';
4+
5+
const isProduction = env.NODE_ENV !== 'development';
6+
7+
export default {
8+
prefix: 'tw-',
9+
content: [
10+
isProduction && '!./templates/devtest/**/*',
11+
isProduction && '!./web_src/js/standalone/devtest.js',
12+
'./templates/**/*.tmpl',
13+
'./web_src/**/*.{js,vue}',
14+
].filter(Boolean),
15+
blocklist: [
16+
// classes that don't work without CSS variables from "@tailwind base" which we don't use
17+
'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter',
18+
'backdrop-filter',
19+
// unneeded classes
20+
'[-a-zA-Z:0-9_.]',
21+
],
22+
theme: {
23+
colors: {
24+
// make `tw-bg-red` etc work with our CSS variables
25+
...Object.fromEntries(
26+
Object.keys(parse([
27+
readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
28+
readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
29+
].join('\n'), {})).filter((prop) => prop.startsWith('color-')).map((prop) => {
30+
const color = prop.substring(6);
31+
return [color, `var(--color-${color})`];
32+
})
33+
),
34+
inherit: 'inherit',
35+
current: 'currentcolor',
36+
transparent: 'transparent',
37+
},
38+
},
39+
};

templates/devtest/gitea-ui.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@
275275
<div>ps: no JS code attached, so just a layout</div>
276276
{{template "shared/combomarkdowneditor" .}}
277277
</div>
278+
279+
<h1>Tailwind CSS Demo</h1>
280+
<div>
281+
<button class="{{if true}}tw-bg-red{{end}} tw-p-5 tw-border tw-rounded hover:tw-bg-blue active:tw-bg-yellow">Button</button>
282+
</div>
283+
278284
<script src="{{AssetUrlPrefix}}/js/devtest.js?v={{AssetVersion}}"></script>
279285
</div>
280286
{{template "base/footer" .}}

web_src/css/base.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
--fonts-regular: var(--fonts-override, var(--fonts-proportional)), "Noto Sans", "Liberation Sans", sans-serif, var(--fonts-emoji);
3030
}
3131

32+
*, ::before, ::after {
33+
/* these are needed for tailwind borders to work because we do not load tailwind's base
34+
https://github.com/tailwindlabs/tailwindcss/blob/master/src/css/preflight.css */
35+
border-width: 0;
36+
border-style: solid;
37+
border-color: currentcolor;
38+
}
39+
3240
textarea {
3341
font-family: var(--fonts-regular);
3442
}

web_src/css/index.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@
5959
@import "./explore.css";
6060
@import "./review.css";
6161
@import "./actions.css";
62+
63+
@tailwind utilities;
6264
@import "./helpers.css";

webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import webpack from 'webpack';
1111
import {fileURLToPath} from 'node:url';
1212
import {readFileSync} from 'node:fs';
1313
import {env} from 'node:process';
14+
import tailwindcss from 'tailwindcss';
15+
import tailwindConfig from './tailwind.config.js';
1416

1517
const {EsbuildPlugin} = EsBuildLoader;
1618
const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
@@ -145,6 +147,15 @@ export default {
145147
import: {filter: filterCssImport},
146148
},
147149
},
150+
{
151+
loader: 'postcss-loader',
152+
options: {
153+
postcssOptions: {
154+
map: false, // https://github.com/postcss/postcss/issues/1914
155+
plugins: [tailwindcss(tailwindConfig)],
156+
},
157+
},
158+
}
148159
],
149160
},
150161
{

0 commit comments

Comments
 (0)