Is there an annotation/configuration that will cau...
# javascript
r
Is there an annotation/configuration that will cause Gradle to output compiled kotlin/js to a different “package”? I have a multiplatform lib that I’m building which compiles to JVM and JS, and I was hoping to not have to use the fully qualified package name to call shared code from JS-land.
h
Well, the default behaviour for the compiler/transpiler is to use the fully qualified name in JS: https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html#package-structure
But in order to keep the public parts of your API from being removed by the DCE tool, you need to mention all the parts that are to be kept in the gradle build file. So why not make an alias file in the root of your project somewhere which could both act as a proxy for the fully qualified names and save your users some typing?
r
Thanks for the input here, alias file seems like a decent approach. I’ll give that a shot
Hoping to follow up on this @hallvard, curious if you’ve found an approach that works here. I tried dropping a file at the root with some
typealias
declarations and I’m not seeing them exposed when I import the lib. Just to test, I threw a val in that same file which I can see downstream, so it seems like just
typealias
isn’t working as I’d expect.
h
I'm on vacation now, so I cannot help you with any real examples, but in your place, I wouldn't have bothered with typealiases. I would just do 'fun short() = com.very.long.short()' and 'fun add(a: Int, b: Int) = com.very.long.add(a,b)'.
I'm not back in the office for the next two weeks, so I guess that for further ideas, you should ask in plenary ...
r
No worries at all, thanks again! Enjoy your vacation!