Is there a kotlin.js library compiled as a plain j...
# javascript
s
Is there a kotlin.js library compiled as a plain js library? The bundler that react-native is using seems to freeze trying to bundle the kotlin.js library
g
Yeah, the kotlin.js standard lib is on NPM. You will still have to compile your own kotlin code though. Better to compile your kotlin code withe the standard lib so it is in one or two bundles then compile that along with react native. (I'm just guessing this is the right way to do it by the way I've never use react native)
s
How do I compile my code with the standard library?
I've been trying to find a way to do that
Also, I'm using kotlin.js from npm, which is what is what seems to not be able to be packed.
g
You'll need to use gradle, take a look at how I'm doing it here https://github.com/gbaldeck/vue.kt
It will most likely be a similar setup for react native
s
I am using Gradle. I'm not seeing anything special in your gradle file that would do this though: https://github.com/gbaldeck/vue.kt/blob/master/build.gradle
g
So what gradle does is it compiles your code with the kotlin standard lib and outputs them both under the build/classes folder
in my case, since I'm using the DCE, the compiled code of both my project and the kotlin standard lib is outputed to build\classes\kotlin\main\min
with names vuekt.js and kotlin.js respectively
then I include them both as modules in the webpack config
the first part where I use gradle should be about the same for both of us, the second part, where I hand the build process over to webpack, will need to be specific to whatever react native needs
Also, your kotlin code needs to be using react native specific libraries, and providing react native everything it needs. meaning you will need to create a wrapper for react native if you haven't already. The jetbrains kotlinjs wrapper for react is a good place to start
b
@spierce7 you can find more info about DCE here https://kotlinlang.org/docs/reference/javascript-dce.html
s
Is DCE fast enough to have part of your normal development cycle?
g
definitely, it takes a couple seconds at most
you can turn it off for dev purposes though, then turn it on for production builds
b
Since 1.2.20 you can simple switch to dev mode by
runDceKotlinJs.dceOptions.devMode = true
. But, as far as I understand, disabling it will return us to the original problem.
@spierce7 could you please file an issue about original problem with self-contained example to reproduce?
And let us know if using DCE solve your problem
g
@bashor I don't think that the DCE is the only thing that will solve the problem. He needs to be using a wrapper specific to react native also
b
Great! I have confirmed that DCE make it possible to use kotlinjs. Also a wrapper of react native would be helpful to build react native project with kotlinjs.
s
For anyone else interested, I have a github project showing the issue here. The readme has repro instructions: https://github.com/ScottPierce/ReactNativeKotlinError
Also for the record, I couldn't get the DCE plugin approach to work. I gave it a shot. I also tried the frontend plugin to use webpack, but webpack wasn't packing in the kotlin.js file like I thought it would.
b
@spierce7 thank you!
s
I'm going to assume that kotlin-js isn't safe to move forward with for react-native. I imagine it will be a while before you guys get around to looking into this
I'm actually going to keep plugging away at it and see if I can figure it out. I have a week or 2 before we need to make a call.