W3cubDocs

/Kotlin

Development Server and Continuous Compilation

Last Updated 23 February 2020
How to set up the local development environment for automatic recompilation and reloading.

Instead of manually compiling and executing our Kotlin/JS project every time we want to see the changes we made, we can make use of the continuous compilation mode. Instead of using the regular run command, we instead invoke the Gradle wrapper in continuous mode:

./gradlew run --continuous

If we are working from inside IntelliJ IDEA, we can pass the same flag via the run configuration. After running the Gradle run task for the first time from the IDE, IntelliJ IDEA automatically generates a run configuration for it, which we can edit:

Editing run configurations in IntelliJ IDEA

Enabling continuous mode via the Run/Debug Configurations dialog is as easy as adding the --continuous flag to the arguments for the run configuration:

Adding the continuous flag to a run configuration in IntelliJ IDEA

When executing this run configuration, we can note that the Gradle process continues watching for changes to the program:

Gradle waiting for changes

Once a change has been detected, the program will be recompiled automatically. If we still have the page open in our browser, the development server will trigger an automatic reload of the page, and our changes will become visible. This is thanks to the integrated webpack-dev-server that is managed by the Kotlin/JS Gradle plugin.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/docs/tutorials/javascript/dev-server-continuous-compilation.html