Experimental Gradle support for NPM, Yarn, and Web...
# javascript
s
Experimental Gradle support for NPM, Yarn, and Webpack for Kotlin/JS released in 1.3.40. Also test runners for Kotlin/JS now implement all Gradle Test runner APIs and behave in a way similar to the Kotlin/JVM test runner. https://blog.jetbrains.com/kotlin/2019/06/kotlin-1-3-40-released/
👍 9
🎉 9
❤️ 3
v
Hi, thank you for announcement. I am looking for kotlin/js project with unit tests.
j
This looks so promising, thanks for the good work!
s
Could you share some project(s) with
gradle.build.kts
that have been upgraded to use this new Gradle Kotlin/JS plugin?
s
You can create simple project via IDE wizard:
Screenshot 2019-06-20 at 11.45.07.png
For more advanced project you can take a look at https://github.com/snrostov/kotlin-full-stack-application-demo (edited)
s
Ok thanks
Any plan to migrate the sample app to
gradle.build.kts
😉 ?
Any plan to migrate the sample app to
gradle.build.kts
😉 ?
You mean sample app in wizard?
s
I mean Gradle Kotlin DSL is quickly becoming the default in most projects I see. So it would help for users to have sample applications with it. The sample app in the wizard use Groovy or Kotlin DSL?
Hum no it seems to be Groovy DSL
s
In Gradle project wizard there is “Kotlin DSL build script” checkbox. “JS client and JVM server” uses Groovy DSL, yes.
s
Which is kind of strange to me given the fact that Kotlin DSL is now stable with Gradle 5
☝️ 2
Providing at least a sample project with Kotlin DSL and the new Kotlin/JS plugin would be super useful IMO
1
❤️ 1
(I mean on a GitHub repo and link it in the documentation)
Or better a tuto
Since Kotlin/JS ecosystem is changing fast, providing this kind of up to date guidance would really help increasing adoption
☝️ 2
I will try to update my https://github.com/sdeleuze/spring-kotlin-fullstack sample asap
FWIW on Spring side we don't provide anymore Groovy DSL with Kotlin. When you select Kotlin + Gradle on https://start.spring.io/, a
build.gradle.kts
files is generated.
❤️ 1
👍 5
s
https://github.com/sdeleuze/spring-kotlin-fullstack
It seems this sample using old multiplatform kotlin gradle plugins. Unfortunately new kotlin/js plugin incompatible with it. I can help with updating it to the new multiplatform plugin with new kotlin/js plugin features. I will send PR.
❤️ 1
As for other examples: yes, there are some plans for it, including samples with build.gradle.kts.
❤️ 1
😊 2
s
Ok thanks for the PR that would really help
u
@snrostov After changing
Copy code
plugins {
    id("kotlin2js") version "1.3.40"
}
to
Copy code
plugins {
    kotlin("js") version "1.3.40"
}
I get
Task with name 'compileKotlin2Js' not found in root project 'project_name'.
I use
compileKotlin2Js
task to specify
KotlinJsOptions
. Is there any documentation on how to use the plugin? Also how to extend
compileKotlin2Js
to create several tasks/compilations of one source set with different
KotlinJsOptions
? Also what about DCE? How to turn it on with new plugin?
3
j
@U75957 I'm also interested in any doc about the new plugin's configuration. It seems all we have for now is just the blog post about the new release but it doesn't help much for the migration :(
s
I get
Task with name 'compileKotlin2Js' not found in root project 'project_name'.
I use
compileKotlin2Js
task to specify
KotlinJsOptions
.
In the new plugin, it is called
compileKotlinJs
. The reason is that this new plugin works the same as the JS part of the multiplatform plugin.
Also how to extend
compileKotlin2Js
to create several tasks/compilations of one source set with different
KotlinJsOptions
? Also what about DCE? How to turn it on with new plugin?
Debug/release and other build variants currently not supported out of box. We are just started to design it… But you can still create all tasks manually.
s
Thanks a lot for the PR which is now merged!
u
@snrostov thanq,
compileKotlinJs
do the job. And just for note: my use-case with build variants is such that I need one build with
main = "call"
and other with
main = "noCall"
. For now I have Copy task, which also just remove line with
main()
call from build. (not a very beautiful decision, but I don't know how to do otherwise)
s
@U75957 You can do this in multiplatform plugin by creating 2 js targets and common source set between them.
u
@snrostov I've already tried it. But common source set can't be targeted to single platform https://youtrack.jetbrains.com/issue/KT-28194
s
Ah, yes, sorry this is a case for the hierarchical mpp which requires huge work (which is in progress).
p
example project that publishes a library for kotlinjs with gradle 1.3.40 https://github.com/exaV/screeps-kotlin-types
👍🏻 1
f
@snrostov I'm testing with the new plugin
kotlin("js")
and you say:
In the new plugin, it is called
compileKotlinJs
.
but can't resolve the reference to task `compileKotlinJs`:
Copy code
compileKotlinJs.kotlinOptions {
    outputFile = "routes/node/index2.js"
}
I changed to: (Work)
Copy code
tasks {
    "compileKotlinJs"(Kotlin2JsCompile::class)  {
        kotlinOptions.outputFile = "routes/node/index2.js"
        kotlinOptions.metaInfo = false
    }
}
Some reason why it doesn't work shortened call to compileKotlinJs?