Thread
#compose-web
    c

    Carter

    1 year ago
    Let’s say I’m modularizing a compose web app being served by a JVM ktor server. So I’ve got: browserApp module contains all the compose UI and also image assets. serverApp module contains several rest endpoints plus the root route returns the compose JavaScript client. My question is: is there a way currently to get the image assets in browserApp to be served from serverApp? Currently they aren’t being packaged into the server JAR, and I don’t know if this is possible.
    Big Chungus

    Big Chungus

    1 year ago
    They should be packed. Do you have them in browser resources?
    Here's my (non-compoae) fullstack setup. https://www.github.com/mpetuska/kamp/tree/master/app%2Fbuild.gradle.kts Might give you an idea how to serve embedded assets
    c

    Carter

    1 year ago
    When you say “in browser resources” what does that mean? If I run the browserApp directly (task browserApp:jsBrowserRun) then the assets are loaded.
    Also I’ll take a look at the example thanks! This is probably more of a gradle setup issue instead of compose
    Thanks to your help, I did get it finally working. This is what I ended up with, which has improved performance for debug builds by disabling webpack until a flag is set. I also had to work around a minor security issue by stripping the webpack mapping file (otherwise it could accidentally be served if someone could guess the filename).
    tasks.getByName<Jar>("jvmJar") {
        val webpackTask = run {
            val webpackTaskName = if (isJavascriptMinificationEnabled) {
                "jsBrowserProductionWebpack"
            } else {
                "jsBrowserDevelopmentWebpack"
            }
    
            tasks.getByPath(":browserApp:$webpackTaskName") as org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
        }
        dependsOn(webpackTask)
        from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) {
            include("*.js") // ensures the mapping file doesn't get copied
            into("asset/js")
        }
    
        // Get the resources
        val browserDistributionTask = tasks.getByPath(":browserApp:jsBrowserProductionExecutableDistributeResources")
        dependsOn(browserDistributionTask)
        from(browserDistributionTask.outputs)
    }
    Big Chungus

    Big Chungus

    1 year ago
    Glad to hear you've figured it out