Skip to content

Commit d70b631

Browse files
merge: Allow the browser to see the initial Kotlin source files
With this MR, the Vite plugin serves the initial Kotlin source files so the browser can find them. With this MR, Chrome does find the initial Kotlin files, however it still doesn't refer to them in stack traces. This is the first step towards, but not a complete solution to, #56. See merge request opensavvy/automation/kotlin-vite!106
2 parents 7b9d2c4 + c516b9c commit d70b631

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

vite-base/src/main/kotlin/config/Dump.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fun DumpDsl.dumpViteConfig(config: ViteConfig) {
99

1010
value("Root", config.root)
1111
value("Base", config.base)
12+
value("Public dir", config.publicDir)
1213
}
1314

1415
section("Build") {

vite-base/src/main/kotlin/config/ViteConfig.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface ViteConfig {
3636
root.convention(other.root)
3737
base.convention(other.base)
3838
plugins.convention(other.plugins)
39+
publicDir.convention(other.publicDir)
3940
build.target.convention(other.build.target)
4041
build.modulePreload.convention(other.build.modulePreload)
4142
build.outDir.convention(other.build.outDir)
@@ -149,6 +150,15 @@ interface ViteConfig {
149150
)
150151
}
151152

153+
/**
154+
* Directory to serve as plain static assets. Files in this directory are served at `/` during dev
155+
* and copied to the root `outDir` during build, and are always served or copied as-is without transform.
156+
*
157+
* The value can be either an absolute file system path or a path relative to the project [root].
158+
*/
159+
@get:Internal
160+
val publicDir: Property<String>
161+
152162
/**
153163
* Configuration for Rollup to build the production bundle.
154164
*

vite-base/src/main/kotlin/tasks/WriteConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ abstract class WriteConfig : DefaultTask() {
4242
inputs.property("plugins", config.plugins)
4343
inputs.property("base", config.base)
4444
inputs.property("root", config.root.map { it.toString() })
45+
inputs.property("publicDir", config.publicDir.orElse("false"))
4546
inputs.property("build.target", config.build.target)
4647
inputs.property("build.modulePreload", config.build.modulePreload)
4748
inputs.property("build.outDir", config.build.outDir.map { it.toString() })
@@ -74,6 +75,7 @@ abstract class WriteConfig : DefaultTask() {
7475
.joinToString(separator = ",\n ") { "${it.exportedAs}(${it.configuration ?: ""})" }
7576
},
7677
],
78+
publicDir: ${config.publicDir.orNull?.let { "'$it'" } ?: false},
7779
build: {
7880
target: '${config.build.target.get()}',
7981
modulePreload: ${config.build.modulePreload.get()},

vite-kotlin/src/main/kotlin/KotlinVitePlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal val Project.viteBuildProdDir: Provider<Directory>
5454
get() = viteBuildDir.map { it.dir("prod") }
5555

5656
internal val Project.viteBuildDevDir: Provider<Directory>
57-
get() = viteBuildDir.map { it.dir("dev/child") } // subfolder to match the nesting of the source maps :)
57+
get() = viteBuildDir.map { it.dir("dev") }
5858

5959
/**
6060
* Default dist directory (override by config)

vite-kotlin/src/main/kotlin/tasks/ConfigWriter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal fun createConfigWriterTasks(project: Project) {
2020

2121
config {
2222
root.set(project.viteBuildDevDir)
23+
publicDir.convention("../../../../..")
2324

2425
build {
2526
outDir.set(project.viteBuildDistDir)

0 commit comments

Comments
 (0)