6

I've started looking into Kotlin and I'd like to use it instead of TypeScript for my front end language. Both compile down to JavaScript so I'd like to set it up so that I make a Kotlin file, lets call it myFile.kt, then when I run the compiler it makes a myFile.js file.

Just like how TypeScript takes a myFile.ts and compiles it to a myFile.js.

I'm using the latest version of IntelliJ 15 with release candidate 1 of Kotlin.

I've been searching all over the internet for the way to do this but so far all I've found is setting up IntelliJ so that Kotlin creates a JavaScript library from your code in a JAR file. I also haven't been able to get that to compile any of the kt files in my project (they were previously js files).

Is what I'd like to do currently possible or am I thinking about this in the wrong way?

1 Answer 1

5

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 are sample of library project. JS sources can be founded in buildDir. So yes, you can get js files from Kotlin sources.

Kotlin language a very different from JavaScript (even ES6), so you can't just rename js to kt, this will not work. You need rewrite javascript source files to Kotlin.

For example:

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

Should be rewritten as:

fun main(args: Array<String>) {
  println("Hello, World!")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.