Set up a development environment for Kotlin/React

I wish to develop web applications in Kotlin, since the type safety and the advanced features make the development experience a lot more pleasant. Kotlin can be compiled to Javascript and ran in the browser, but the current guide on how to do this is slightly outdated.
1 answer

In IntelliJ, start by creating a new Kotlin project. You will be asked to choose the project type, at which point you can choose a pure frontend application or a full-stack web application depending on what suits your needs best. You may need to wait a few minutes for all the necessary dependencies to finish downloading.
You should then see your project. Within the src/main directory you will be able to find your main .kt file containing the script's starting point and an index.html file in the resources directory. Note that inside of the HTML file, the only script that is linked is one .js file, named the same as your project. This file will be generated at compile-time and will contain all your compiled Kotlin code.

To run the project, you can bring up the Gradle tool window from the View menu, and run the browserDevelopmentRun Gradle task to run your project for the first time. This may take a couple of minutes the first time you do it.
However, you probably don't want to be manually stopping and restarting your web server every time you make a change to a file. By bringing up your run configurations tool window, you can edit the newly created browserDevelopmentRun configuration. In the Arguments text field, add the argument --continuous and save your changes. Upon next run, this will make the system continuously listen for changes and update your browser automatically.

Comments

I am a Kotlin beginner and wanted to develop my first web application in Kotlin and had problems with the current guide. Thank you for your answer, it helped me a lot.

Marco Weber - Tue, 12/15/2020 - 14:44 :::