When I build an MPP project for JS browser(IR) tar...
# multiplatform
g
When I build an MPP project for JS browser(IR) target, the Webpack task copies the
.js
and
.js.map
files to the distribution directory, but not the
.d.ts
file. Is there a way to get that file included too?
b
It doesn't? I could swear it does. What kind of binary do you have registered?
g
Copy code
js(IR) {
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }

            distribution {
            }
            webpackTask {
                outputFileName = "sliktest.js"
            }
        }

        binaries.executable()
        useCommonJs()
    }
b
And that's you issue. You're not really building an
executable
if you need
.d.ts
files. Change it to
binaries.library()
g
Ah, thanks.
b
You might find npm-publish useful for packaging and distributing.
🙏 1
g
binaries.library()
causes Gradle sync to fail in the IDE with a weird internal intellij stacktrace, but at least on the command line it does now include the
d.ts
in the distribution. Thanks for the help. 🙂
b
Yeah, binaries.library() did not receive as much love as binaries.executable() yet.
If you do use that plugin, just running
./gradlew packJsNpmpublication
should produce all you need to distribute your lib in
build/publications/npm/js
🙏 1
You can also publish them via the plugin to npm repository, but the most common use-case I've found is to pack kotlin.js lib into tarball and then install it into a JS/TS project from that (assuming both projects live in the same monorepo) e.g.
Copy code
pwd # IdeaProjects/my-project/kotlin-lib
./gradlew pack
cd ../ts-app
pwd # IdeaProjects/my-project/ts-app
yarn install ../kotlin-lib/build/publications/npm/js-1.0.0.tar.gz
But you can do all that without a plugin as well, just a bit more work