To make adjustments to the configuration used by Karma, place your additional configuration files inside a directory called in the root of your project. You can find the file at build/js/packages/projectName-test/. The Kotlin/JS Gradle plugin automatically generates a Karma configuration file at build time which includes your settings from the kotlin.js. block in your adle(.kts). To run a project, execute the standard lifecycle run task, or the alias to which it corresponds:
If you want to customize the configuration used by webpack-dev-server, for example adjust the port the server runs on, use the webpack configuration file.įor running Kotlin/JS projects targeting Node.js, the run task is an alias for the nodeRun task (which is also available in Kotlin multiplatform projects). It uses the webpack-dev-server to serve your JavaScript artifacts. The Kotlin/JS plugin provides a run task that lets you run pure Kotlin/JS projects without additional configuration.įor running Kotlin/JS projects in the browser, this task is an alias for the browserDevelopmentRun task (which is also available in Kotlin multiplatform projects).
Once an npm dependency is installed, you can use its API in your code as described in Calling JS from Kotlin. OptionalDependencies via optionalNpm(.), and To learn more about when each type of dependency can best be used, have a look at the official documentation linked from npm:
Learn how to configure Yarn in Kotlin/JS Gradle plugin.īesides regular dependencies, there are three more types of dependencies that can be used from the Gradle DSL. It works out of the box without additional configuration, but you can tune it to specific needs.
The plugin uses the Yarn package manager to download and install NPM dependencies. Like any other Gradle projects, Kotlin/JS projects support traditional Gradle dependency declarations in the dependencies section of the build script. For projects targeting Node.js, there are also an option to use an existing Node.js installation. This allows developers to build, run, and test simple projects without additional configuration.
This includes downloading and installing the required environment and dependencies for running and testing the application. The Kotlin/JS plugin automatically configures its tasks for working with the selected environment. (This is typically faster than creating executable files, and can be a possible optimization when dealing with non-leaf modules of your project.) In those cases, omitting binaries.executable() will cause the compiler to only generate Kotlin-internal library files, which can be used from other projects, but not run on their own. This is the default behavior when using the current Kotlin/JS compiler, but the instruction is explicitly required if you are working with the Kotlin/JS IR compiler, or have set kotlin.js.=false in your gradle.properties. The instruction binaries.executable() explicitly instructs the Kotlin compiler to emit executable. Don't forget to choose the language for the build script: Groovy or Kotlin.Īlternatively, you can apply the plugin to a Gradle project manually in the Gradle build file ( adle or ). Then select Kotlin and choose a Kotlin/JS target that suits you best. To create a Kotlin/JS project in IntelliJ IDEA, go to File | New | Project.
Dependency management and configuration adjustments can be done to a large part directly from the Gradle build file, with the option to override automatically generated configurations for full control. For example, the plugin downloads the Yarn package manager for managing npm dependencies in background and can build a JavaScript bundle from a Kotlin project using webpack.
To let developers easily manage their Kotlin/JS projects, we offer the kotlin.js Gradle plugin that provides project configuration tools together with helper tasks for automating routines typical for JavaScript development. Kotlin/JS projects use Gradle as a build system.