Hello everybody Can I use kotlin loader/compiler f...
# javascript
l
Hello everybody Can I use kotlin loader/compiler from webpack? Like just add some loader to config, webpack -w, and get success?
k
No, it's impossible. But you can run both kotlinc and webpack from a Gradle script
l
What about maven?
I found example there
k
There definitely should be a way to run
npm
from Maven. It's out of scope of Kotlin compiler
For example, you can try
exec-maven-plugin
But there's one thing that makes Gradle more preferrable. Since Kotlin 1.1.50, Gradle will introduce support for incremental compilation for Kotlin/JS
l
Ah... incremental
kotlin forces me to move to gradle)
How to compile kt to js automatically on file change?
Is it good idea to call kotlin compiler from webpack loader each time file changes?
Or gradle will do it automatically?
e
g
@konsoletyper kotlin 1.1.50 or kotlin 1.1.5 ? 😉
@lewik it’s less kotlin that forces you to move to gradle than javascript. These projects are much more complex and gradle is better at handling this. During dev, it can be interesting to have gradle in continuous mode (it will be even better with incremental compilation), and also in parallel webpack with watch set to true.
l
@gaetan I agree. Thank you.
I have javascript project already. Trying to user one kotlin class, compiled to js. Is there any doc for webpack + kotlin? I can't properly import kotlin.js std library (I used lib from npm install kotlin)
k
@lewik here you can find example of setting up Kotlin with Gradle and Webpack: https://github.com/JetBrains/kotlin-examples/tree/master/gradle/js-dce
l
Why node is there?
k
What do you mean?
How are you going to run webpack without node?
l
So I have js project already. As I understand - I will use 'webpack -w' as usual. And run gradle in some mode (like --watch). Gradle will compile js file and put it somewhere in webpack context. Webpack detects changes and merge js files. (Seems that compile js-from-kt again inside webpack - not good idea)
--solved--
g
@gaetan Whoa, looks like 1.1.50 it’s a new versioning scheme for Kotlin. https://bintray.com/kotlin/kotlin-dev/kotlin/1.1.50-eap-8 Looks like instead 1.1.5 and 1.1.5-1 we will see 1.1.51
👍 1
f
I'm also working on a boilerplate for building react-apps with kotlin. Its still wip but you can checkout the webpack config I use https://github.com/figitaki/kotlin-scripts