0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kotlin Multiplatform Javascript版 Day1

Last updated at Posted at 2024-03-16

概要

(個人メモ)
NodejsやBrowser向けのKotlin Multiplatformプロジェクトのテンプレを作成

ソース

実行

nodejs
gradlew jsNodeRun

標準出力にHello World!が表示される。

browser
gradlew jsBrowserRun

開いたBrowserのConsoleにHello World!が出力されている。

関数をexportするnpmモジュールを取り込む

例: is-sortedモジュール

JavaScriptモジュール側の定義スタイル
//...
module.exports = function checksort (array, comparator) {
//...
build.gradle.kts
//..
kotlin {
    js {
        nodejs {}
        binaries.executable()
    }
    sourceSets {
        val jsMain by getting {
            dependencies {implementation(npm("is-sorted", "1.0.5"))}
        }
    }
}
Main.kt
@JsModule("is-sorted")
@JsNonModule
external fun <T> sorted(a: Array<T>): Boolean

fun main() {
    println("Is sorted: ${sorted(arrayOf(1, 2, 3))}")
    println("Is sorted: ${sorted(arrayOf(1, 3, 2))}")
}

クラスをexportするnpmモジュールを取り込む

TODO

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?