Hi Guys ^^, I need to call this kotlin function f...
# compose-web
n
Hi Guys ^^, I need to call this kotlin function from wasm index.html script.
Copy code
@JsExport
fun submitJsonToKMM(jsonData: String) {
    
}
My index.html code
Copy code
<script>

const editor = ace.edit("editor");

function submitJson() {
        const jsonData = editor.getValue();
        // Pass the JSON data to the KMM WASM project
        submitJsonToKMM(jsonData);
      }
</script>
It’s not working, getting
submitJsonToKMM is not defined
, Can anyone please help…
b
Depends on which output do you consume. If it’s webpack output (dist) you need to configure Webapck in build.gradle.kts like:
Copy code
browser {
    commonWebpackConfig {
        output = KotlinWebpackOutput("Foo", KotlinWebpackOutput.Target.VAR)
        ...
    }
}
Related webpack docs
Then at runtime you will have a Foo with Promise<Module>
In index.html, after mains script included you can do:
Copy code
<script type="module">
    // to avoid writing await ..ю  every time 
    globalThis.Foo = await Foo;

    // call exported fun bar
    Foo.bar();
</script>