Skip to content

Commit

Permalink
Vite. Add SingleViteCachePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
porotkin committed Sep 2, 2024
1 parent b8eb6f9 commit 575f27b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.turansky.kfc.gradle.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.named

class SingleViteCachePlugin : Plugin<Project> {
override fun apply(target: Project): Unit = with(target) {
tasks.link(Vite.productionTask, Vite.developmentTask)
tasks.link(Vite.developmentTask, Vite.productionTask)
}

private fun TaskContainer.link(
taskName: String,
relatedTaskName: String,
) {
named<KotlinViteTask>(taskName) {
doFirst {
val relatedTask = named<KotlinViteTask>(relatedTaskName).get()
project.delete(relatedTask.outputDirectory)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.turansky.kfc.gradle.plugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.create

class ViteApplicationPlugin : Plugin<Project> {
Expand All @@ -28,6 +29,8 @@ class ViteApplicationPlugin : Plugin<Project> {
tasks.named("build") {
dependsOn(Vite.productionTask)
}

plugins.apply(SingleViteCachePlugin::class)
}
}

Expand Down

0 comments on commit 575f27b

Please sign in to comment.