SwiftPM Build Plugin for integrating TailwindCSS
Find a file
laosb 37194f5d29
Some checks failed
CI / Test on Linux (push) Has been cancelled
CI / Test on Linux-1 (push) Has been cancelled
CI / Test on macOS (push) Has been cancelled
CI / Test on macOS-1 (push) Has been cancelled
chore: Use explicit ./artifacts path in release workflow
2025-10-23 20:46:37 +08:00
.github/workflows chore: Use explicit ./artifacts path in release workflow 2025-10-23 20:46:37 +08:00
.zed Improve source file detection and tests 2025-08-20 21:01:17 +08:00
Plugins/TailwindCSS fix: Specify UTF-8 encoding when reading Tailwind.css file 2025-08-20 21:12:55 +08:00
Sources fix: expand triple for bundle info.json too. 2025-10-05 17:37:39 +08:00
Tests/SwiftTailwindTests Improve source file detection and tests 2025-08-20 21:01:17 +08:00
.gitignore add artifact bundle script 2025-08-17 12:13:16 +08:00
LICENSE Add LICENSE and README files 2025-08-17 18:14:38 +08:00
Package.resolved refactor: Replace shell script with Swift CLI for artifact bundling 2025-10-05 15:39:43 +08:00
Package.swift fix: Update TailwindCSSCLI binary target to 1.1.0-test.4 2025-10-05 17:44:50 +08:00
README.md Prepare for new version scheme. 2025-08-18 15:55:22 +08:00

SwiftTailwind

Use Tailwind CSS in your Swift projects, seemlessly integrated as a Build Tool Plugin.

Usage

Add this package to your Swift project as a dependency using the Swift Package Manager.

dependencies: [
  .package(url: "https://github.com/laosb/SwiftTailwind.git", from: "1.0.0+tw.4.1.12"),
],

Then, in your Package.swift file, add the plugin to your target:

targets: [
  .target(
    name: "YourTargetName",
    plugins: [
      .plugin(name: "TailwindCSS", package: "SwiftTailwind")
    ]
  )
]

Place your Tailwind CSS entrypoint file at Tailwind.css in your target. To integrate seamlessly with Swift Package Manager build process, SwiftTailwind requires defining your source files explicitly, and does not support @source not to exclude files. Instead, you can use @source to include specific files or directories.

@import "tailwindcss" source(none);
/* Note that as of writing, Tailwind doesn't scan .swift files by default, so you need to specify a glob pattern including the extension. */
@source "./Views/**/*.swift";
@source "./Template.swift";
@source "./Static";

The plugin will automatically process your Tailwind CSS files during the build process, generating the necessary CSS output. The output will be named as tw.css and will be placed in the TailwindCSS.bundle directory within your target. You won't see it in your source tree, but it will be available to your build product as Bundle.module.url(forResource: "TailwindCSS", withExtension: "bundle").

import Foundation

let cssFileURL = Bundle.module
  .url(forResource: "TailwindCSS", withExtension: "bundle")!
  .appending(component: "tw.css")

About the binary blob

A binary artifact bundle will be downloaded from this repo's GitHub Releases. It contains the standalone version of Tailwind CSS CLI, which is used to process your Tailwind CSS files. This allows you to use Tailwind CSS without needing to install Node.js or npm in your Swift project.

It is built using Scripts/buildArtifactBundle.sh, which pulls the specified version of Tailwind CSS CLI from their GitHub Releases and packages it into a Swift Package compatible format. It is then manually uploaded to this repository's GitHub Releases.

Any contributions to automate the artifact generation are welcome!

License

This project is licensed under the MIT License. See the LICENSE file for details.