Compile Kotlin with JavaScript

I started to learn Kotlin, and I would like to use it instead of TypeScript for my interface language. Both compile before JavaScript, so I would like to configure it so that I create a Kotlin file, call it myFile.kt , and then when I run the compiler, it will make myFile.js file.

Just like TypeScript takes myFile.ts and compiles it into myFile.js .

I am using the latest version of IntelliJ 15 with a candidate for the 1st release of Kotlin.

I have searched all over the Internet for a way to do this, but so far all I have found is to configure IntelliJ so that Kotlin creates a JavaScript library from your code in a JAR file. I also could not get this to compile any of the kt files in my project (previously they were js ).

What would I like to do now, or am I thinking about it wrong?

+5
source share
1 answer

I think this should help:

https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsProject/libraryProject/build.gradle

There is a sample library project. JS sources can be buildDir based. So yes, you can get js files from Kotlin sources.

Kotlin language is very different from JavaScript (even ES6), so you can’t just rename js to kt , it won’t work. You need to rewrite the javascript source files in Kotlin.

For instance:

 console.log('Hello, World!'); 

It should be rewritten as:

 fun main(args: Array<String>) { println("Hello, World!") } 
+4
source

Source: https://habr.com/ru/post/1242578/


All Articles