Created
December 15, 2023 05:41
-
-
Save eduardolat/438a1de077ccac6b9792153e708c1824 to your computer and use it in GitHub Desktop.
Regex for TailwindCSS + Gomponents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @type {import('tailwindcss').Config} */ | |
module.exports = { | |
// Change this to your project source folder | |
content: ['./web/**/*.go'], | |
plugins: [], | |
theme: { | |
extend: {}, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Tailwind CSS + Gomponents | |
// It can handle single and multiple lines inside the matches | |
// It can handle double quotes (") and backticks (`) | |
"tailwindCSS.includeLanguages": { | |
"go": "go", | |
}, | |
"tailwindCSS.experimental.classRegex": [ | |
["Class\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"], // Class("...") or Class(`...`) | |
["Classes\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"], // Classes("...") or Classes(`...`) | |
["Class\\{([^)]*)\\}", "[\"`]([^\"`]*)[\"`]"], // Class{"..."} or Class{`...`} | |
["Classes\\{([^)]*)\\}", "[\"`]([^\"`]*)[\"`]"], // Classes{"..."} or Classes{`...`} | |
["Class:\\s*[\"`]([^\"`]*)[\"`]"], // Class: "..." or Class: `...` | |
["Classes:\\s*[\"`]([^\"`]*)[\"`]"], // Classes: "..." or Classes: `...` | |
], | |
} |
Here's my whole current config for GoLand, going to Settings -> Languages & Frameworks -> Style Sheets -> TailwindCSS:
{
"includeLanguages": {
"ftl": "html",
"jinja": "html",
"jinja2": "html",
"smarty": "html",
"tmpl": "gohtml",
"cshtml": "html",
"vbhtml": "html",
"razor": "html",
"go": "html"
},
"files": {
"exclude": [
"**/.git/**",
"**/node_modules/**",
"**/.hg/**",
"**/.svn/**"
]
},
"emmetCompletions": false,
"classAttributes": ["class", "className", "ngClass"],
"colorDecorators": false,
"showPixelEquivalents": true,
"rootFontSize": 16,
"hovers": true,
"suggestions": true,
"codeActions": true,
"validate": true,
"lint": {
"invalidScreen": "error",
"invalidVariant": "error",
"invalidTailwindDirective": "error",
"invalidApply": "error",
"invalidConfigPath": "error",
"cssConflict": "warning",
"recommendedVariantOrder": "warning"
},
"experimental": {
"configFile": null,
"classRegex": [
["Class(?:es)?[({]([^)}]*)[)}]", "[\"`]([^\"`]*)[\"`]"]
]
}
}
Note that I had to install TailwindCSS through npm for this to work, the Tailwind CLI doesn't seem to be enough:
npm install -D tailwindcss
I got it working in GoLand without installing node dependencies with this little hack: https://youtrack.jetbrains.com/issue/WEB-55647/Support-Tailwind-css-autocompletion-using-standalone-tailwind-CLI#focus=Comments-27-10957961.0-0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! This also appears to work for the IntelliJ/GoLand plugin.