1

I'm trying to build some basic Kotlin code as a JS library. Just for testing, I want to be able to call some of this code right from a browser console.

Here is some of the code I'm working with.

build.gradle.kts

plugins {
    kotlin("js") version "1.5.10"
}

group = "..."
version = "..."

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(kotlin("test"))
}

kotlin {
    js(LEGACY) {
        browser {
            webpackTask {
                output.libraryTarget = "global"
                output.library = "connect"
            }
        }
        binaries.executable()
    }
}

main.kt

package main


fun main(args: Array<String>) {
    println("Hello world! From Kotlin!")
}

fun testLog(string: String){
    console.log("test log")
    console.log(string)
}

index.html

<!DOCTYPE html>
<html>
    <head>
        <script src="./connect.js"></script>
    </head>
    <body>
        <h1>test</h1>
    </body>
</html>

But this is what I get in the console.

browser console output

What am I missing?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.