Saturday, June 27, 2020

No clear way to store resources in Kotlin JS projects

I'm working on a Node JS application written in Kotlin with the new Kotlin JS plugin. I needed to include some static files (web page templates) with the application, but it is not at all clear how I should connect them to the project. Gradle created a resources folder, but items in it didn't seem to be copied to anywhere in the build output. It looks like the old Kotlin2Js plugin worked with Webpack for deployment (?), but I see no such configuration or build step in my project. So I rigged up a post-compile step to just copy all the resources to the same folder as the compiled JavaScript files:
tasks.getByName("compileKotlinJs") {
    val resFolder = project.file("src/main/resources")
    inputs.dir(resFolder)
    doLast("copy resources") {
        resFolder.copyRecursively(project.file("build/js/packages/${project.name}/kotlin"), true)
    }
}

No comments:

Post a Comment