I am using Vapor and its FileMiddleware
to host CSS files. It automatically hosts all files in my packages Public
directory. I want to pre-process my CSS files using Tailwind CSS, so I am trying to create a build tool plugin to do so.
I've implemented my plugin like this:
import PackagePlugin
@main
struct TailwindCSSBuild: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
guard let target = target as? SourceModuleTarget else { return [] }
let inputFiles = target.sourceFiles.filter({ $0.path.extension == "css" })
return try inputFiles.map { inputFile in
let inputPath = inputFile.path
let outputName = inputPath.stem + ".css"
let outputPath = context.pluginWorkDirectory.appending(outputName)
return .buildCommand(
displayName: "Generating \(outputName) from \(inputPath.lastComponent)",
executable: try context.tool(named: "tailwindcss").path,
arguments: [
"-i", "\(inputPath)",
"-o", "\(outputPath)",
"-c", "\(context.package.directory.appending("tailwind.config.js"))"
],
inputFiles: [inputPath],
outputFiles: [outputPath]
)
}
}
}
Whenever I call swift run
with my app package that uses the plugin, I get
error: unexpected input file: <path to my app package>/.build/plugins/outputs/app/App/TailwindCSSBuild/index.css
Is there a way to do custom processing of a resource like this without throwing this error?