ch8n / kmm-full-stack

0 stars 0 forks source link

unable to create share code in react js #1

Open ch8n opened 1 week ago

ch8n commented 1 week ago

I'm working on sharing my models in a Ktor app, targeting the jsMain module, which will be called from a front-end written in React with Vite. I used the KMP Wizard to generate the Ktor server and added the jsMain module manually. In the composeApp package's build.gradle.kts, I added this block to configure JavaScript:

js {
    useCommonJs()
    moduleName = "kotlinJs"
    browser {
        testTask {
            enabled = false
        }
        webpackTask {
            outputFileName = "kotlin.js"
            output.libraryTarget = COMMONJS2
        }
        @OptIn(ExperimentalDistributionDsl::class)
        distribution {
            outputDirectory.set(projectDir.resolve("output"))
        }
    }
    binaries.executable()
}

In the shared module's build.gradle.kts, I only added:

js {
    browser()
    binaries.executable()
}

When I run jsBrowserProductionWebpack, it creates the kotlin.js bundle. However, I’m having trouble importing this JS file into my React project. Any help would be greatly appreciated!

ch8n commented 1 week ago

link to a thread in slack channel is available here Slack thread