https://github.com/livebud/tailwind
Tailwind.css for the Go ecosystem
https://github.com/livebud/tailwind
Last synced: 12 months ago
JSON representation
Tailwind.css for the Go ecosystem
- Host: GitHub
- URL: https://github.com/livebud/tailwind
- Owner: livebud
- License: mit
- Created: 2022-11-12T07:44:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-11T20:01:55.000Z (over 3 years ago)
- Last Synced: 2025-05-14T23:13:41.219Z (about 1 year ago)
- Language: Go
- Size: 528 KB
- Stars: 58
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: License.md
Awesome Lists containing this project
README
# Tailwind.go
Use Tailwind in Go.
Unlike other options, this package embeds tailwind directly and doesn't spawn a subprocess, so it's faster.
## Example Usage
```go
package main
import (
"context"
"fmt"
"os"
"github.com/livebud/js"
v8 "github.com/livebud/js/v8"
"github.com/livebud/tailwind"
)
func main() {
// Initialize a V8 isolate
vm, _ := v8.Load(&js.Console{
Log: os.Stdout,
Error: os.Stderr,
})
defer vm.Close()
// Generate the CSS for this index.html file
processor := tailwind.New(vm)
ctx := context.Background()
css, _ := processor.Process(ctx, "index.html", `
Hello Tailwind!
`)
fmt.Println(css)
}
```
This results in a CSS file:
```css
/*! tailwindcss v3.2.4 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}html{-webkit-text-size-adjust:100%;font-feature-settings:normal;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4}
/* ... */
```
For production, I recommend building this CSS file and embedding it alongside the processed HTML file.
For development, you may want to run this processor dynamically. Keep in mind that this processor currently depends on CGO.
I originally built this project for [Bud](https://github.com/livebud/bud), which handles the environment differences for you.
## CLI Usage
We've also included a rudimentary CLI for quickly testing. If you already have the official CLI installed, stick with that.
```
go install github.com/livebud/tailwind/cmd/tailwind@latest
tailwind example/play.html
```
## Development
You can install the dependencies with make install:
```sh
make install
```
This command expects that you have `go` and `npm` in your toolchain. After installing the dependencies, you can run tests with:
```sh
make test
```
## License
MIT