Thread
#multiplatform
    j

    janvladimirmostert

    2 years ago
    I'm trying out Kotlin Multiplatform for the first time, i've used the IntelliJ New Module to create a JVM/JS project What is the correct way to add a new npm dependency that does have TypeScript support should i just add it in the jsMain in build.gradle
    jsMain {
                dependencies {
                    implementation kotlin('stdlib-js')
                    implementation npm('lit-html', '1.2.1')
                }
            }
    or should i rather do
    mkdir lit-html-kt
    cd lit-html-kt
    npm init -y || exit
    sudo npm install -g dukat || exit
    npm install lit-html || exit
    dukat node_modules/lit-html/lit-html.d.ts || exit
    
    rm -rf ./*.json || exit
    rm -rf ./node_modules || exit
    which then generates kotlin files for this npm package ?
    j

    Joffrey

    2 years ago
    If you just add the npm dependency, you won't be able to use it from Kotlin. In addition to declaring it in Gradle, you need Kotlin external declarations for it to work. These declarations can be manually generated using Dukat via CLI as you pointed out, which then requires you to put the output files as sources in your project. If these declarations don't need manual intervention, you can automate the process by making Gradle use Dukat for you. For this, you simply need to enable the Gradle property
    kotlin.js.experimental.generateKotlinExternals=true
    j

    janvladimirmostert

    2 years ago
    that makes sense, thanks for this info!