### Install SwiftTailwind Package Source: https://github.com/loopwerk/swifttailwind/blob/main/README.md This snippet shows how to add SwiftTailwind as a dependency to your Swift project's Package.swift file. It ensures that SwiftTailwind is available for use in your executable targets. ```swift dependencies: [ .package(url: "https://github.com/loopwerk/SwiftTailwind", from: "1.0.0"), ], targets: [ .executableTarget( name: "YourApp", dependencies: ["SwiftTailwind"] ), ] ``` -------------------------------- ### Initialize SwiftTailwind Instance Source: https://context7.com/loopwerk/swifttailwind/llms.txt Demonstrates how to instantiate the SwiftTailwind client by specifying a Tailwind CSS version. The library automatically resolves the project root by locating the Package.swift file. ```swift import SwiftTailwind // Initialize with a specific Tailwind CSS version let tailwind = SwiftTailwind(version: "4.2.1") // For Tailwind CSS 3.x projects let tailwind3 = SwiftTailwind(version: "3.4.17") ``` -------------------------------- ### Run Tailwind CSS with SwiftTailwind Source: https://github.com/loopwerk/swifttailwind/blob/main/README.md This Swift code demonstrates how to initialize SwiftTailwind and run the Tailwind CSS CLI with specified options. It handles the downloading and caching of the CLI, requiring no Node.js or npm. ```swift import SwiftTailwind let tailwind = SwiftTailwind(version: "4.2.1") try await tailwind.run( input: "input.css", output: "output.css", options: .minify ) ``` -------------------------------- ### Execute Tailwind CSS Compilation Source: https://context7.com/loopwerk/swifttailwind/llms.txt Shows how to run the Tailwind CLI using the run method. Supports input/output file paths, minification, and watch mode through the options parameter. ```swift import SwiftTailwind let tailwind = SwiftTailwind(version: "4.2.1") // Basic usage - compile input.css to output.css try await tailwind.run( input: "src/styles/input.css", output: "public/css/output.css" ) // With minification for production builds try await tailwind.run( input: "src/styles/input.css", output: "public/css/output.css", options: .minify ) // With watch mode for development try await tailwind.run( input: "src/styles/input.css", output: "public/css/output.css", options: .watch ) // Combining multiple options try await tailwind.run( input: "src/styles/input.css", output: "public/css/output.css", options: .minify, .watch ) // Using absolute paths try await tailwind.run( input: "/Users/dev/project/src/input.css", output: "/Users/dev/project/dist/output.css", options: .minify ) ``` -------------------------------- ### Configure RunOption for CLI Execution Source: https://context7.com/loopwerk/swifttailwind/llms.txt Explains how to use the RunOption enum to configure CLI flags like minification and watch mode. Options can be passed individually or as an array. ```swift import SwiftTailwind let tailwind = SwiftTailwind(version: "4.2.1") // Production build with minification try await tailwind.run( input: "input.css", output: "output.css", options: .minify ) // Development with file watching try await tailwind.run( input: "input.css", output: "output.css", options: .watch ) // Pass options as an array for dynamic configuration let options: [RunOption] = [.minify] try await tailwind.run( input: "input.css", output: "output.css", options: options ) ``` -------------------------------- ### Handle SwiftTailwind Errors Source: https://context7.com/loopwerk/swifttailwind/llms.txt Demonstrates how to catch and handle specific errors thrown by SwiftTailwind, such as platform incompatibility, download failures, or checksum mismatches. ```swift import SwiftTailwind let tailwind = SwiftTailwind(version: "4.2.1") do { try await tailwind.run( input: "input.css", output: "output.css", options: .minify ) } catch SwiftTailwindError.unsupportedPlatform { print("Error: This platform or architecture is not supported by the Tailwind CSS standalone CLI.") } catch SwiftTailwindError.downloadFailed(let url) { print("Error: Failed to download from \(url)") } catch SwiftTailwindError.checksumMismatch { print("Error: Downloaded binary failed checksum validation.") } catch { print("Unexpected error: \(error.localizedDescription)") } ``` -------------------------------- ### Compile Tailwind CSS with SwiftTailwind Source: https://context7.com/loopwerk/swifttailwind/llms.txt This Swift code snippet shows how to use the SwiftTailwind library to compile CSS. It includes functionality to minify the output and can be used in a build process for static sites or server applications. The primary dependency is the SwiftTailwind package. ```swift import SwiftTailwind import Foundation struct SiteBuilder { let tailwind = SwiftTailwind(version: "4.2.1") func build(minify: Bool = false) async throws { print("Building site...") // Compile Tailwind CSS if minify { try await tailwind.run( input: "resources/css/main.css", output: "output/css/styles.css", options: .minify ) } else { try await tailwind.run( input: "resources/css/main.css", output: "output/css/styles.css" ) } print("CSS compiled successfully") } func develop() async throws { print("Starting development server with CSS watching...") // Run Tailwind in watch mode for development try await tailwind.run( input: "resources/css/main.css", output: "output/css/styles.css", options: .watch ) } } // Usage let builder = SiteBuilder() try await builder.build(minify: true) // Production // or try await builder.develop() // Development with watch ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.