https://kotlinlang.org logo
Title
f

franztesca

03/28/2023, 8:42 AM
I'm trying to compile a Kotlin/JS library that should be used by both browser and node target. This is my gradle js configuration:
js {
        binaries.library()
        browser {
            distribution {
                directory = File("$projectDir/js_output/browser/")
            }
        }
        nodejs {
            distribution {
                directory = File("$projectDir/js_output/node/")
            }
        }
    }
My goal is to compile the browser version to the output folder
js_output/browser
and the node one to
js_output/node
. However this doesn't work, because apparently the Kotlin target is shared between node and browser, therefore setting the distribution in the
nodejs
block overrides the one of
browser
, and thus both are always compiled to the same distribution directory (
js_output/node
). I use the
jsNodeProductionLibraryDistribution
and
jsBrowserProductionLibraryDistribution
tasks to create the production library distributions. This is actually a KMP project. Any hints on how to do this properly?